基于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();
?>
相关推荐
DsirNg8 小时前
让流程会停下:AI 自动化的交班设计
自动化·可观测性·幂等性·智能体·ai 工作流·人工在环·工单分流
AI行业说9 小时前
2026年清洁耗材智能模板机品牌排名:扫地机拖布、美妆粉扑工厂自动化选型指南
运维·自动化
志栋智能10 小时前
超自动化运维:支持微服务架构的运维模式
运维·架构·自动化
XR12345678811 小时前
办公网自主创新建设怎么选?信创办公场景的选型逻辑
开发语言·php
梦想的旅途211 小时前
企业微信API如何实现自动化办公
运维·自动化·企业微信
CRMEB13 小时前
不懂设计也能有精美商城?CRMEB 主题广场与可视化装修的“千店千面“实操
人工智能·ai·小程序·开源·php
梦梦代码精13 小时前
《LikeShop全产品技术硬核拆解:ThinkPHP8+Vue3+UniApp架构,私有化部署与二次开发实战指南》
java·低代码·系统架构·php·开源软件
汉拓3D数字化13 小时前
3C自动化参数化设计实战:换线快、工装灵、机架秒变型
科技·自动化·系统·软件
SugarAbsinthe15 小时前
【Agent开发实习小记】从人工逐条验证到自动化验收:新 API 接入前的效率瓶颈
人工智能·python·自动化·pytest
辛迪聊物业数字化16 小时前
【智能楼宇系统有什么用?赋能园区高效 节能 安全】
经验分享·安全·微信小程序·php