一、前期准备
1、MySQL数据库的安装:MySQL-5.6.22,自行安装
2、Dubbo视频教程--基础篇--第03节--ZooKeeper注册中心安装
3、Dubbo视频教程--基础篇--第06节--Dubbo管理控制台的安装
4、Dubbo视频教程--基础篇--第10节--Dubbo监控中心的介绍与简易监控中心的安装
5、持续集成管理平台(SVN、Nexus、Maven、Hudson)的安装:
Dubbo视频教程--基础篇--第11节至18节
6、Dubbo视频教程--高级篇--第21节--ActiveMQ的安装与使用
7、Dubbo视频教程--高级篇--第22节--Redis的安装与使用
8、Dubbo视频教程--高级篇--第23节--FastDFS分布式文件系统的安装与使用
二、对部署环境进行规划
创建数据库
数据库编码为:UTF-8
数据库引擎为:InnoDB
导入“基于Dubbo的分布式系统架构视频教程--简易版支付系统源码.rar”中的
“数据库--edu_simple_pay.rar”中的“edu_simple_pay.sql”
调整公共配置文件
应用部署前期准备
1、common工程构建、发布到Maven私有库
尤其注意pay-common-config工程的构建(配置文件修改后需要重新构建,引用处也要重新构建)
2、facade工程构建、发布到Maven私有库
部署服务
1、规划好服务部署目录,准备好服务管理脚本
/home/wusc/edu/service/account/service-account.sh
#!/bin/sh
## java env
export JAVA_HOME=/usr/local/java/jdk1.7.0_72
export JRE_HOME=$JAVA_HOME/jre
## you just need to change this param name
APP_NAME=account
SERVICE_DIR=/home/wusc/edu/service/$APP_NAME
SERVICE_NAME=pay-service-$APP_NAME
JAR_NAME=$SERVICE_NAME\.jar
PID=$SERVICE_NAME\.pid
cd $SERVICE_DIR
case "$1" in
start)
nohup $JRE_HOME/bin/java -Xms128m -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
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
2、使用Hudson来自动化部署服务
3、通过Dubbo管控台检查各服务是否都部署成功
部署Web应用
1、规划好Web应用部署目录、端口、脚本
bank-receive-tomcat 8081
boss-tomcat 8082
gateway-tomcat 8083
notify-receive-tomcat 8084
portal-tomcat 8085
shop-tomcat 8086
trade-tomcat 8087
/home/wusc/edu/web/bank-receive-tomcat/restart.sh
## java env
export JAVA_HOME=/usr/local/java/jdk1.7.0_72
export JRE_HOME=$JAVA_HOME/jre
## restart tomcat
current_dir=$(cd `dirname $0`; pwd)
echo "=== current_dir is:$current_dir"
$current_dir/bin/shutdown.sh
sleep 3
rm -rf $current_dir/webapps/*/
sleep 2
$current_dir/bin/startup.sh
部署APP
/home/wusc/edu/app/queue-notify/app-queue-notify.sh
#!/bin/sh
## java env
export JAVA_HOME=/usr/local/java/jdk1.7.0_72
export JRE_HOME=$JAVA_HOME/jre
## you only need to change next two parameters value
APP_DIR=/home/wusc/edu/app/queue-notify
APP_NAME=pay-app-queue-notify
JAR_NAME=$APP_NAME\.jar
cd $APP_DIR
## check app process weather exists
process=`ps aux | grep -w "$APP_NAME" | grep -v grep`
if [ "$process" == "" ]; then
echo "=== $APP_NAME process not exists"
else
echo "=== $APP_NAME process exists"
echo "=== $APP_NAME process is : $process"
## get PID by process name
P_ID=`ps -ef | grep -w "$APP_NAME" | grep -v "grep" | awk '{print $2}'`
echo "=== $APP_NAME process PID is:$P_ID"
echo "=== begin kill $APP_NAME process"
kill $P_ID
sleep 3
P_ID=`ps -ef | grep -w "$APP_NAME" | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "=== $APP_NAME process stop success"
else
echo "=== $APP_NAME process kill failed, PID is:$P_ID"
echo "=== begin kill -9 $APP_NAME process, PID is:$P_ID"
sleep 3
kill -9 $P_ID
fi
fi
sleep 2
echo "=== begin start $APP_NAME"
$JRE_HOME/bin/java -Xms128m -Xmx512m -jar $APP_DIR/$JAR_NAME >/dev/null 2>&1 &
部署定时任务
定时任务的部署与调用分离
/home/wusc/edu/timer/report/timer-report.sh
#!/bin/sh
## java env
export JAVA_HOME=/usr/local/java/jdk1.7.0_72
export JRE_HOME=$JAVA_HOME/jre
## you only need to chage next two line value
SERVICE_DIR=/home/wusc/edu/timer/report
APP_NAME=pay-timer-report
JAR_NAME=$APP_NAME\.jar
sleep 1
echo "=== invoke task, please wait"
$JRE_HOME/bin/java -jar $SERVICE_DIR/$JAR_NAME >/dev/null 2>&1 &
## until process stop to print log
while true
do
process=`ps aux | grep $APP_NAME | grep -v grep`;
if [ "$process" == "" ]; then
sleep 1;
echo "=== task complete";
sleep 3;
break;
else
echo "=== process is running, please wait";
sleep 10;
continue;
fi
done