Dubbo基础篇--在Linux操作系统上手工部署Dubbo服务

部署到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]# 

Dubbo基础篇--在Linux操作系统上手工部署Dubbo服务_第1张图片

停止、重启服务

[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脚本

[cpp]  view plain  copy
 
  1. #!/bin/sh  
  2.   
  3. ## java env  
  4. export JAVA_HOME=/usr/local/java/jdk1.7.0_72  
  5. export JRE_HOME=$JAVA_HOME/jre  
  6.   
  7. ## service name  
  8. APP_NAME=user  
  9.   
  10. SERVICE_DIR=/home/wusc/edu/service/$APP_NAME  
  11. SERVICE_NAME=edu-service-$APP_NAME  
  12. JAR_NAME=$SERVICE_NAME\.jar  
  13. PID=$SERVICE_NAME\.pid  
  14.   
  15. cd $SERVICE_DIR  
  16.   
  17. case "$1" in  
  18.   
  19.     start)  
  20.         nohup $JRE_HOME/bin/java -Xms256m -Xmx512m -jar $JAR_NAME >/dev/null 2>&1 &  
  21.         echo $! > $SERVICE_DIR/$PID  
  22.         echo "=== start $SERVICE_NAME"  
  23.         ;;  
  24.   
  25.     stop)  
  26.         kill `cat $SERVICE_DIR/$PID`  
  27.         rm -rf $SERVICE_DIR/$PID  
  28.         echo "=== stop $SERVICE_NAME"  
  29.   
  30.         sleep 5  
  31.         ##  
  32.         ## edu-service-aa.jar  
  33.         ## edu-service-aa-bb.jar  
  34.         P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`  
  35.         if [ "$P_ID" == "" ]; then  
  36.             echo "=== $SERVICE_NAME process not exists or stop success"  
  37.         else  
  38.             echo "=== $SERVICE_NAME process pid is:$P_ID"  
  39.             echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID"  
  40.             kill -9 $P_ID  
  41.         fi  
  42.         ;;  
  43.   
  44.     restart)  
  45.         $0 stop  
  46.         sleep 2  
  47.         $0 start  
  48.         echo "=== restart $SERVICE_NAME"  
  49.         ;;  
  50.   
  51.     *)  
  52.         ## restart  
  53.         $0 stop  
  54.         sleep 2  
  55.         $0 start  
  56.         ;;  
  57.   
  58. esac  
  59. exit 0  
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)避免进程误杀--全匹配


你可能感兴趣的:(手动部署dubbo服务,把dubbo打成jar包)