linux下部署專案節點相關指令碼
阿新 • • 發佈:2018-12-10
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