部署到edu-provider-01(192.168.1.121)
一、环境变量配置
Connecting to 192.168.1.121:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Fri Mar 25 13:36:38 2016 from 192.168.1.5
[root@edu-provider-01 ~]# ln -s /usr/java/jdk1.7.0_45/ /usr/jdk
[root@edu-provider-01 ~]# vi /etc/profile
JAVA_HOME=/usr/jdk
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
[root@edu-provider-01 ~]# java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
[root@edu-provider-01 ~]#
[root@edu-provider-01 ~]# source /etc/profile
[root@edu-provider-01 ~]# cd /home/yxq
[root@edu-provider-01 ~]# mkdir edu
[root@edu-provider-01 ~]# cd edu
[root@edu-provider-01 edu]# mkdir app
[root@edu-provider-01 edu]# mkdir serivce
[root@edu-provider-01 edu]# mkdir timer
[root@edu-provider-01 edu]# mkdir web
[root@edu-provider-01 edu]# cd serivce/
[root@edu-provider-01 serivce]# mkdir user
2.目录规范
要避免应用迁移时路径冲突
[root@edu-provider-01 serivce]# ls
user
[root@edu-provider-01 serivce]# cd user
[root@edu-provider-01 user]# ls
edu-service-user.jar lib service-user.sh
[root@edu-provider-01 user]# chmod 777 service-user.sh
[root@edu-provider-01 user]# ./service-user.sh start
=== start edu-service-user
[root@edu-provider-01 user]#
停止、重启服务
[root@edu-provider-01 user]# ./service-user.sh stop
=== stop edu-service-user
=== edu-service-user process not exists or stop success
[root@edu-provider-01 user]# ./service-user.sh restart
cat: /home/yxq/edu/serivce/user/edu-service-user.pid: No such file or directory
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
=== stop edu-service-user
=== edu-service-user process not exists or stop success
=== start edu-service-user
=== restart edu-service-user
[root@edu-provider-01 user]#
service-user.sh脚本
<span style="font-size:18px;">#!/bin/sh ## java env export JAVA_HOME=/usr/local/java/jdk1.7.0_72 export JRE_HOME=$JAVA_HOME/jre ## service name APP_NAME=user SERVICE_DIR=/home/wusc/edu/service/$APP_NAME SERVICE_NAME=edu-service-$APP_NAME JAR_NAME=$SERVICE_NAME\.jar PID=$SERVICE_NAME\.pid cd $SERVICE_DIR case "$1" in start) nohup $JRE_HOME/bin/java -Xms256m -Xmx512m -jar $JAR_NAME >/dev/null 2>&1 & echo $! > $SERVICE_DIR/$PID echo "=== start $SERVICE_NAME" ;; stop) kill `cat $SERVICE_DIR/$PID` rm -rf $SERVICE_DIR/$PID echo "=== stop $SERVICE_NAME" sleep 5 ## ## edu-service-aa.jar ## edu-service-aa-bb.jar P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "=== $SERVICE_NAME process not exists or stop success" else echo "=== $SERVICE_NAME process pid is:$P_ID" echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID" kill -9 $P_ID fi ;; restart) $0 stop sleep 2 $0 start echo "=== restart $SERVICE_NAME" ;; *) ## restart $0 stop sleep 2 $0 start ;; esac exit 0 </span>3.自定义Dubbo服务维护的Shell脚本
脚本命名规范
/hom/yxq/edu/service/xxx/service-xxx.sh
例如:
/home/yxq/edu/serivce/user/service-user.sh
效果
./service-user.sh start
./service-user.sh stop
./service-user.sh restart
5.手动维护注意事项(结合自定义的Shell脚本)
(1)脚本规范--尽可能通用
(2)守护进程
(3)内存调优设置--按需调整
(4)日志处理--只保留应用log4j输出的日志
(5).避免服务冲突--进程名、端口
(6)避免进程误杀--全匹配