基于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();
?>
相关推荐
电化学仪器白超1 小时前
小乌龟Git全程图形化操作指南:嵌入式本地版本管理与Gitee私有云备份实战
git·python·单片机·嵌入式硬件·物联网·gitee·自动化
没有口袋啦2 小时前
《基于 GitOps 理念的企业级自动化 CI/CD 流水线》
阿里云·ci/cd·云原生·自动化·k8s
liulilittle4 小时前
Prompt for OpenCode + CodeX-5.3:多个重型任务交付给AI自动化完成
运维·自动化·prompt
M158227690555 小时前
工业 CAN 总线无线互联利器|4 路 CAN 转 4G/WiFi 网关 产品介绍
开发语言·php
zhensherlock5 小时前
Protocol Launcher 系列:Overcast 一键订阅播客
前端·javascript·typescript·node.js·自动化·github·js
小程故事多_806 小时前
破局AI Agent落地困境,Harness六大组件全解析与实践启示
人工智能·自动化·ai编程
niucloud-admin7 小时前
PHP SAAS 框架常见问题——配置问题——地图配置报错
php
古月方枘Fry7 小时前
三层交换+VRRP实现负载
开发语言·网络·php
Agent产品评测局8 小时前
企业流程异常处理自动化落地,预警处置全流程实现方案:2026企业“数字免疫系统”构建指南
运维·人工智能·ai·chatgpt·自动化
萑澈9 小时前
实践教程:我如何用 n8n 自动化“软著申请”中最头疼的文档撰写工作
运维·elasticsearch·自动化