ansible+playbook 搭建lnmp環境


用三台機器 做ansible+playbook 搭建lnmp環境 

IP分配 

ansible 主機192.168.202.132

lnmp第一台主機 192.168.202.131

lnmp第一台主機 192.168.202.133

1.1 ansible主機安裝ansible

[root@localhost ~]# yum -y install ansible
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.jdcloud.com
 * extras: mirror.bit.edu.cn 

1.2 ansible主機生成密鑰設置免密碼登錄

[root@localhost ~]# ssh -keygen
Bad escape character 'ygen'.
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_r
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_
Your public key has been saved in /root/.ssh/id_rsa.
The key fingerprint is:
SHA256:snafmBirD5A4bkRNfs/yraWQ7BqJf4SKpLd0UO5yZyA rhost
The key's randomart image is:
+---[RSA 2048]----+
|   .             |
|  +              |
| . o..           |
|.. +. o          |
|o.E +..oS        |
|oo.*oo+o.        |
|+++o*+*..o       |
|+oo+o*.=++ .     |
| ..++++oo o      |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id root@192.168.202.131
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be i "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.202.131 (192.168.2can't be established.
ECDSA key fingerprint is SHA256:+YOuMKydPwvlPwXHq3Cgj6X6jdlupF1W3A.
ECDSA key fingerprint is MD5:33:f9:54:0f:ce:1e:53:96:96:29:e3:04:7c.
Are you sure you want to continue connecting (yes/no
/usr/bin/ssh-copy-id: INFO: attempting to log in wit key(s), to filter out any that are already installe
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be in- if you are prompted now it is to install the new k
root@192.168.202.131's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root202.131'"
and check to make sure that only the key(s) you wantdded.
[root@localhost ~]# ssh-copy-id root@192.168.202.133

  

1.3 ansible主機配置

[root@localhost ~]# vim /etc/ansible/hosts 

[lnmp]
192.168.202.131
192.168.202.133

 如圖:

 

 

 1.4 編寫ansible的playbook  

---
        - hosts: lnmp
          tasks:
                - name: "安裝需要的環境"
                  yum: name=gcc,gcc-c++,make,php,php-gd,php-mysql,php-fpm,pcre-devel,zlib-devel,mariadb,mariadb-server state=latest - name: "導入nginx包" unarchive: src=nginx-1.16.1.tar.gz dest=/root - name: "編譯安裝" shell: cd /root/nginx-1.16.1 && ./configure && make && make install - name: "分發配置文件" copy: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf - name: "分發主界面" copy: src=info.php dest=/var/www/html/info.php - name: 啟動nginx shell: /usr/local/nginx/sbin/nginx - name: "啟動mysql" shell: systemctl restart mariadb - name: "啟動php-fpm" shell: systemctl restart php-fpm - name : "關閉防火牆" shell: systemctl stop firewalld - name: "關閉selinux" shell: setenforce 0 ~ 

 

 

1.4.2 更改nginx的配置文件

1.4.3 分發一個php的測試界面

1.4.4 執行ansible-playbook

 

1.4.5 展示效果看看lnmp是否搭建成功


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM