基于jenkins自动化部署PHP环境

实验环境

|---------------|-----------------|----------------|------------|
| 操作系统 | IP 地址 | 主机名 | 角色 |
| CentOS7.5 | 192.168.147.141 | git | git服务器 |
| CentOS7.5 | 192.168.147.142 | Jenkins git客户端 | jenkins服务器 |
| CentOS7.5 | 192.168.147.143 | web | web服务器 |

具体环境配置见上一篇!

准备git仓库

复制代码
[root@git ~]# su - git
上一次登录:三 8月 23 20:41:53 CST 2023pts/0 上
[git@git ~]$ mkdir php.git
[git@git ~]$ cd php.git
[git@git php.git]$ git --bare init
初始化空的 Git 版本库于 /home/git/php.git/
[git@git php.git]$ exit
登出

上传代码到仓库

复制代码
[root@git ~]# git clone git@192.168.147.141:/home/git/php.git
正克隆到 'php'...
git@192.168.200.111's password: 
warning: 您似乎克隆了一个空版本库。
[root@git ~]# cd php/
[root@git php]# cat << EOF > index.php
<?php
phpinfo();
?>
EOF
[root@git php]# git add .
[root@git php]# git commit -m "all"
[master(根提交) 4ec0ba3] all
 1 file changed, 3 insertions(+)
 create mode 100644 index.php
[root@git php]# git push origin master
git@192.168.147.141's password: 
Counting objects: 3, done.
Writing objects: 100% (3/3), 218 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.147.141:/home/git/php.git
 * [new branch]      master -> master

部署web主机环境

复制代码
[root@web ~]# yum install -y httpd mariadb-server mariadb mariadb-devel php php-mbstring php-mysql php-bcmath php-gd php-xmlrpc php-ldap php-xml libevent libevent-devel net-snmp net-snmp-devel libxml2 libxml2-devel ntpdate
[root@web ~]# systemctl start httpd
[root@web ~]# systemctl start mariadb

Jenkins主机将密钥发布到web主机

复制代码
[root@jenkins ~]# su -s /bin/bash jenkins
bash-4.2$ ssh-keygen
bash-4.2$ ssh-copy-id root@192.168.147.143

基于rsync部署

创建一个Freestyle project

build Now

基于ansible部署

复制代码
[root@jenkins ~]# rpm -ivh epel-release-latest-7.noarch.rpm 
[root@jenkins ~]# yum -y install ansible
[root@jenkins ~]# vim /etc/ansible/hosts
[webserver]
192.168.147.143

修改jenkins运行用户

复制代码
[root@jenkins ~]# vim /etc/sysconfig/jenkins 
JENKINS_USER="root"
[root@jenkins ~]# jenkins restart

添加Ansible插件

复制代码
[root@web ~]# cat /var/www/html/php-ansible/index.php 
<?php
phpinfo();
?>
相关推荐
HAHAXX81 小时前
淘宝RPA定时拉取交易数据实战:从人工录单报错到自动化对账全流程复盘
运维·自动化·rpa
虎鲸不是鱼1 小时前
【虎鲸进化论 09】活下去:自启、守护、探活
人工智能·自动化·大模型·llm·自进化agent
2301_32241428042 小时前
基于web的校园失物招领管理系统59695-计算机毕设 原创(免费领源码+部署教程+开发环境)
mysql·nginx·php·apache·thinkphp·phpstudy·wampserver
xixiaoyunya4 小时前
把网站状态巡检自动化:从“每天手动刷一遍”到秒级无人值守
运维·自动化
霍格沃兹测试学院-小舟畅学4 小时前
Playwright MCP:基于页面语义理解的元素定位与浏览器自动化操作
运维·自动化
4SAPI5 小时前
官方API、API聚合平台与自建LLM Gateway:三种方案怎么选
大数据·人工智能·gateway·php
智商网输送线配件5 小时前
电子制造零散耗材补货实战:小批量混批采购平台怎么选才不停机?
大数据·服务器·前端·数据库·自动化
sbjdhjd6 小时前
从 preg_replace 规则到缓存绕过:一次授权 PHP 防护实验中的图片载荷、回调检测与哈希碰撞复盘
网络安全·数据挖掘·php·文件包含·宝塔·哈希·火绒
青企通6 小时前
传统企业数字化转型的技术路径:从需求建模到小程序 MVP 的落地方法
小程序·php·apache
虎鲸不是鱼6 小时前
【虎鲸进化论 07】给 AI 装上手和脚:MCP 协议与“给 Agent 用的工具“设计
人工智能·自动化·大模型·llm·自进化agent