基于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();
?>
相关推荐
2401_894915532 小时前
Geo 优化源码部署常见报错排查:连接失败、地图加载、地域词失效解决方案
服务器·开发语言·python·安全·php
2601_965798472 小时前
My Honest Review of Rank Math SEO Pro for Beginner Sites
数据库·人工智能·php
一夜白头催人泪5 小时前
从0到1搭建AI驱动的UI自动化:无代码DOM设计文档
人工智能·ui·自动化
JXJD20046 小时前
AI 推理服务器高速连接器线束自动化设备定制指南 全场景互连非标整线方案参考
服务器·人工智能·自动化
DeepVisionary6 小时前
再观察小星火:当大厂分成“冰封“,国产轻模式创作者平台如何跑出加速度
python·自动化
vx-程序开发6 小时前
django医院预约挂号系统---附源码23353
java·javascript·spring boot·python·eclipse·django·php
小杨互联网7 小时前
Cursor 前端 Dist 自动化逆向框架:/fr 流水线 · 4 脚本 · Vite/Webpack
前端·webpack·自动化·前端逆向框架·ai前端逆向框架
Nayxxu7 小时前
Gemini Computer Use 安全清单:浏览器、桌面、移动端自动化怎么控权限
运维·安全·自动化
minhuan7 小时前
大模型应用CI/CD全流程解析:打通模型训练、评估、部署自动化,应用持续迭代实践23.7
ci/cd·自动化·大模型应用·大模型应用ci/cd全流程解析·大模型应用工程体系
愚公搬代码7 小时前
【愚公系列】《WorkBuddy从上手到变现》017-用AI Agent实现公众号自动化运营(从1个号到矩阵:规模化的可能和边界)
运维·人工智能·自动化·小龙虾·workbuddy