Jenkins调用ansible部署lnmp平台

目录

一、准备工作

1.1、准备两台虚拟机

1.2、配置文件

1.3、Jenkins网页安装ansible插件

二、构建项目

1.构建主item

3.测试item

3.1新建item

3.2与主item关联

4.部署item(dicuz)

2.新建部署item

3.测试

4.关联测试item

5.整体测试


一、准备工作

1.1、准备两台虚拟机

服务器:192.168.80.186(jenkins)

客户端:192.168.80.183

1.2、配置文件

安装ansible

复制代码
 [root@jenkins ~]# yum -y install ansible

修改配置文件

复制代码
 #将107行的注释去掉
 [root@jenkins ~]# vim /etc/ansible/ansible.cfg
 107 remote_user = root   

添加目标主机

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

生成jenkins用户的密码

cs 复制代码
[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:OYuvQOatCCe5YmcPc+xvJFdFY7TptUQJ+wQluaCfWOk jenkins@jenkins
The key's randomart image is:
+--[ED25519 256]--+
|          oO+o.  |
|         ..oO.   |
|        . ++.+   |
|       . =..= .  |
|    o   S .. o   |
| . +.o = E       |
|+ .ooo* .        |
|.* +=o o         |
|+ + oo+o.        |
+----[SHA256]-----+


将密钥拷给客户端root用户
bash-5.2$ ssh-copy-id root@192.168.80.183


bash-5.2$ ansible webServer -m ping
[WARNING]: Platform linux on host 192.168.80.183 is using the discovered Python interpreter at /usr/bin/python3, but future
installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
192.168.80.183 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}

1.3、Jenkins网页安装ansible插件

配置ansible

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

二、构建项目

1.构建主item

新建item

env设置

配置构建步骤

进行构建

构建结果

去客户机验证

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

2.添加步骤

必须分布执行否则不成功

开启php-fpm

开启mysqld

开启nginx

去客户端验证

cs 复制代码
[root@nfs-server ~]# systemctl is-enabled nginx
enabled
[root@nfs-server ~]# systemctl is-enabled mysqld
enabled
[root@nfs-server ~]# systemctl is-enabled php-fpm.service 
enabled

3.测试item

3.1新建item

php构建

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

mysql配置

cs 复制代码
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)

cs 复制代码
[root@jenkins ~]# mkdir /data
[root@jenkins data]# ls
discuz.zip
2.新建部署item
3.测试

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

4.关联测试item

在lnmp-test中添加

5.整体测试

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

相关推荐
晚风吹人醒.15 分钟前
SSH远程管理及访问控制
linux·运维·ssh·scp·xshell·访问控制·远程管理
necessary6532 小时前
使用Clion查看linux环境中的PG源码
linux·运维·服务器
江湖有缘3 小时前
Jump个人仪表盘Docker化部署教程:从0到 搭建专属导航页
运维·docker·容器
FL16238631293 小时前
win11+WSL+Ubuntu-xrdp+远程桌面闪退+黑屏闪退解决
linux·运维·ubuntu
AOwhisky4 小时前
Linux逻辑卷管理:从“固定隔间”到“弹性存储池”的智慧
linux·运维·服务器
05大叔5 小时前
大事件Day02
运维·服务器
C Yu小白5 小时前
Linux系统调用与文件操作详解
linux·运维·服务器
ZFB00016 小时前
【麒麟桌面系统】V10-SP1 2503 系统知识——常见用户组简介
linux·运维·kylin
acrelgxy6 小时前
告别被动抢修与盲目巡检!安科瑞运维云平台,让电力系统实现预测性守护。
运维·电力监控系统·智能电力仪表
f***28146 小时前
Springboot中使用Elasticsearch(部署+使用+讲解 最完整)
spring boot·elasticsearch·jenkins