标签:method bin 内容 python touch XML remove running ssh
1,用户所有的web服务,都应该使用普通用户。所有web服务都不应该监听80端口,除了负载均衡
新建www用户
useradd www
ssh-keygen -t rsa
cat id_rsa.pub
把内容复制到客户端的 ~.ssh/authorized_keys (权限644)
可以通过ssh ip 直接免密码进入
vim deploy.sh
#!/bin/bash #Node List NODE_LIST="10.0.0.154" #Date/Time Veriables LOG_DATE=‘date "+%Y-%m-%d"‘ LOG_TIME=‘date "+%H-%M-%S"‘ CDATE=$(date "+%Y-%m-%d") CTIME=$(date "+%H-%M-%S") #Shell Env SHELL_NAME="deploy.sh" SHELL_DIR="/home/www" SHELL_LOG="${SHELL_DIR}/${SHELL_NAME}.log" # Code Env PRO_NAME="web-demo" CODE_DIR="/deploy/code/web-demo" CONFIG_DIR="/deploy/config/web-demo" TMP_DIR="/deploy/tmp" TAR_DIR="/deploy/tar" LOCK_FILE="/tmp/deploy.lock" usage(){ echo $"Usage:$0[deploy|roolback]" } writelog(){ LOGINFO=$1 echo "${CDATE} ${CTIME}: ${SHELL_NAME}: ${LOGINFO} " >> ${SHELL_LOG} } shell_lock(){ touch ${LOCK_FILE} } shell_unlock(){ rm -f ${LOCK_FILE} } code_get(){ writelog "code_get"; cd $CODE_DIR && echo "git pull" cp -r ${CODE_DIR} ${TMP_DIR}/ API_VER="123" } code_build(){ echo code_get } code_config(){ writelog "code_config" /bin/cp -r ${CONFIG_DIR}/base/* ${TMP_DIR}/"${PRO_NAME}" PKG_NAME="${PRO_NAME}"_"${API_VER}"_"${CDATE}-${CTIME}" cd ${TMP_DIR} && mv ${PRO_NAME} ${PKG_NAME} } code_tar(){ writelog "code_tar" cd ${TMP_DIR} && tar czf ${PKG_NAME}.tar.gz ${PKG_NAME} writelog "${PKG_NAME}.tar.gz" } code_scp(){ writelog "code_scp" for node in $NODE_LIST;do scp ${TMP_DIR}/${PKG_NAME}.tar.gz $node:/opt/webroot/ done } cluster_node_remove(){ writelog "cluster_node_remove" } code_deploy(){ for node in $NODE_LIST;do ssh $node "cd /opt/webroot && tar zxf ${PKG_NAME}.tar.gz" done scp ${CONFIG_DIR}/other/192.168.56.12.crontab.xml 10.0.0.154:/opt/webroot/${PKG_NAME}/crontab.xml rm -rf /web/root-demo && ln -s /opt/webroot/${PKG_NAME} /webroot/web-demo } config_diff(){ echo config_diff } code_test(){ echo code_test } cluster_node_in(){ echo cluster_node_in } rollback(){ echo rollback } main(){ if [ -f $LOCK_FILE ];then echo "Deploy is running" && exit; fi DEPLOY_METHOD=$1 case $DEPLOY_METHOD in deploy) shell_lock; code_get; code_build; code_config; code_tar; code_scp; cluster_node_remove; code_deploy; code_test; cluster_node_in; shell_unlock; ;; roolback) shell_lock; rollback; shell_unlock; ;; *) usage; esac } main $1
标签:method bin 内容 python touch XML remove running ssh
原文地址:http://www.cnblogs.com/minseo/p/6938680.html