做个总结
linux服务器上做负载均衡
自己准备的:linux服务器(45.78.20.168),jdk1.7,nginx,redis,tomcat7两个,部署的项目;
1:jdk1.7安装,两个tomcat分别端口8080,8081;部署相同的项目;启动;
http://45.78.20.168:8080/redis3.2/getRedis.action2:安装nginx,添加负载的配置,安装目录下找
/etc/nginx/conf.d/default.conf文件(或/etc/nginx/nginx.conf);策略设置为默认轮询;
upstream www.nimenhaihaoma.com {
server 45.78.20.168:8080;
server 45.78.20.168:8081;
}
server{
listen 80;
server_name www.nimenhaihaoma.com;
location / {
proxy_pass http://www.nimenhaihaoma.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
3:配置session共享,方式很多,这里用的redis的session共享(兼容jdk版本至少1.7):
tomcat的lib包加
commons-pool2-2.0.jar,jedis-2.5.2.jar,tomcat-redis-session-manager1.2.jar;
tomcat配置文件context.xml,在标签<Context>内添加配置:
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="localhost" port="6379" database="0" maxInactiveInterval="60" />
4:项目里面区分session的代码:
(1):放session的接口(执行一次);
(2):取session数据(不断刷新),看tomcat打印信息;
5:效果,
http://www.nimenhaihaoma.com/redis3.2/getRedis.action (狂刷session值相同)
posted @
2016-08-17 17:03 魏文甫 阅读(119) |
评论 (0) |
编辑 收藏
项目只是加载spring的几个定时任务,启动服务一直循环加载spring文件,问题的根节点:定时器类里面的service对象采取配置的方式注入,而这个定时器类的构造让我给加上了:
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext*.xml");
myServiceImpl = context.getBean("XXXService");
加上这段为了方便测试,在该类里写main方法测试执行,把调用写到构造里;,spring定时器配置好时间后,此处构造忘了去掉;导致启动tomcat服务一直在加载spring注入文件;
同理,spring注入的方式,在action里同样有这样的效果,构造方法一定注意;
posted @
2015-04-25 11:09 魏文甫 阅读(175) |
评论 (0) |
编辑 收藏
1,添加索引文件中的一条新的索引
Question addQ = new Question();//新添加的一条数据,对象id在索引文件中没有
addQ.setId("999999999");
addQ.setQuestionname("新添加的一条数据名称");
Analyzer sa = new SmartChineseAnalyzer(Version.LUCENE_40);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, sa);
iwc.setOpenMode(OpenMode.APPEND);
IndexWriter writer = null;
try {
Directory dir1 = FSDirectory.open(new File("F:\\temp"));
writer = new IndexWriter(dir1, iwc);
FieldType ft = new FieldType();
ft.setIndexed(true);
ft.setStored(true);
ft.setTokenized(true);
FieldType ft2 = new FieldType();
ft2.setIndexed(true);
ft2.setStored(true);
ft2.setTokenized(false);
Document doc = new Document();
doc.add(new Field("id", addQ.getId(), ft2));
doc.add(new Field("questionname", addQ.getQuestionname(), ft));
writer.addDocument(doc);
writer.close();
} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (LockObtainFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
try {
if(writer!=null){
writer.close();
}
if(sa!=null){
sa.close();
}
} catch (CorruptIndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}执行完程序后,索引文件中已经添加新的索引数据。2,删除索引文件中的一条新的索引
Question delQ = new Question();//索引文件中有的一条数据,根据对象id删 delQ.setId("1111111"); delQ.setQuestionname("要删除的一条数据"); IndexWriter writer = null;
Analyzer sa = new SmartChineseAnalyzer(Version.LUCENE_40);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, sa);
Directory dir1 = null;
try {
dir1 = FSDirectory.open(new File("F:\\temp"));
writer = new IndexWriter(dir1, iwc);
Term term = new Term("id", delQ.getId());
writer.deleteDocuments(term);
writer.commit();
writer.close();
} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (LockObtainFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (writer != null) {
writer.close();
sa.close();
}
} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("索引删除完成");
3,更新索引文件中的一条索引
更新索引文件中的一条索引的理念是:先找到这条索引删除,然后再添加这条更新后的索引
posted @
2013-08-16 12:08 魏文甫 阅读(335) |
评论 (0) |
编辑 收藏
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File("F:\\temp")));// 打开索引
IndexSearcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new SmartChineseAnalyzer(Version.LUCENE_40);
String[] fields = { "questionname","id" };
Occur[] occurs = new Occur[] { Occur.SHOULD,Occur.SHOULD };
Query query = MultiFieldQueryParser.parse(Version.LUCENE_40, "测试 的", fields,
occurs, analyzer);
TopDocs result = searcher.search(query, searcher.getIndexReader()
.maxDoc());
ScoreDoc[] hits = result.scoreDocs;
List<Document> list = new ArrayList<Document>();
for (int i = 0; i <hits.length; i++) {
Document doc = searcher.doc(hits[i].doc);
list.add(doc);
}
System.out.println("搜索list的长度\t→→→→\t"+list.size());
for (Document document : list) {
System.out.println(document.getField("questionname"));
}
analyzer.close();
注:红色字体是输入的检索条件,多个用空格隔开,找到的结果先匹配同时符合多个的结果,结果只是拿过来的document一个list集合,具体结果再解析就行了。
结果如图:
posted @
2013-08-12 17:26 魏文甫 阅读(1167) |
评论 (1) |
编辑 收藏
Connection conn = null;
Statement stat = null;
ResultSet rs = null;
Analyzer sa = new SmartChineseAnalyzer(Version.LUCENE_40);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, sa);
iwc.setOpenMode(OpenMode.CREATE);
Directory dir1 = FSDirectory.open(new File("F:\\temp"));
IndexWriter writer = new IndexWriter(dir1, iwc);
int numIndexed = -1;
FieldType ft = new FieldType();
ft.setIndexed(true);
ft.setStored(true);
ft.setTokenized(true);
FieldType ft2 = new FieldType();
ft2.setIndexed(true);
ft2.setStored(true);
ft2.setTokenized(false);
Class.forName("com.mysql.jdbc.Driver");
conn = (Connection) DriverManager.getConnection(
"jdbc:mysql:///question", "root", "root");
stat = (Statement) conn.createStatement();
rs = stat.executeQuery("select id,questionname from question");
List<String> list = new ArrayList<String>();
while (rs.next()) {
String id = rs.getString("questionname");
String questionname = rs.getString("questionname");
list.add(id);
list.add(questionname);
}
rs.close();
stat.close();
conn.close();
for (String string : list) {
Document doc = new Document();
doc.add(new Field("questionname", string, ft2));
writer.addDocument(doc);
}
numIndexed = writer.maxDoc();
writer.close();
执行完这段程序f盘多一个文件夹temp,里面就是创建好的索引文件了,然后进行根据索引文件查询
posted @
2013-08-12 16:50 魏文甫 阅读(1412) |
评论 (0) |
编辑 收藏
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=GBK" />
<title></title>
<script type="text/javascript" src="jquery-1.8.2.js"></script>
<script type="text/javascript">
$(document).mousemove(function(e) {
var innerHeight = window.innerHeight;
if (e.pageY > innerHeight) {
$("#topDiv").css("display", "block");
}
if (e.pageY < innerHeight) {
$("#topDiv").css("display", "none");
}
});
$("#topIcon").mouseover(function() {
$("#topIcon").css("text-decoration", "none");
$("#topIcon").children("i").removeClass();
$("#topIcon").children("i").addClass("icon-chevron-up");
});
$("#topIcon").mouseout(function() {
$("#topIcon").children("i").removeClass();
$("#topIcon").children("i").addClass("icon-arrow-up");
});
</script>
</head>
<body id="bodyId">
<div id="topDiv"
style="position: fixed;right: 60px;bottom: 60px;display: none">
<a id="topIcon" href="#bodyId" style="background-color: #aaaaaa"><span
style="text-align: justify;display: block;text-decoration: none;width: 14px;background-color: #cccccc">回到顶端</span>
</a>
</div>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
</body>
</html>
posted @
2013-08-07 10:35 魏文甫 阅读(207) |
评论 (0) |
编辑 收藏
求单一登陆和单点登陆的思路及核心代码???
posted @
2013-08-07 09:56 魏文甫 阅读(319) |
评论 (0) |
编辑 收藏
html中中文正则表达式不对的问题 中文的正则表达式:var reg = /^[\u4e00-\u9fa5]$/;(一个中文字符)
放在html中可能出现的问题有:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title></title>
</head>
<body>
<script type="text/javascript">
var reg0 = /^[\u4e00-\u9fa5]$/;
alert(reg0.test("看"));
</script>
</body>
</html>
本页编码为UTF-8时出现的结果可能是错误的,
所以出现此类情况,编码格式改为gb2312(红色标注的编码改为gb2312)
posted @
2013-07-29 15:56 魏文甫 阅读(220) |
评论 (0) |
编辑 收藏
简单的代码:
public static void main(String[] args) {
try {
File allfile = new File("f:\\excel\\total.xlsx");
File file2 = new File("f:\\excel\\xxxxxx.xlsx");
XSSFWorkbook h = new XSSFWorkbook(new FileInputStream(allfile));
XSSFSheet x = h.getSheetAt(0);
XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream(file2));
XSSFSheet hssfSheet = hssfWorkbook.getSheetAt(0);
int ii = hssfSheet.getLastRowNum();//读取的表格行数
System.out.println(ii);
FileOutputStream out_ = new FileOutputStream(allfile);
for (int i = 0; i < ii; i++) {
XSSFRow lastRow = x.createRow(x.getLastRowNum()+1);
XSSFRow xssfRow = hssfSheet.getRow(i);
XSSFCell xssfCell0 = xssfRow.getCell(0);
CellStyle cellStyle0 = xssfCell0.getCellStyle();
CellStyle newStyle0 = h.createCellStyle();
newStyle0.cloneStyleFrom(cellStyle0);
XSSFCell xssfCell0_ = lastRow.createCell(0);
xssfCell0_.setCellStyle(newStyle0);
xssfCell0_.setCellValue(xssfCell0.toString());
XSSFCell xssfCell1 = xssfRow.getCell(1);
CellStyle cellStyle1 = xssfCell1.getCellStyle();
CellStyle newStyle1 = h.createCellStyle();
newStyle1.cloneStyleFrom(cellStyle1);
XSSFCell xssfCell1_ = lastRow.createCell(1);
xssfCell1_.setCellStyle(newStyle1);
xssfCell1_.setCellValue(xssfCell1.toString());
XSSFCell xssfCell2 = xssfRow.getCell(2);
CellStyle cellStyle2 = xssfCell2.getCellStyle();
CellStyle newStyle2 = h.createCellStyle();
newStyle2.cloneStyleFrom(cellStyle2);
XSSFCell xssfCell2_ = lastRow.createCell(2);
xssfCell2_.setCellStyle(newStyle2);
xssfCell2_.setCellValue(xssfCell2.toString());
XSSFCell xssfCell3 = xssfRow.getCell(3);
CellStyle cellStyle3 = xssfCell3.getCellStyle();
CellStyle newStyle3 = h.createCellStyle();
newStyle3.cloneStyleFrom(cellStyle3);
XSSFCell xssfCell3_ = lastRow.createCell(3);
xssfCell3_.setCellStyle(newStyle3);
xssfCell3_.setCellValue(xssfCell3.toString());
XSSFCell xssfCell4 = xssfRow.getCell(4);
CellStyle cellStyle4 = xssfCell4.getCellStyle();
CellStyle newStyle4 = h.createCellStyle();
newStyle4.cloneStyleFrom(cellStyle4);
XSSFCell xssfCell4_ = lastRow.createCell(4);
xssfCell4_.setCellStyle(newStyle4);
xssfCell4_.setCellValue(xssfCell4.toString().toString());
}
h.write(out_);
out_.flush();
out_.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
posted @
2013-07-19 18:02 魏文甫 阅读(626) |
评论 (0) |
编辑 收藏