news 2026/5/27 11:21:19

今天我们继续DevOps内容Jenkins自动化部署PHP项目

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
今天我们继续DevOps内容Jenkins自动化部署PHP项目

1、实验环境

需要准备三台服务器充当:git、jenkins、web

2、准备git仓库

[root@git ~]# useradd git [root@git ~]# echo "123" | passwd --stdin git [root@git ~]# su - git 上一次登录:三 8月 23 20:41:53 CST 2023pts/0 上 [git@git ~]$ mkdir php.git [git@git ~]$ cd php.git #--bare:创建一个裸仓库。裸仓库是一种特殊的Git仓库,它不包含工作目录(没有文件的检出和编辑空间),主要用于共享,是作为远程仓#库被其他仓库推送(push)和拉取(pull)的中心存储库。 [git@git php.git]$ git --bare init #初始化空的 Git 版本库于 /home/git/php.git/ [git@git php.git]$ exit #登出

3、上传代码到仓库

[root@git ~]# git clone git@192.168.166.9:/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.166.9'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.166.9:/home/git/php.git * [new branch] master -> master

4、部署web主机环境

yum install -y nginx php php-mysqlnd mysql-server php-fpm cd /etc/nginx/ mv nginx.conf nginx.conf.back cp nginx.conf.default nginx.conf vim nginx.conf http { ... include conf.d/*.conf; ... server { ... location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; root html; fastcgi_pass php-fpm; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; } ... } } systemctl start php-fpm mysqld nginx

6、基于rsync部署

创建一个Freestyle project

7、 基于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.166.6

修改jenkins运行用户

[root@jenkins ~]# vim /usr/lib/systemd/system/jenkins.service User=root Group=root [root@jenkins ~]# systemctl daemon-reload [root@jenkins ~]# systemctl restart jenkins ###设置SSH的免密登录 [root@jenkins ~]# ssh-keygen -N '' -f ~/.ssh/id_rsa [root@jenkins ~]# ssh-copy-id root@192.168.158.5 [root@jenkins ~]# ssh-copy-id git@192.168.158.4

添加Ansible插件

[root@web ~]# cat /etc/nginx/nginx.conf server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html/php-ansible; index index.html index.php; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; ..... [root@web ~]# systemctl restart nginx
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/16 9:34:27

免费开源PLC编程工具:OpenPLC Editor完全上手指南

免费开源PLC编程工具&#xff1a;OpenPLC Editor完全上手指南 【免费下载链接】OpenPLC_Editor 项目地址: https://gitcode.com/gh_mirrors/ope/OpenPLC_Editor 在工业自动化快速发展的今天&#xff0c;寻找一款功能强大且易于使用的开源PLC编程工具成为工程师们的共同…

作者头像 李华
网站建设 2026/5/25 20:17:15

Windows系统优化利器:一键清理冗余组件,提升电脑性能

Windows系统优化利器&#xff1a;一键清理冗余组件&#xff0c;提升电脑性能 【免费下载链接】Win10BloatRemover Configurable CLI tool to easily and aggressively debloat and tweak Windows 10 by removing preinstalled UWP apps, services and more. Originally based o…

作者头像 李华
网站建设 2026/5/26 22:13:08

RuoYi-Flowable工作流平台从零部署到实战应用完全指南

RuoYi-Flowable工作流平台从零部署到实战应用完全指南 【免费下载链接】RuoYi-Flowable-Plus 本项目基于 RuoYi-Vue-Plus 进行二次开发扩展Flowable工作流功能&#xff0c;支持在线表单设计和丰富的工作流程设计能力。如果觉得这个项目不错&#xff0c;麻烦点个star&#x1f31…

作者头像 李华
网站建设 2026/5/13 22:18:58

SuperPNG终极指南:免费快速实现Photoshop无损图像压缩

还在为Photoshop导出的PNG文件体积过大而烦恼吗&#xff1f;SuperPNG插件就是你的救星&#xff01;这款强大的免费工具能让图像在保持完美画质的同时&#xff0c;文件体积锐减50%以上。无论你是网页设计师、摄影师还是普通用户&#xff0c;都能轻松上手。 【免费下载链接】Supe…

作者头像 李华
网站建设 2026/5/2 14:23:00

Visual C++运行库完全修复指南:从基础安装到企业级部署

Visual C运行库完全修复指南&#xff1a;从基础安装到企业级部署 【免费下载链接】vcredist AIO Repack for latest Microsoft Visual C Redistributable Runtimes 项目地址: https://gitcode.com/gh_mirrors/vc/vcredist 当游戏闪退、专业软件报错"找不到MSVCP140.…

作者头像 李华
网站建设 2026/5/3 4:44:53

B站视频本地化保存全攻略:解锁高清资源永久收藏

还记得那个让你反复回味的B站视频吗&#xff1f;当它突然下架时&#xff0c;那份遗憾是否还萦绕心头&#xff1f;在这个数字内容瞬息万变的时代&#xff0c;掌握视频本地化保存技能已成为数字时代必备能力。 【免费下载链接】bilibili-downloader B站视频下载&#xff0c;支持下…

作者头像 李华