ansible分离部署lamp架构
lamp分离部署
1、安装环境:
系统 | IP地址 | 安装服务 | 主机名 | |
---|---|---|---|---|
控制节点 | ContOS 8.2 | 192.168.56.129 | ansible | control |
受控主机 | ContOS 8.2 | 192.168.56.130 | apache | server1 |
受控主机 | ContOS 8.2 | 192.168.56.131 | php | server2 |
受控主机 | ContOS 8.2 | 192.168.56.132 | mysql | server3 |
在这之前每台机器要配置好网络仓库或者本地仓库
2、在control上编写清单文件
[root@control ~]# cd /etc/ansible/
[root@control ansible]# vim ta
[server1]
192.168.56.130 ansible_user=root ansible_password=1
[server2]
192.168.56.131 ansible_user=root ansible_password=1
[server3]
192.168.56.132 ansible_user=root ansible_password=1
查看是否ping同:
[root@control ansible]# ansible all -m ping
192.168.56.130 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
192.168.56.131 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
192.168.56.132 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
3、在server1、2、2上安装python
[root@control ansible]# ansible all -m yum -a 'name=python38 state=latest'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: python38-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64",
"Installed: python38-setuptools-41.6.0-4.module+el8.2.0+5978+503155c0.noarch",
"Installed: python38-pip-19.2.3-5.module+el8.2.0+5979+f9f0b1d2.noarch"
]
}
192.168.56.131 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: python38-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64",
"Installed: python38-setuptools-41.6.0-4.module+el8.2.0+5978+503155c0.noarch",
"Installed: python38-pip-19.2.3-5.module+el8.2.0+5979+f9f0b1d2.noarch"
]
}
192.168.56.132 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: python38-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64",
"Installed: python38-setuptools-41.6.0-4.module+el8.2.0+5978+503155c0.noarch",
"Installed: python38-pip-19.2.3-5.module+el8.2.0+5979+f9f0b1d2.noarch",
"Installed: python38-libs-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64",
"Removed: python38-libs-3.8.6-3.module_el8.4.0+665+abc3a503.x86_64"
]
}
4、在server1、2、2上关闭防火墙
//暂停防火墙
[root@control ansible]# ansible all -m service -a 'name=firewalld state=stopped'
192.168.56.131 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"name": "firewalld",
"state": "stopped",
"status": {
"ActiveEnterTimestamp": "Mon 2021-07-19 16:52:40 CST",
"ActiveEnterTimestampMonotonic": "4669816",
"ActiveExitTimestamp": "Mon 2021-07-19 20:47:26 CST",
"ActiveExitTimestampMonotonic": "14090605593",
"ActiveState": "inactive",
"After": "system.slice polkit.service dbus.socket sysinit.target dbus.service basic.target",
"AllowIsolate": "no",
"AllowedCPUs": "",
"AllowedMemoryNodes": "",
"AmbientCapabilities": "",
"AssertResult": "yes",
"AssertTimestamp": "Mon 2021-07-19 16:52:39 CST",
"AssertTimestampMonotonic": "4084673",
"Before": "shutdown.target network-pre.target multi-user.target",
"BlockIOAccounting": "no",
"BlockIOWeight": "[not set]",
"BusName": "org.fedoraproject.FirewallD1",
"CPUAccounting": "no",
"CPUAffinity": "",
"CPUQuotaPerSecUSec": "infinity",
"CPUSchedulingPolicy": "0",
"CPUSchedulingPriority": "0",
"CPUSchedulingResetOnFork": "no",
"CPUShares": "[not set]",
"CPUUsageNSec": "[not set]",
"CPUWeight": "[not set]",
"CacheDirectoryMode": "0755",
"CanIsolate": "no",
"CanReload": "yes",
"CanStart": "yes",
"CanStop": "yes",