Jenkins调用ansible部署lnmp

一、Jenkins主机中安装并配置ansible

1、安装ansible

apl 复制代码
jenkinsIP:192.168.157.111
部署对象:192.168.157.112
[root@jenkins ~]# yum install -y ansible

2、修改配置

apl 复制代码
[root@jenkins ~]#vim /etc/ansible/ansible.cfg
开启
remote_user=root

3、添加目标主机组

apl 复制代码
[root@jenkins ~]# vim /etc/ansible/hosts 
[webServer]
192.168.157.112

4、生成jenkins用户的密码

apl 复制代码
[root@jenkins ~]# su -s /bin/bash jenkins
bash-5.2$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_ed25519): 
Created directory '/var/lib/jenkins/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /var/lib/jenkins/.ssh/id_ed25519
Your public key has been saved in /var/lib/jenkins/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:ybQ5QYHak9Z/LRi3EGyGNHyEDO98FO/80KgzZJNMW2U jenkins@jenkins
The key's randomart image is:
+--[ED25519 256]--+
|      .*=*o   E  |
|      .o=.*o o   |
|     o o++o.o    |
|    . ==.Oo*.o   |
|     . .S.O==o.  |
|         =oo+o.  |
|          +. ..  |
|           o     |
|                 |
+----[SHA256]-----+

##把密钥拷贝给部署对象root账户
bash-5.2$ ssh-copy-id root@192.168.157.112

二、Jenkins配置ansible插件

1.安装ansible插件

2.配置ansible

/usr/bin/ ansible命令存放位置

三、构建项目

1.构建主item

新建item

env设置

配置构建步骤

进行构建

构建结果

验证

apl 复制代码
[root@localhost ~]# rpm -q nginx
nginx-1.24.0-5.oe2403sp1.x86_64
[root@localhost ~]# rpm -q mysql
mysql-8.0.43-1.oe2403sp1.x86_64
[root@localhost ~]# rpm -q php-fpm
php-fpm-8.3.24-1.oe2403sp1.x86_64

2.添加步骤

分布执行否则不成功

开启php-fpm

开启mysqld

开启nginx

验证

apl 复制代码
[root@localhost ~]# systemctl is-enabled nginx
enabled
[root@localhost ~]# systemctl is-enabled mysqld
enabled
[root@localhost ~]# systemctl is-enabled php-fpm
enabled

3.测试item

3.1新建item

php构建

apl 复制代码
echo -e "<?php\nphpinfo();\n?>" > /usr/share/nginx/html/php.php

mysql配置

apl 复制代码
echo -e '<?php\n$link=mysqli_connect("127.0.0.1","root","");\nif ($link)\n{\n echo "OK";\n}\nmysqli_close($link);\n?>' > /usr/share/nginx/html/mysql.php

3.2与主item关联

在lnmp-ansible里面操作

测试


4.部署item(dicuz)

1.导入discuz安装包

apl 复制代码
[root@jenkins ~]# mkdir /data
[root@jenkins data]# ls
discuz.zip

2.新建部署item

3.测试

直接一直下一步,只设置admin密码即可

4.关联测试item

在lnmp-test中添加

5.整体测试

后面只需要执行lmp-ansible 就完成整个部署了

6-1756948837358)]

4.关联测试item

在lnmp-test中添加

5.整体测试

后面只需要执行lmp-ansible 就完成整个部署了

相关推荐
闲人编程6 小时前
Elasticsearch搜索引擎集成指南
python·elasticsearch·搜索引擎·jenkins·索引·副本·分片
Sheffield9 小时前
command和shell模块到底区别在哪?
linux·云计算·ansible
陈桴浮海11 小时前
【Linux&Ansible】学习笔记合集二
linux·学习·ansible
馨谙15 小时前
Ansible模块化Playbook管理:静态导入与动态包含详解
运维·ansible
vx_Biye_Design1 天前
【关注可免费领取源码】房屋出租系统的设计与实现--毕设附源码40805
java·spring boot·spring·spring cloud·servlet·eclipse·课程设计
人间打气筒(Ada)2 天前
jenkins基于Pipeline发布项目
java·pipeline·jenkins·流水线·ci·cd·cicd
vx_Biye_Design2 天前
基于Spring Boot+vue的湖北旅游景点门票预约平台的设计--毕设附源码29593
java·vue.js·spring boot·spring cloud·servlet·eclipse·课程设计
馨谙2 天前
Ansible 事实(Facts)全面指南:自动化运维中的主机信息管理
运维·ansible
馨谙2 天前
Ansible处理程序完全指南:实现智能的任务触发机制
运维·ansible
lang201509282 天前
JSR-340 :高性能Web开发新标准
java·前端·servlet