all.sh
#!/bin/bash
function stop(){
echo "Stopping "$1
cmdCommand="ps -ef|grep java|grep "$1"|grep -v grep|awk '{print \$2}'"
echo $cmdCommand
eval "pid=\`"$cmdCommand"\`"
if [ -n "$pid" ]
then
#!kill -9 强制终止
echo "pid:" $pid
# kill -9 $pid
for i in $pid
do
echo "kill -9 的pid:" $i
kill -9 $i
done
fi
}
function start(){
cd $1
echo "chmod:"$2
chmod 777 $2
mkdir log
javaCommand="nohup java -jar "$2" "$3" >log/$2.`date +%Y%m%d%H%M%S`.log 2>1&"
echo "execute start:"$javaCommand
eval $javaCommand
echo "execute end:"$javaCommand
}
basepath=/home/users/jiafujun
echo "cd "$basepath
cd $basepath
# pwd
# 注意,sh命令的最后面需要包含空格,不然会导致传递的参数包含换行符,导致命令执行失败
echo "--------Start socket--------"
stop socket-jar-with-dependencies.jar
start $basepath socket-jar-with-dependencies.jar
echo "--------Start socket End--------"
echo "--------Start sale--------"
stop sale-jar-with-dependencies.jar
start $basepath sale-jar-with-dependencies.jar
echo "--------Start sale End--------"
echo "--------Start Report--------"
stop report-jar-with-dependencies.jar
start $basepath report-jar-with-dependencies.jar "type=1 attime=false thread=1 all"
start $basepath report-jar-with-dependencies.jar "type=2 attime=true thread=1 time"
start $basepath report-jar-with-dependencies.jar "type=2 attime=true thread=2 base"
start $basepath report-jar-with-dependencies.jar "type=2 attime=true thread=4 database"
start $basepath report-jar-with-dependencies.jar "type=2 attime=true thread=4 msg"
start $basepath report-jar-with-dependencies.jar "type=2 attime=true thread=2 log"
start $basepath report-jar-with-dependencies.jar "type=2 attime=true thread=2 qq"
echo "--------Start Report End--------"
执行结果:
[root@master jiafujun]# ./all.sh
cd /home/users/jiafujun
--------Start socket--------
Stopping socket-jar-with-dependencies.jar
ps -ef|grep java|grep socket-jar-with-dependencies.jar|grep -v grep|awk '{print $2}'
pid: 23408
kill -9 的pid: 23408
chmod:socket-jar-with-dependencies.jar
mkdir: 无法创建目录"log": 文件已存在
execute start:nohup java -jar socket-jar-with-dependencies.jar >log/socket-jar-with-dependencies.jar.20180202135158.log 2>1&
execute end:nohup java -jar socket-jar-with-dependencies.jar >log/socket-jar-with-dependencies.jar.20180202135158.log 2>1&
--------Start socket End--------
--------Start sale--------
Stopping sale-jar-with-dependencies.jar
ps -ef|grep java|grep sale-jar-with-dependencies.jar|grep -v grep|awk '{print $2}'
pid: 23418
kill -9 的pid: 23418
chmod:sale-jar-with-dependencies.jar
mkdir: 无法创建目录"log": 文件已存在
execute start:nohup java -jar sale-jar-with-dependencies.jar >log/sale-jar-with-dependencies.jar.20180202135158.log 2>1&
execute end:nohup java -jar sale-jar-with-dependencies.jar >log/sale-jar-with-dependencies.jar.20180202135158.log 2>1&
--------Start sale End--------
--------Start Report--------
Stopping report-jar-with-dependencies.jar
ps -ef|grep java|grep report-jar-with-dependencies.jar|grep -v grep|awk '{print $2}'
pid: 23428 23432 23436 23440 23444 23448 23452
kill -9 的pid: 23428
kill -9 的pid: 23432
kill -9 的pid: 23436
kill -9 的pid: 23440
kill -9 的pid: 23444
kill -9 的pid: 23448
kill -9 的pid: 23452
chmod:report-jar-with-dependencies.jar
mkdir: 无法创建目录"log": 文件已存在
execute start:nohup java -jar report-jar-with-dependencies.jar type=1 attime=false thread=1 all >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
execute end:nohup java -jar report-jar-with-dependencies.jar type=1 attime=false thread=1 all >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
chmod:report-jar-with-dependencies.jar
mkdir: 无法创建目录"log": 文件已存在
execute start:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=1 time >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
execute end:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=1 time >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
chmod:report-jar-with-dependencies.jar
mkdir: 无法创建目录"log": 文件已存在
execute start:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=2 base >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
execute end:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=2 base >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
chmod:report-jar-with-dependencies.jar
mkdir: 无法创建目录"log": 文件已存在
execute start:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=4 database >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
execute end:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=4 database >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
chmod:report-jar-with-dependencies.jar
mkdir: 无法创建目录"log": 文件已存在
execute start:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=4 msg >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
execute end:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=4 msg >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
chmod:report-jar-with-dependencies.jar
mkdir: 无法创建目录"log": 文件已存在
execute start:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=2 log >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
execute end:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=2 log >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
chmod:report-jar-with-dependencies.jar
mkdir: 无法创建目录"log": 文件已存在
execute start:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=2 qq >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
execute end:nohup java -jar report-jar-with-dependencies.jar type=2 attime=true thread=2 qq >log/report-jar-with-dependencies.jar.20180202135158.log 2>1&
--------Start Report End--------
查看是否运行
[root@master jiafujun]# ps -aux|grep java
root 12872 1.7 2.4 5402064 194004 ? Sl 15:02 0:10 java -jar storage/distribution-manager-storage-0.0.1-SNAPSHOT.jar
root 12909 1.5 3.2 5267100 254992 ? Sl 15:02 0:08 java -jar storagegateway/distribution-manager-storagegateway-0.0.1-SNAPSHOT.jar
root 12953 4.5 4.7 5402060 372096 ? Sl 15:03 0:25 java -jar distribution_query/distribution-manager-distribution-query-0.0.1-SNAPSHOT.jar
root 12981 3.0 4.3 5404112 342728 ? Sl 15:03 0:17 java -jar distribution_storage/distribution-manager-distribution-storage-0.0.1-SNAPSHOT.jar
root 13011 4.8 4.2 5404108 338192 ? Sl 15:03 0:26 java -jar query/distribution-manager-query-0.0.1-SNAPSHOT.jar
root 13080 4.7 5.4 5612056 428820 ? Sl 15:03 0:25 java -jar login/distribution-manager-login-0.0.1-SNAPSHOT.jar
root 13126 2.4 2.3 5266880 182436 ? Sl 15:03 0:13 java -jar querygateway/distribution-manager-querygateway-0.0.1-SNAPSHOT.jar
root 14701 0.1 2.7 4853352 219392 ? Sl 1月15 26:40 /home/jdk/jdk1.8.0_131/bin/java -Dzookeeper.log.dir=./log_zoo -Dzookeeper.root.logger=INFO,CONSOLE,ROLLINGFILE -cp /home/usr/local/zookeeper/bin/../build/classes:/home/usr/local/zookeeper/bin/../build/lib/slf4j-log4j12-1.6.1.jar:/home/usr/local/zookeeper/bin/../build/lib/slf4j-api-1.6.1.jar:/home/usr/local/zookeeper/bin/../build/lib/netty-3.10.5.Final.jar:/home/usr/local/zookeeper/bin/../build/lib/log4j-1.2.16.jar:/home/usr/local/zookeeper/bin/../build/lib/jline-0.9.94.jar:/home/usr/local/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/usr/local/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/home/usr/local/zookeeper/bin/../lib/netty-3.10.5.Final.jar:/home/usr/local/zookeeper/bin/../lib/log4j-1.2.16.jar:/home/usr/local/zookeeper/bin/../lib/jline-0.9.94.jar:/home/usr/local/zookeeper/bin/../zookeeper-3.4.10-ZooInspector.jar:/home/usr/local/zookeeper/bin/../zookeeper-3.4.10.jar:/home/usr/local/zookeeper/bin/../src/java/lib/ivy-2.4.0.jar:/home/usr/local/zookeeper/bin/../conf:.:/home/jdk/jdk1.8.0_131/lib/dt.jar:/home/jdk/jdk1.8.0_131/lib/tools.jar: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/usr/local/zookeeper/bin/../conf/zoo.cfg
root 15548 9.0 0.6 4454284 50612 pts/3 Sl 15:12 0:00 java -jar socket-jar-with-dependencies.jar
root 15558 17.3 1.0 4520832 81472 pts/3 Sl 15:12 0:01 java -jar sale-jar-with-dependencies.jar
root 15568 23.7 1.3 4520828 106756 pts/3 Sl 15:12 0:02 java -jar report-jar-with-dependencies.jar type=1 attime=false thread=1 all
root 15572 25.0 1.2 4520828 101924 pts/3 Sl 15:12 0:02 java -jar report-jar-with-dependencies.jar type=2 attime=true thread=1 time
root 15576 42.7 1.5 4522876 121324 pts/3 Sl 15:12 0:03 java -jar report-jar-with-dependencies.jar type=2 attime=true thread=2 base
root 15580 45.0 1.7 4524924 134628 pts/3 Sl 15:12 0:04 java -jar report-jar-with-dependencies.jar type=2 attime=true thread=4 database
root 15584 32.0 1.3 4522876 105904 pts/3 Sl 15:12 0:02 java -jar report-jar-with-dependencies.jar type=2 attime=true thread=4 msg
root 15588 36.5 1.3 4522876 109312 pts/3 Sl 15:12 0:03 java -jar report-jar-with-dependencies.jar type=2 attime=true thread=2 log
root 15592 41.1 1.5 4522876 123112 pts/3 Sl 15:12 0:03 java -jar report-jar-with-dependencies.jar type=2 attime=true thread=2 qq
root 15729 0.0 0.0 112680 972 pts/3 S+ 15:12 0:00 grep --color=auto java
root 21912 0.4 15.2 5783684 1200432 ? Sl 1月31 13:25 /home/jdk/jdk1.8.0_131/bin/java -Djava.util.logging.config.file=/home/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.endorsed.dirs=/home/tomcat/endorsed -classpath /home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/home/tomcat -Dcatalina.home=/home/tomcat -Djava.io.tmpdir=/home/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 23473 0.1 1.5 5535448 120720 ? Sl 1月30 8:10 java -jar dispatcher/distribution-dispatcher-1.0.0-SNAPSHOT.jar
root 23474 0.2 1.5 5693260 125008 ? Sl 1月30 9:19 java -jar order/distribution-order-1.0.0-SNAPSHOT.jar
root 29058 0.1 1.4 5610052 111188 pts/0 Sl 10:15 0:28 /home/jdk/jdk1.8.0_131/bin/java -Djava.util.logging.config.file=/home/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.endorsed.dirs=/home/tomcat7/endorsed -classpath /home/tomcat7/bin/bootstrap.jar:/home/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/home/tomcat7 -Dcatalina.home=/home/tomcat7 -Djava.io.tmpdir=/home/tomcat7/temp org.apache.catalina.startup.Bootstrap start
查看CPU
[root@master jiafujun]# top
top - 15:14:17 up 35 days, 20:00, 4 users, load average: 10.71, 12.83, 12.11
Tasks: 286 total, 1 running, 284 sleeping, 0 stopped, 1 zombie
%Cpu(s): 22.8 us, 1.7 sy, 0.0 ni, 17.6 id, 57.8 wa, 0.0 hi, 0.2 si, 0.0 st
KiB Mem : 7874196 total, 143720 free, 6793932 used, 936544 buff/cache
KiB Swap: 3932156 total, 497436 free, 3434720 used. 725592 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
15592 root 20 0 5544404 325148 14936 S 64.3 4.1 0:18.68 java
3384 mysql 20 0 3041796 560304 2984 S 20.0 7.1 1452:09 mysqld
15580 root 20 0 5409228 281904 14788 S 7.7 3.6 0:16.84 java
15568 root 20 0 5076408 185156 14772 S 2.0 2.4 0:15.37 java
19666 apache 20 0 507392 13652 3512 S 1.0 0.2 2:12.44 httpd
15558 root 20 0 5342668 196184 14820 S 0.7 2.5 0:11.49 java
42 root 20 0 0 0 0 S 0.3 0.0 2:15.41 kswapd0
2854 gdm 20 0 470280 816 684 S 0.3 0.0 2:01.24 ibus-daemon
8405 nobody 20 0 2350760 3452 1812 S 0.3 0.0 13:01.12 httpd
9245 root 20 0 15040 996 0 S 0.3 0.0 11:48.64 IntelliJIDEALic
12953 root 20 0 5402060 371388 10884 S 0.3 4.7 0:25.86 java
12981 root 20 0 5404112 341328 10896 S 0.3 4.3 0:17.37 java
14522 zabbix 20 0 292044 1920 1380 S 0.3 0.0 0:52.85 zabbix_server
14536 zabbix 20 0 185716 2764 1656 S 0.3 0.0 0:49.31 zabbix_server
15548 root 20 0 5276120 178408 14828 S 0.3 2.3 0:16.19 java
15584 root 20 0 5342664 210640 14772 S 0.3 2.7 0:09.77 java
23473 root 20 0 5535448 122916 5216 S 0.3 1.6 8:10.89 java
1 root 20 0 191028 2204 1276 S 0.0 0.0 2:25.49 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.79 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:04.56 ksoftirqd/0
7 root rt 0 0 0 0 S 0.0 0.0 0:00.55 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 S 0.0 0.0 43:06.38 rcu_sched
10 root rt 0 0 0 0 S 0.0 0.0 0:14.94 watchdog/0
11 root rt 0 0 0 0 S 0.0 0.0 0:15.01 watchdog/1
12 root rt 0 0 0 0 S 0.0 0.0 0:00.65 migration/1
13 root 20 0 0 0 0 S 0.0 0.0 0:39.22 ksoftirqd/1
16 root rt 0 0 0 0 S 0.0 0.0 0:13.90 watchdog/2
特别需要注意的是如下行,代表内存不够了,用的是硬件交换内存
KiB Swap: 3932156 total, 497436 free, 3434720 used. 725592 avail Mem
本文由 创作,采用 知识共享署名4.0 国际许可协议进行许可。本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为: 2020/05/07 05:06