网站怎么让百度收录,长春启做网站多少,长沙建设工程信息网,前端入职后很痛苦最近把ezdpl在生产环境中实施了#xff0c;再加上这段时间的一些修改#xff0c;一并介绍一下。再次申明#xff1a; ezdpl不是开箱即用的#xff0c;需要根据自己的应用环境定制。对初学者来说使用起来反倒困难更多、风险更大。它不是一个通用的项目#xff0c;更多的是提…最近把ezdpl在生产环境中实施了再加上这段时间的一些修改一并介绍一下。再次申明 ezdpl不是开箱即用的需要根据自己的应用环境定制。对初学者来说使用起来反倒困难更多、风险更大。它不是一个通用的项目更多的是提供一种思路将繁琐的操作变得简单易行而且是用最原始的上传文件、执行脚本的方式。但是要享受简单首先要做艰苦的准备和测试工作。地址 https://github.com/Panblack/ezdpl 一、说明1、组成1) ezdpl.sh 主脚本批量部署用的 auto.sh 脚本2) 应用目录可以包含任意个版本目录3) 版本目录含files和可选的 pre.sh、fin.sh 脚本2、工作目录 ├── 应用A
│ ├── 版本1
│ │ ├── files
│ │ │ ├── etc
│ │ │ ├── usr
│ │ │ └── opt
│ │ ├── pre.sh
│ │ └── fin.sh
│ ├── 版本2
│ │ └── fin.sh
│ ├── 版本3
│ │ └── files
├── 应用B
│ └── 版本1
│ └── files
├──ezdpl.sh
└──auto.sh3、流程首先操作机需要能无密码登录所有目标服务器指令 ssh-keygen -t rsa ; ssh-copy-id 用户名目标服务器 。主脚本有2/3是判断参数和目标服务器是否合法真正的操作部分只有三处1) 如果有 pre.sh 脚本就上传并在目标服务器执行 2) 复制 files 目录下的所有文件到目标服务器的根目录 /3) 如果有 fin.sh 脚本就上传并在目标服务器执行最后判断是否要重启目标服务器。为什么要有两个脚本呢很简单复制文件之前可能需要对系统进行配置有些系统配置需要特定文件上传之后。具体怎么用看您心情。4、用法 ./ezdpl.sh Silent Mode Y|N ip address:[port] app/version [reboot Y|N(N)] [username(root)]主脚本共 5 个参数Silent Mode Y|N Y - 静默模式 N - 需要手工确认只能是 Y 或 N 。ip address:[port] 目标服务器 IP地址:端口如果目标服务器sshd端口不是默认的 22就需要指明。app/version 工作目录下的应用目录和版本比如 orders/20151012 。[reboot Y|N(N)] 执行完 fin.sh 脚本后是否重启一般新装系统往往需要重启。默认为 N可省略。[username(root)] 执行远程登录的用户名默认是 root可省略。5、最佳实践* 能用文件解决的就尽量不用脚本除非你的sed、awk、正则表达式功底深厚并且愿意承担风险。文件的好处是准确率高便于事先审核、事后排错。* 在测试环境配置一套“干净”的系统然后将配好的文件复制到 ezdpl 工作目录。记住文件需要带完整路径用 cp --parents 就可以了。* 如果有软连接则必须压缩打包再传输因为 scp 会将软连接复制成目标文件。* 稳定版本保持不动用 chattr i 指令保护起来或者打包备份防止意外修改。微小变更也要建立新的版本并加以说明以便跟踪变更历史而且利于回退。* 累积的小变更定期合并到新的稳定版。cp --parents 示例我们要从服务器 webserver1 上复制出 httpd 的配置文件 [rootwebserver1:/etc/httpd]# cp -r --parents ./conf /tmp/files结果会得到 /tmp/files/etc/httpd/conf/ 含conf内的文件和目录顺便说一下要让 CentOS 在提示符显示全路径在 /root/.bash_profile 末尾添上这一行 PS1[\u\h:$PWD]# 注意大小写、单引号并且井号后面有个空格。再执行 source /root/.bash_profile如果要让新建用户也具备这个特性在 /etc/skel/.bash_profile 末尾添上这一行 PS1[\u\h:$PWD]$ 注意要用美元符 。二、范例1、场景为新装操作系统准备的应用服务器初始化环境“应用/版本” 为 appserver/current 。 [rootoperation:/opt/ezDpl]# ll
total 28
-rw-r--r-- 1 root root 304 Oct 24 18:49 auto.sh
-rw-r--r-- 1 root root 3383 Oct 24 18:57 ezdpl.sh
drwxr-xr-x 3 root root 4096 Oct 24 13:48 appserver
drwxr-xr-x 3 root root 4096 Oct 24 13:49 loadbalance
drwxr-xr-x 3 root root 4096 Oct 24 13:49 orders
drwxr-xr-x 3 root root 4096 Oct 24 13:49 stocks
drwxr-xr-x 3 root root 4096 Oct 24 13:49 crm2、appserver目录结构 appserver/
├── current
│ ├── files
│ │ │ ├── cron.daily
│ │ │ │ └── ntpsync
│ │ │ ├── profile
│ │ │ ├── profile.d
│ │ │ │ └── colorls.sh
│ │ │ ├── security
│ │ │ │ └── limits.conf
│ │ │ ├── skel
│ │ │ │ └── .bash_profile
│ │ │ ├── sysconfig
│ │ │ │ └── iptables
│ │ │ └── sysctl.conf
│ │ ├── opt
│ │ │ ├── jdk1.8.0_65
│ │ │ │ └── bin
│ │ │ ├── logs
│ │ │ ├── packages
│ │ │ └── tomcat8
│ │ │ ├── bin
│ │ │ ├── conf
│ │ │ ├── lib
│ │ │ ├── temp
│ │ │ ├── webapps
│ │ │ └── work
│ │ └── usr
│ │ └── local
│ │ └── bin
│ ├── fin.sh
│ └── pre.sh
└──20151012└── fin.sh上述目录结构中etc目录下是已经改写好的配置文件分别为 etc/cron.daily/ntpsyncntpdate 0.pool.ntp.org 1.pool.ntp.org 自动获取网络时间etc/profile设置java环境变量etc/profile.d/colorls.sh用 2015-10-12 09:00 的格式显示文件日期时间alias llls -l --colorauto --time-stylelong-iso 2/dev/nulletc/security/limits.conf修改ulimits值以适应高并发etc/skel/.bash_profile设定新建用户的环境etc/sysconfig/iptables防火墙设置etc/sysctl.conf内核参数opt里面是基础应用比如 jdk调整好的 tomcat 等上传到目标服务器的 /opt 目录。usr/local/bin 里面是平常使用的服务器管理脚本上传到目标服务器的 /usr/local/bin 目录。3、pre.sh 脚本作用为无法连接外网的服务器配置内部 yum 源源必须事先准备好本例中源所在服务器为10.6.1.200安装必要的包备份原始配置文件。 #!/bin/bash
mkdir -p /etc/yum.repos.d/temp
mv /etc/yum.repos.d/* /etc/yum.repos.d/templocal_repo
[Local]
nameLocal repo
baseurlhttp://10.6.1.200/centos6
gpgcheck0
enabled1echo -e $local_repo /etc/yum.repos.d/local.reponginx_repo
[nginx]
namenginx repo
baseurlhttp://10.6.1.200/nginx
gpgcheck0
enabled1echo -e $nginx_repo /etc/yum.repos.d/nginx.repoyum -y install telnet man vim wget zip unzip ntpdate tree gcc iptraf tcpdump bind-utils
yum -y install nginx
echo
echo Packages installed...
echo
/bin/cp /etc/sysconfig/iptables /etc/sysconfig/iptables.date %Y%m%d
/bin/cp /etc/security/limits.conf /etc/security/limits.conf.date %Y%m%d
/bin/cp /etc/sysctl.conf /etc/sysctl.conf.date %Y%m%d
#....其余文件备份指令省略 4、fin.sh 创建用户并成为应用程序目录所有者 #!/bin/bash
useradd operuser echo HisPassWord | passwd --stdin operuser
chown -R operuser:operuser /opt 5、auto.sh 将appserver的current版本依次部署到10.6.1.x等五台服务器上。简单吧 #!/bin/bash
sh ezdpl.sh Y 10.6.1.11 appserver/current Y
sh ezdpl.sh Y 10.6.1.12 appserver/current Y
sh ezdpl.sh Y 10.6.1.13 appserver/current Y
sh ezdpl.sh Y 10.6.1.14 appserver/current Y
sh ezdpl.sh Y 10.6.1.15 appserver/current Y 为了达到并行的目的auto.sh脚本可以稍加修改比如 sh ezdpl.sh Y 10.6.1.11 appserver/current Y /tmp/10.6.1.11.log
sh ezdpl.sh Y 10.6.1.12 appserver/current Y /tmp/10.6.1.12.log
sh ezdpl.sh Y 10.6.1.13 appserver/current Y /tmp/10.6.1.13.log
...6、变更服务器运行一段时间后需要统一修改 operuser 的密码并且将该用户加入到 developing 组。将指令写入 fin.sh 脚本pre.sh 也行因为此项变更不涉及到上传文件所以没有前后之分。 #!/bin/bash
echo HisNewPassWord | passwd --stdin operuser
usermod -aG developing operuser 修改auto.sh脚本并执行。 #!/bin/bash
sh ezdpl.sh Y 10.6.1.11 appserver/20151012 Y /tmp/10.6.1.11.log
sh ezdpl.sh Y 10.6.1.12 appserver/20151012 Y /tmp/10.6.1.12.log
sh ezdpl.sh Y 10.6.1.13 appserver/20151012 Y /tmp/10.6.1.13.log
sh ezdpl.sh Y 10.6.1.14 appserver/20151012 Y /tmp/10.6.1.14.log
sh ezdpl.sh Y 10.6.1.15 appserver/20151012 Y /tmp/10.6.1.15.log 也很简单对吧 7、回退 部署了应用orders的版本20151018但是应用出现新的BUG要回退到版本20151012。 部署部署时的 pre.sh 一般要包含删除服务器当前版本的指令 sh ezdpl.sh Y 10.6.1.11 orders/20151018 Y /tmp/10.6.1.11.log
sh ezdpl.sh Y 10.6.1.12 orders/20151018 Y /tmp/10.6.1.12.log
sh ezdpl.sh Y 10.6.1.13 orders/20151018 Y /tmp/10.6.1.13.log
...回退相当于部署上一个版本当然pre.sh 脚本会先删除有BUG的 版本20151018。还是很简单吧 sh ezdpl.sh Y 10.6.1.11 orders/20151012 Y /tmp/10.6.1.11.log
sh ezdpl.sh Y 10.6.1.12 orders/20151012 Y /tmp/10.6.1.12.log
sh ezdpl.sh Y 10.6.1.13 orders/20151012 Y /tmp/10.6.1.13.log
...但是依旧强烈建议在生产环境实施之前要做充分的测试。三、ezdpl.sh 版本1.1 #!/bin/bash
# https://github.com/Panblack/ezdpl# Check Parameters
#echo $1
#echo $2
#echo $3
#echo
if [ -n $1 ]; then_silent$1if [ $_silent ! Y ]; thenif [ $_silent ! N ]; thenecho The first parameter must be Y or N. Exit!exit 1fifi
elseecho silent. Usage: ./ezdpl.sh Silent Mode Y|N ip address:[port] app/version [reboot Y|N(N)] [username(root)]exit 1
fiif [ -n $2 ]; then#Detailed param check will be needed._ipaddress$(echo $2|awk -F: {print $1})_port$(echo $2|awk -F: {print $2})if [ ${#_port} -eq 0 ]; then_port22fi
elseecho ipaddress:port. Usage: ./ezdpl.sh Silent Mode Y|N ip address:[port] app/version [reboot Y|N(N)] [username(root)]exit 1
fiif [ -n $3 ]; then_app_version$3
elseecho app/version. Usage: ./ezdpl.sh Silent Mode Y|N ip address:[port] app/version [reboot Y|N(N)] [username(root)]exit 1
fi# Optional parameters
if [ -n $4 ]; then_reboot$4
else_rebootN
fi
if [ -n $5 ]; then_username$5
else_usernameroot
fi# Silent mode or not
if [ $_silent ! Y ]; thenechoecho Ezdpl does things in a raw and simple way.echo https://github.com/Panblack/ezdplechoecho Will initialize a new server, or deploy apps to a certain server, or upgrade a production server.echo Usage: ./ezdpl.sh Silent Mode Y|N ip address:[port] app/version [reboot Y|N(N)] [username(root)]echo Manually Initialize 10.1.1.1: ./ezdpl.sh N 10.1.1.1 common/current Yecho Silently Deploy app_a to 10.1.1.1: ./ezdpl.sh Y 10.1.1.1:22 app_a/current Y rootecho Silently Upgrade 10.1.1.2s app_a: ./ezdpl.sh Y 10.1.1.2:2222 app_a/20150720echo Manually Upgrade 10.1.1.2s conf: ./ezdpl.sh N 10.1.1.2:2222 app_a/2015-10-12echo# Confirmationread -p Will overwrite configuration files or apps on $_ipaddress. Enter Y to continue: if [ $REPLY ! Y ]; thenecho Exitexit 0fi# Confirmation againread -p Are you sure? Enter Y to continue: if [ $REPLY ! Y ]; thenecho Exitexit 0fi
fi# Check
echo Target Server: ${_ipaddress}...
ssh -p $_port $_username$_ipaddress uname /dev/null
if [ $? ! 0 ]; thenechoecho $_ipaddress is not reachable. exit 1
fiif [ ! -d ./$_app_version ]; thenechoecho There is no $_app_version configured here !exit 1
fi# Everything seems OK. Go!
# Run pre.sh on the target server
if [ -f ./$_app_version/pre.sh ]; thenscp -P $_port ./$_app_version/pre.sh $_username$_ipaddress:/tmp/ssh -p $_port $_username$_ipaddress sh /tmp/pre.shecho $_username$_ipaddress:/tmp/pre.sh executed.
fi# Start copy app/version/files/*
if [ -d ./$_app_version/files ]; thenscp -P $_port -r ./$_app_version/files/* $_username$_ipaddress:/echo ./$_app_version/files/* copied.
fi# Run fin.sh on the target server
if [ -f ./$_app_version/fin.sh ]; thenscp -P $_port ./$_app_version/fin.sh $_username$_ipaddress:/tmp/ssh -p $_port $_username$_ipaddress sh /tmp/fin.shecho $_username$_ipaddress:/tmp/fin.sh executed.
fi# Reboot target server.
if [ $_reboot Y ]; thenechoecho Target server will reboot...echossh -p $_port $_username$_ipaddress reboot
fi
echo Target Server: ${_ipaddress} done!; echo
# End of ezdpl.sh 转载于:https://www.cnblogs.com/panblack/p/ezdpl_practice.html