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",
"CapabilityBoundingSet": "cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_fsetid cap_kill cap_setgid cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config cap_mknod cap_lease cap_audit_write cap_audit_control cap_setfcap cap_mac_override cap_mac_admin cap_syslog cap_wake_alarm cap_block_suspend",
......
......
//更改SELINUX
[root@control ansible]# ansible all -m lineinfile -a 'path=/etc/selinux/config regexp="^SELINUX=" line="SELINUX=disabled"'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line replaced"
}
192.168.56.131 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line replaced"
}
192.168.56.132 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line replaced"
}
//查看selinux
[root@control ansible]# ansible all -m shell -a 'cat /etc/selinux/config'
192.168.56.131 | CHANGED | rc=0 >>
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
192.168.56.130 | CHANGED | rc=0 >>
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
192.168.56.132 | CHANGED | rc=0 >>
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
//临时关闭
[root@control ansible]# ansible all -m shell -a 'setenforce 0'
192.168.56.131 | CHANGED | rc=0 >>
192.168.56.132 | CHANGED | rc=0 >>
192.168.56.130 | CHANGED | rc=0 >>
测试:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PFdmFwIg-1626828126595)(C:\Users\zzmxnh\AppData\Roaming\Typora\typora-user-images\image-20210720160330876.png)]
5、安装apache
//安装httpd
[root@control ansible]# ansible server1 -m yum -a 'name=httpd state=present'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: apr-util-1.6.1-6.el8.x86_64",
"Installed: redhat-logos-httpd-81.1-1.el8.noarch",
"Installed: apr-util-bdb-1.6.1-6.el8.x86_64",
"Installed: httpd-2.4.37-21.module+el8.2.0+5008+cca404a3.x86_64",
"Installed: httpd-filesystem-2.4.37-21.module+el8.2.0+5008+cca404a3.noarch",
......
//启动服务并开机自启
[root@control ansible]# ansible server1 -m service -a 'name=httpd state=started enabled=yes'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"enabled": true,
"name": "httpd",
"state": "started",
"status": {
"ActiveEnterTimestampMonotonic": "0",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "inactive",
"After": "system.slice nss-lookup.target sysinit.target -.mount basic.target systemd-tmpfiles-setup.service systemd-journald.socket network.target httpd-init.service remote-fs.target tmp.mount",
"AllowIsolate": "no",
"AllowedCPUs": "",
"AllowedMemoryNodes": "",
//查看80端口是否开启
[root@control ansible]# ansible server1 -m shell -a "ss -antl"
192.168.56.130 | CHANGED | rc=0 >>
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 32 *:21 *:*
LISTEN 0 128 [::]:22 [::]:*
6、安装MYSQL
//安装MySQL
[root@control ansible]# ansible server2 -m yum -a "name=mariadb state=present"
192.168.56.131 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: perl-Carp-1.42-396.el8.noarch",
"Installed: perl-Data-Dumper-2.167-399.el8.x86_64",
"Installed: perl-Encode-4:2.97-3.el8.x86_64",
"Installed: perl-Errno-1.28-419.el8.x86_64",
"Installed: perl-Exporter-5.72-396.el8.noarch",
"Installed: perl-File-Path-2.15-2.el8.noarch",
"Installed: perl-File-Temp-0.230.600-1.el8.noarch",
"Installed: perl-Getopt-Long-1:2.50-4.el8.noarch",
......
......
[root@control ansible]# ansible server2 -m yum -a 'name=mariadb-server state=present'
192.168.56.131 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: psmisc-23.1-5.el8.x86_64",
"Installed: mariadb-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: mariadb-errmsg-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: perl-DBD-MySQL-4.046-3.module_el8.1.0+203+e45423dc.x86_64",
"Installed: mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64",
"Installed: mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: perl-Math-BigInt-1:1.9998.11-7.el8.noarch",
"Installed: perl-Math-Complex-1.59-419.el8.noarch",
"Installed: mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64"
]
}
//启动MySQL 设置开机自启
[root@control ansible]# ansible server2 -m service -a "name=mariadb enabled=yes"
192.168.56.131 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"enabled": true,
"name": "mariadb",
"status": {
"ActiveEnterTimestampMonotonic": "0",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "inactive",
"After": "network.target systemd-tmpfiles-setup.service systemd-journald.socket tmp.mount basic.target system.slice -.mount sysinit.target",
"AllowIsolate": "no",
//查看端口号3306
[root@control ansible]# ansible server2 -m shell -a'ss -antl'
192.168.56.131 | CHANGED | rc=0 >>
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 70 *:33060 *:*
LISTEN 0 128 *:3306 *:*
7、安装php
//安装php
[root@control ansible]# ansible server3 -m yum -a 'name=php state=present'
192.168.56.132 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: httpd-tools-2.4.37-39.module_el8.4.0+778+c970deab.x86_64",
"Installed: nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch",
"Installed: php-fpm-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
"Installed: php-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
"Installed: mailcap-2.1.48-3.el8.noarch",
"Installed: mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64",
"Installed: php-cli-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
"Installed: apr-1.6.3-11.el8.x86_64",
"Installed: php-common-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
"Installed: centos-logos-httpd-85.8-1.el8.noarch",
"Installed: apr-util-1.6.1-6.el8.x86_64",
"Installed: apr-util-bdb-1.6.1-6.el8.x86_64",
"Installed: httpd-2.4.37-39.module_el8.4.0+778+c970deab.x86_64",
"Installed: apr-util-openssl-1.6.1-6.el8.x86_64",
"Installed: httpd-filesystem-2.4.37-39.module_el8.4.0+778+c970deab.noarch"
]
}
[root@control ansible]# ansible server3 -m yum -a "name=php-* state=present"
192.168.56.132 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: gd-2.2.5-7.el8.x86_64",
"Installed: hunspell-1.6.2-1.el8.x86_64",
"Installed: unixODBC-2.3.7-1.el8.x86_64",
"Installed: binutils-2.30-93.el8.x86_64",
"Installed: cpp-8.4.1-1.el8.x86_64",
"Installed: hunspell-en-0.20140811.1-12.el8.noarch",
"Installed: hunspell-en-GB-0.20140811.1-12.el8.noarch",
"Installed: hunspell-en-US-0.20140811.1-12.el8.noarch",
......
......
[root@control ansible]# ansible server3 -m yum -a "name=curl state=present"
192.168.56.132 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"msg": "Nothing to do",
"rc": 0,
"results": []
}
[root@control ansible]# ansible server3 -m yum -a "name=curl-devel state=present"
192.168.56.132 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: openssl-1:1.1.1g-15.el8_3.x86_64",
"Installed: libcurl-7.61.1-18.el8.x86_64",
"Installed: libcurl-devel-7.61.1-18.el8.x86_64",
"Installed: openssl-libs-1:1.1.1g-15.el8_3.x86_64",
"Installed: libssh-0.9.4-2.el8.x86_64",
"Installed: libssh-config-0.9.4-2.el8.noarch",
"Removed: libcurl-7.61.1-12.el8.x86_64",
"Removed: libssh-0.9.0-4.el8.x86_64",
"Removed: libssh-config-0.9.0-4.el8.noarch",
"Removed: openssl-1:1.1.1c-15.el8.x86_64",
"Removed: openssl-libs-1:1.1.1c-15.el8.x86_64"
]
}
//建立php与mysql 的联系
[root@control ansible]# ansible server3 -m yum -a 'name=php-mysqlnd state=installed'
192.168.56.132 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"msg": "Nothing to do",
"rc": 0,
"results": []
}
8、编写php配置文件并传输到server1上
[root@centos8-1 ~]# ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf line="<VirtualHost 192.168.100.147:80>\nDocumentRoot "/var/www/html/www1"\nServerName www.node2.com\nProxyRequests off\nProxyPassMatch ^/(.*\.php)$ fcgi://192.168.100.149:9000/var/www/html/www1/$1\n<Directory "/var/www/html/www1">\nOptions None\nAllowOverride None\nOrder allow,deny\nAllow from all\n</Directory>\n</VirtualHost>"'
ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^AddType " insertafter="^AddType application/x-" line="AddType application/x-httpd-php .php"'
ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^AddType " insertafter="^AddType application/x-" line="AddType application/x-httpd-php-source .phps"'
ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^DirectoryIndex" line="DirectoryIndex index.html index.php"'
[root@control ansible]# ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf line="<VirtualHost 192.168.100.147:80>\nDocumentRoot "/var/www/html/www1"\nServerName www.node2.com\nProxyRequests off\nProxyPassMatch ^/(.*\.php)$ fcgi://192.168.100.149:9000/var/www/html/www1/$1\n<Directory "/var/www/html/www1">\nOptions None\nAllowOverride None\nOrder allow,deny\nAllow from all\n</Directory>\n</VirtualHost>"'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
[root@control ansible]# ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^AddType " insertafter="^AddType application/x-" line="AddType application/x-httpd-php .php"'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
[root@control ansible]# ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^AddType " insertafter="^AddType application/x-" line="AddType application/x-httpd-php-source .phps"'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line replaced"
}
[root@control ansible]# ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^DirectoryIndex" line="DirectoryIndex index.html index.php"'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
//编写配置文件
[root@control ansible]# vim info.php
[root@control ansible]# cat info.php
<?php
phpinfo();
?>
//把文件 info.php 传输server1上
[root@control ansible]# ansible server1 -m copy -a 'src=/etc/ansible/info.php dest=/var/www/html'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"checksum": "b45f1713a937379fc84371dad935a4fe288fa18b",
"dest": "/var/www/html/info.php",
"gid": 0,
"group": "root",
"md5sum": "b32a8588458413d37e22992b8752bb8f",
"mode": "0644",
"owner": "root",
"secontext": "system_u:object_r:httpd_sys_content_t:s0",
"size": 25,
"src": "/root/.ansible/tmp/ansible-tmp-1626704143.2048132-1523154-228742052150207/source",
"state": "file",
"uid": 0
}
//查看servers1上
[root@control ansible]# ansible server1 -m shell -a 'cat /var/www/html/info.php'
192.168.56.130 | CHANGED | rc=0 >>
<?php
phpinfo();
?>
9、配置apache和php
//在配置文件添加
[root@control ansible]# ansible server1 -m shell -a ' sed -i '/proxy_module/s/#//g' /etc/httpd/conf/httpd.conf'
[WARNING]: Consider using the replace, lineinfile or template module rather
than running 'sed'. If you need to use command because replace, lineinfile or
template is insufficient you can add 'warn: false' to this command task or set
'command_warnings=False' in ansible.cfg to get rid of this message.
192.168.56.130 | CHANGED | rc=0 >>
[root@control ansible]# ansible server1 -m shell -a 'sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd/conf/httpd.conf'
[WARNING]: Consider using the replace, lineinfile or template module rather
than running 'sed'. If you need to use command because replace, lineinfile or
template is insufficient you can add 'warn: false' to this command task or set
'command_warnings=False' in ansible.cfg to get rid of this message.
192.168.56.130 | CHANGED | rc=0 >>
[root@control ansible]# ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf line="<VirtualHost *:80>\DocumentRoot "/var/www/html/index.php" \ServerName www.192.168.200.147 \ ProxyRequests Off \ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/index.php/$1 \<Directory "/var/www/html/index.php"> \Options none \AllowOverride none \Require all granted \</Directory> \</VirtualHost>"'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
[root@control ansible]# ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^AddType " insertafter="^AddType application/x-" line="AddType application/x-httpd-php-source .phps"'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
[root@control ansible]# ansible server1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^DirectoryIndex" line="DirectoryIndex index.html index.php"'
192.168.56.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
//重启服务
[root@control ansible]# ansible server1 -m service -a 'name=httpd state=started'
192.168.56.130 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"name": "httpd",
"state": "started",
"status": {
"ActiveEnterTimestamp": "Mon 2021-07-19 21:50:30 CST",
"ActiveEnterTimestampMonotonic": "27244494883",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "active",
"After": "httpd-init.service tmp.mount systemd-journald.socket sysinit.target nss-lookup.target remote-fs.target network.target -.mount systemd-tmpfiles-setup.service system.slice basic.target",
"AllowIsolate": "no",
"AllowedCPUs": "",
......
......
10、配置php
[root@control ansible]# ansible server3 -m lineinfile -a 'path=/etc/php-fpm.d/www.conf regexp="^listen =" line="listen = 192.168.56.132:9000"'
192.168.56.132 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line replaced"
}
[root@control ansible]#
[root@control ansible]# ansible server3 -m lineinfile -a 'path=/etc/php-fpm.d/www.conf regexp="^listen.allowed_clients =" line="listen.allowed_clients = 192.168.56.132"'
192.168.56.132 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line replaced"
}
[root@control ansible]# ansible server1 -a 'mkdir /var/www/html/www1'
[WARNING]: Consider using the file module with state=directory rather than
running 'mkdir'. If you need to use command because file is insufficient you
can add 'warn: false' to this command task or set 'command_warnings=False' in
ansible.cfg to get rid of this message.
192.168.56.130 | CHANGED | rc=0 >>
[root@control ansible]# ansible server3 -m service -a 'name=php-fpm state=started'
192.168.56.132 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"name": "php-fpm",
"state": "started",
"status": {
"ActiveEnterTimestampMonotonic": "0",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "inactive",
"After": "tmp.mount -.mount syslog.target systemd-journald.socket network.target basic.target sysinit.target systemd-tmpfiles-setup.service system.slice",
"AllowIsolate": "no",
"AllowedCPUs": "",
"AllowedMemoryNodes": "",
"AmbientCapabilities": "",
"AssertResult": "no",
"AssertTimestampMonotonic": "0",
"Before": "shutdown.target",
"BlockIOAccounting": "no",
"BlockIOWeight": "[not set]",
"CPUAccounting": "no",
"CPUAffinity": "",
"CPUQuotaPerSecUSec": "infinity",
"CPUSchedulingPolicy": "0",
"CPUSchedulingPriority": "0",
11、查看结果
et systemd-journald.socket network.target basic.target sysinit.target systemd-tmpfiles-setup.service system.slice", “AllowIsolate”: “no”, “AllowedCPUs”: “”, “AllowedMemoryNodes”: “”, “AmbientCapabilities”: “”, “AssertResult”: “no”, “AssertTimestampMonotonic”: “0”, “Before”: “shutdown.target”, “BlockIOAccounting”: “no”, “BlockIOWeight”: “[not set]”, “CPUAccounting”: “no”, “CPUAffinity”: “”, “CPUQuotaPerSecUSec”: “infinity”, “CPUSchedulingPolicy”: “0”, “CPUSchedulingPriority”: “0”,
### 11、查看结果
|