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 就完成整个部署了

相关推荐
streaker3039 小时前
Docker + Jenkins + Nginx 实现前端自动化构建与静态资源发布(含一键初始化脚本)
docker·jenkins
zzu123zsw11 小时前
第11章 分布式构建
分布式·jenkins
zzu123zsw15 小时前
第13章 Jenkins性能优化
运维·性能优化·jenkins
Britz_Kevin16 小时前
从零开始的云计算生活——第五十八天,全力以赴,Jenkins部署
运维·jenkins·生活
程序员的世界你不懂18 小时前
【框架】基于selenium+java框架设计(0-1实战)
java·selenium·servlet
帅帅梓18 小时前
ansible-角色
linux·运维·自动化·ansible
维尔切18 小时前
自动化运维-ansible中的条件判断
运维·自动化·ansible
半梦半醒*1 天前
ansible中配置并行以及包含和导入
linux·运维·ssh·ansible·负载均衡
Akshsjsjenjd1 天前
Ansible 核心功能:循环、过滤器、判断与错误处理全解析
java·数据库·ansible