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

相关推荐
...对方正在输入......13 小时前
Elasticsearch集群部署实战指南
elasticsearch·jenkins
程序员潇潇16 小时前
Jenkins 插件下载速度慢安装失败?这篇文章可能解决你头等难题!
运维·自动化测试·软件测试·功能测试·程序人生·职场和发展·jenkins
LSL666_20 小时前
1 概述及简单登录(不涉及数据库)
数据库·servlet
ζั͡山 ั͡有扶苏 ั͡✾1 天前
EFK 日志系统搭建完整教程
运维·jenkins·kibana·es·filebeat
合作小小程序员小小店1 天前
网页开发,在线%旧版本旅游管理%系统,基于eclipse,html,css,jquery,servlet,jsp,mysql数据库
java·数据库·servlet·eclipse·jdk·旅游·jsp
小晶晶京京2 天前
day62-gitlab和JenKins
运维·gitlab·jenkins
奔跑吧邓邓子2 天前
Jenkins自动化持续集成:从入门到实战
ci/cd·自动化·实战·jenkins·自动化持续集成
老板多放葱和香菜2 天前
1大数据平台及组件搭建https://baijiahao.baidu.com/s?id=1849543147230084630
java·大数据·servlet
百***35942 天前
从0到1部署Tomcat和添加servlet(IDEA2024最新版详细教程)
hive·servlet·tomcat
e***0962 天前
Springboot中使用Elasticsearch(部署+使用+讲解 最完整)
spring boot·elasticsearch·jenkins