这篇文章帮你解决下列问题:
源码获取,源码编译,处理配置文件,应用部署,远程备份,部署回撤,启动,服务器状态,停止
目录
在你的企业中是怎样完成从开发,测试到运维的?
很多企业的升级是这样做的,写完代码后编译打包,放到FTP上,同时发送一个升级邮件。然后让运维按照升级文档,一步一步操作。
这样的流程有很多问题
稍先进一点做法是使用Subversion/Git,开发将代码放到版本库中,运维直接使用 svn up / git pull 升级,这样做法也有很多问题存在
我们需要什么样的流程或者什么样的流程才是最理想流程?
我认为:
开发,测试,运维各司其职,这就是DevOps。
实现自动化部署有很多方法,很多年前笔者就开始研究总结,下面是一些经验分享。
开发,测试,生产三个环境的配置如果出自同一个模板会减少很多由于环境差异带来的困扰。
过程 1. 操作系统部署
实现应用程序自动部署,首先你要清楚自动部署所需要的流程,部署一个流程通常是这样的:
过程 2. 自动部署步骤
自动部署程序完成上面的部署,还需要做下面一些事情。
日志功能
准备一个全新的的服务器,最小化安装CentOS 7操作系统,然后运行下面脚本初始化
curl -s https://raw.githubusercontent.com/oscm/shell/master/os/centos7.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/os/selinux.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/os/iptables/iptables.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/os/ntpd/ntp.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/os/ssh/sshd_config.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/os/user/www.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/gcc/gcc.sh | bash
安装 server-jre 与 apache-tomcat
curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/java/server-jre-8u40.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/web/tomcat/apache-tomcat-8.0.26.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/web/tomcat/systemctl.sh | bash
请使用systemctl 启动与停止 Tomcat
systemctl start tomcat
systemctl stop tomcat
Infrastructure Management Shell https://github.com/oscm/shell
安装Ant
curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/java/ant.sh | bash
下载build.xml文件 https://github.com/oscm/build/tree/master/Ant
wget https://raw.githubusercontent.com/oscm/build/master/Ant/build.xml
打开 build.xml 文件
修改下面几处定义
<property name="repository" value="版本库地址" />
<property name="branch" value="部署分支" />
<property name="remote" value="远程服务器" />
<property name="destination" value="远程目录" />
开始部署代码
ant backup
ant stop
ant deploy
ant start
如果你想学习制作部署工具,还可以看看笔者早期的作品https://github.com/oscm/deployment这个工具使用Bash开发,写这个工具仅仅半天时间,后面小改过几次,这个工具伴随笔者很多年。
第一个版本因为很多缺陷存在,笔者使用Python重新开发 https://github.com/oscm/devops 这个工具更适合PHP项目部署