当前位置: 首页 > news >正文

基于Jenkins自动化部署PHP环境---基于rsync部署

基于基于Jenkins自动打包并部署Tomcat环境_学习新鲜事物的博客-CSDN博客环境

准备git仓库

[root@git ~]# su - git

上一次登录:五 8月 25 15:09:12 CST 2023从 192.168.50.53pts/2 上

[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.50.51:/home/git/php.git/

正克隆到 'php'...

git@192.168.50.51'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(根提交) a251610] all

 1 file changed, 3 insertions(+)

 create mode 100644 index.php

[root@git php]# git push origin master

git@192.168.50.51'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.50.51:/home/git/php.git/

 * [new branch]      master -> master

部署web主机环境

[root@tomcat ~]#  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@tomcat ~]# yum -y install rsync

[root@tomcat ~]# systemctl start httpd

[root@tomcat ~]# 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.50.54

[root@jemkins ~]# su -s /bin/bash jenkins

bash-4.2$  ssh-copy-id root@192.168.50.54

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/var/lib/jenkins/.ssh/id_rsa.pub"

The authenticity of host '192.168.50.54 (192.168.50.54)' can't be established.

ECDSA key fingerprint is SHA256:QTpNCUOIFG1aAs7OSxPHKn0MlNEnLbS7SP/V1xdN8Cg.

ECDSA key fingerprint is MD5:f8:df:e8:5f:ae:af:56:a8:e9:0c:76:13:8b:0e:07:4c.

Are you sure you want to continue connecting (yes/no)? yes

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

root@192.168.50.54's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.50.54'"

and check to make sure that only the key(s) you wanted were added.

基于rsync部署

创建一个Freestyle project

git@192.618.50.51:/home/git/php.git

 

 

rsync -avz --delete * root@192.168.50.54:/var/www/html/

 

 

 

 

[root@tomcat ~]#  ls /var/www/html/

index.php

[root@tomcat ~]#  cat /var/www/html/index.php

<?php

phpinfo();

?>

 基于ansible部署

[root@jemkins ~]# yum -y install ansible

[root@jemkins ~]#  vim /etc/ansible/hosts

 [webservers]
192.168.50.54

修改jenkins运行用户

[root@jemkins ~]# vim /usr/lib/systemd/system/jenkins.service

 34 User=root

 35 Group=root

一般在/etc/init.d/jenkins或/usr/lib/systemd/system/jenkins.service。根据不同的Linux发行版可能略有不同,请根据实际情况进行查找。

添加Ansible插件 

 创建php-ansible

 

 做好ssh密钥通联

 

 

 src=${WORKSPACE} dest=/var/www/html rsync_opts=--exclude=.git

 

 

 

 

 访问http://192.168.50.54/php-ansbile/

 再见

http://www.lryc.cn/news/141141.html

相关文章:

  • 学信息系统项目管理师第4版系列02_法律法规
  • 【大数据】Doris:基于 MPP 架构的高性能实时分析型数据库
  • 【rust/egui】(五)看看template的app.rs:SidePanel、CentralPanel以及heading
  • MTK6833_MT6833核心板_天玑700安卓5G核心板规格性能介绍
  • Maven-Java代码格式化插件spring-javaformat
  • 设计模式之八:模板方法模式
  • hive可以删除单条数据吗
  • python3-Flask实现Api接口
  • 微分享 - 超实用开发日常排查问题Linux运维命令
  • Pico如何使用C/C++选择哪个I2C控制器,以及SDA和SCL针脚
  • 求生之路2私人服务器开服搭建教程centos
  • Redis7之介绍(一)
  • 基于Python+djangoAI 农作物病虫害预警系统智能识别系统设计与实现(源码&教程)
  • Kotlin Flow 转换以及上下游处理
  • 深度学习3. 强化学习-Reinforcement learning | RL
  • TCP/IP网络江湖武艺传承:物理层与通信江湖的幕后
  • 智慧能源管理系统助力某制造企业提高能源利用效率
  • opencv/C++ 人脸检测
  • UE4/5的Custom节点:在VScode使用HLSL(新手入门用)
  • 小研究 - J2EE 应用服务器的软件老化测试研究
  • Tomcat和Servlet基础知识的讲解(JavaEE初阶系列16)
  • 开源在大数据和分析中的角色
  • C#,《小白学程序》第四课:数学计算
  • SparkML机器学习
  • vue Promise 对象 等待所有异步处理完成 再继续处理
  • 【业务功能篇84】微服务SpringCloud-ElasticSearch-Kibanan-电商实例应用
  • 图像检索,目标检测map的实现
  • Docker容器学习:Dockerfile制作Web应用系统nginx镜像
  • 【vue3.0 引入Element Plus步骤与使用】
  • 金融客户敏感信息的“精细化管控”新范式