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

相关推荐
开发者联盟league7 小时前
使用jenkins pipeline将项目打包运行在k8s上报错kubectl: Permission denied
java·kubernetes·jenkins
江华森8 小时前
Jenkins 运维管理实战博客大纲
运维·jenkins
X1A0RAN8 小时前
解决jenkins(本机部署或容器部署)安全机制【CSP】问题
jenkins·allure报告
烧饼Fighting8 小时前
Jenkins自动化编译部署Spring Boot项目
spring boot·自动化·jenkins
serve the people8 小时前
Elasticsearch(3) show me some examples
大数据·elasticsearch·jenkins
牛奶咖啡139 小时前
CI/CD——通过Jenkins插件实现与K8s集成并部署应用到k8s集群的实践保姆级教程
ci/cd·kubernetes·jenkins·jenkins安装k8s插件·jenkins对k8s配置凭据·jenkins配置pod模板·编写流水线脚本部署应用到k8s
serve the people9 小时前
Elasticsearch(4) show me some more advanced content
大数据·elasticsearch·jenkins
兄台の请冷静21 小时前
Linux 安装es
linux·elasticsearch·jenkins
就叫_这个吧1 天前
IDEA中Javaweb项目创建+servlet,实现简单的信息录入获取
java·servlet·intellij-idea·web
就叫_这个吧1 天前
servlet整合tomcat项目启动报错解决,org.apache.tomcat.util.descriptor.web.WebXml.setVersion
java·servlet·tomcat·apache