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

相关推荐
heimeiyingwang10 小时前
【GitOps·入门篇】工具生态:ArgoCD、Flux、Jenkins X 对比选型
jenkins·flux·argocd·gitops
酷可达拉斯14 小时前
自动化运维-Ansible任务控制与流程控制
运维·自动化·ansible
秦渝兴16 小时前
Ansible 自动化部署 K8s 三节点集群(完整教程)
kubernetes·自动化·ansible
骇客野人18 小时前
基于Nginx+Eureka+Apollo+Jenkins+SpringBoot Web系统分布式部署方案
nginx·eureka·jenkins
中才实用2 天前
Jenkins自动化部署
运维·自动化·jenkins
酷可达拉斯3 天前
自动化运维-Ansible触发器与变量
运维·服务器·自动化·ansible
童槿顏丶5 天前
Jenkins部署(Docker)
java·docker·jenkins
lv__pf7 天前
servlet与jsp
java·开发语言·servlet
Elastic 中国社区官方博客8 天前
使用 Elasticsearch open inference API 对 OpenAI chat completions 进行支持
大数据·elasticsearch·搜索引擎·全文检索·jenkins
风起洛阳@不良使10 天前
Servlet体系
servlet