1 节点打包时pom相关配置:
<build>
<finalName>suninfoReport</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<wtpversion>2.0</wtpversion>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature
</projectnature>
</additionalProjectnatures>
<downloadSources>true</downloadSources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- 相关的jar包所在路径/ -->
<classpathPrefix>/usr/local/suninfo/siem/lib/</classpathPrefix>
<mainClass>com.suninfo.main.ReportTaskMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
2 创建.jar节点启动脚本
方式一:【suninfo_center_start.sh】
#!/bin/sh
cd /usr/local/suninfo/imp/node
/usr/local/suninfo/imp/jdk/bin/java -jar suninfoCenter.jar >/dev/null 2>&1 &
方式二:指定内存【suninfo_report_start.sh】
#!/bin/sh
cd /usr/local/suninfo/imp/node
/usr/local/suninfo/imp/jdk/bin/java -Xms512m -Xmx512m -Xss256k -XX:NewRatio=3 -XX:PermSize=64M -XX:MaxPermSize=128M -jar suninfoReport.jar >/dev/null 2>&1 &
3 创建调用各节点启动脚本【node_start.sh】
#!/bin/sh
/usr/local/suninfo/imp/node/suninfo_center_start.sh
/usr/local/suninfo/imp/node/suninfo_report_start.sh
4 创建各节点停止脚本【node_stop.sh】
#!/bin/sh
ps -ef | grep suninfoCenter | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | grep suninfoReport | grep -v grep | awk '{print $2}' | xargs kill -9
5 将项目做成服务
在/etc/init.d/目录下创建服务: vi imp
内容如下:
#!/bin/sh
mode=$1
ret_start=0
source /etc/profile
fun_start(){
echo "startup imp :"
memcached -d -p 11211 -u memcached -m 512 -c 2048 -P /var/run/memcached/memcached.pid -v >> /opt/log/imp/memcached.log 2>&1 &
echo "startup tomcat ...[OK]"
nohup /usr/local/suninfo/imp/tomcat/bin/startup.sh > /opt/log/imp/tomcatlog 2>&1 &
echo "startup node ...[OK]"
/usr/local/suninfo/imp/node/node_start.sh
}
fun_stop(){
echo "shutdown imp :"
echo "shutdown tomcat ...[OK]"
/usr/local/suninfo/imp/tomcat/bin/shutdown.sh
/etc/rc.d/init.d/memcached stop
echo "kill processes ...[OK]"
/usr/local/suninfo/imp/node/node_stop.sh
}
case "$mode" in
'start')
fun_start
exit $ret_start
;;
'stop')
fun_stop
;;
'restart')
fun_stop
sleep 2
fun_start
exit $ret_start
;;
*)
echo "Usage: $0 {start|stop|restart}"
;;
esac
6 调用服务启停项目
serivce imp start
service imp stop