lamp分离部署

lamp分离部署

环境准备:

主机名IP地址
ansible192.168.47.133
apache192.168.47.147
mysql192.168.47.152
php192.168.47.156

在ansible主机上添加受管主机清单

[root@my ansible]# cat inventory 
[apache]
192.168.47.147 ansible_user=root ansible_password=1
[mysql]
192.168.47.152 
[php]
192.168.47.156

创建免密登录

[root@my ansible]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:LriOxnC5gdZ5jjNtRVoo+6tgiv9GlOOnR6KX2sKOUVQ root@my
The key's randomart image is:
+---[RSA 3072]----+
|    E            |
|   .             |
|  .  ..          |
| . .+. o         |
| .o++.+ S        |
|oo++++oo         |
|oB =B*o .        |
|+oO*=*..         |
|++=OXo.          |
+----[SHA256]-----+
[root@my ansible]# ssh-copy-id root@192.168.47.147
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.47.147's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.47.147'"
and check to make sure that only the key(s) you wanted were added.

[root@my ansible]# ssh-copy-id root@192.168.47.152
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.47.152 (192.168.47.152)' can't be established.
ECDSA key fingerprint is SHA256:vM+6iTTQOdnifV0kzdrl75KMCtk1lpt8fsWbMz+QYk8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.47.152's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.47.152'"
and check to make sure that only the key(s) you wanted were added.

[root@my ansible]# ssh-copy-id root@192.168.47.156
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.47.156 (192.168.47.156)' can't be established.
ECDSA key fingerprint is SHA256:vM+6iTTQOdnifV0kzdrl75KMCtk1lpt8fsWbMz+QYk8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.47.156's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.47.156'"
and check to make sure that only the key(s) you wanted were added.

使用ping模块测试主机是否连通

[root@my ansible]# ansible all -m ping
192.168.47.147 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
192.168.47.152 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
192.168.47.156 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

使用shell模块和lineinfile模块关闭防火墙和selinux

[root@my ansible]# ansible all -m shell -a 'systemctl stop firewalld && systemctl disable firewalld'
192.168.47.147 | CHANGED | rc=0 >>

192.168.47.152 | CHANGED | rc=0 >>

192.168.47.156 | CHANGED | rc=0 >>
[root@my ansible]# ansible all -m lineinfile -a 'path=/etc/selinux/config regexp="^SELINUX=" line="SELINUX=disabled" '
192.168.47.147 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": false,
    "msg": ""
}
192.168.47.156 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line replaced"
}
192.168.47.152 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line replaced"
}

用yum模块为apache主机安装apache

[root@my ansible]# ansible apache -m yum -a "name=httpd state=present"
192.168.47.147 | 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",
        "Installed: httpd-tools-2.4.37-21.module+el8.2.0+5008+cca404a3.x86_64",
        "Installed: mod_http2-1.11.3-3.module+el8.2.0+4377+dc421495.x86_64",
        "Installed: apr-util-openssl-1.6.1-6.el8.x86_64",
        "Installed: apr-1.6.3-9.el8.x86_64"
    ]
}

用yum模块为mysql主机安装mariadb*服务

[root@my ansible]# ansible mysql -m dnf -a 'name=mariadb* state=present'
192.168.47.152 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: openssl-devel-1:1.1.1c-15.el8.x86_64",
        "Installed: libkadm5-1.17-18.el8.x86_64",
        "Installed: perl-DBD-MySQL-4.046-3.module+el8.1.0+2938+301254e2.x86_64",
        "Installed: libcom_err-devel-1.45.4-3.el8.x86_64",
        "Installed: perl-Env-1.04-395.el8.noarch",
        "Installed: unixODBC-2.3.7-1.el8.x86_64",
        "Installed: pcre2-devel-10.32-1.el8.x86_64",
        "Installed: pcre2-utf16-10.32-1.el8.x86_64",
        "Installed: pcre2-utf32-10.32-1.el8.x86_64",
        "Installed: copy-jdk-configs-3.7-1.el8.noarch",
        "Installed: perl-Test-Simple-1:1.302135-1.el8.noarch",
        "Installed: keyutils-libs-devel-1.5.10-6.el8.x86_64",
        "Installed: zlib-devel-1.2.11-13.el8.x86_64",
        "Installed: libverto-devel-0.3.0-5.el8.x86_64",
        "Installed: krb5-devel-1.17-18.el8.x86_64",
        "Installed: mariadb-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-backup-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: Judy-1.0.5-18.module+el8+2765+cfa4f87b.x86_64",
        "Installed: mariadb-common-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-connector-c-3.0.7-1.el8.x86_64",
        "Installed: perl-Time-HiRes-1.9758-1.el8.x86_64",
        "Installed: tzdata-java-2019c-1.el8.noarch",
        "Installed: java-1.8.0-openjdk-headless-1:1.8.0.242.b08-4.el8.x86_64",
        "Installed: mariadb-connector-c-devel-3.0.7-1.el8.x86_64",
        "Installed: galera-25.3.26-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-connector-odbc-3.0.7-1.el8.x86_64",
        "Installed: mariadb-devel-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-embedded-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-embedded-devel-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-errmsg-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-gssapi-server-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-java-client-2.2.5-2.el8.noarch",
        "Installed: mariadb-oqgraph-engine-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: lksctp-tools-1.0.18-3.el8.x86_64",
        "Installed: mariadb-server-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: libaio-devel-0.3.112-1.el8.x86_64",
        "Installed: javapackages-filesystem-5.3.0-1.module+el8+2447+6f56d9a6.noarch",
        "Installed: libselinux-devel-2.9-3.el8.x86_64",
        "Installed: mariadb-server-galera-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-server-utils-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: mariadb-test-3:10.3.17-1.module+el8.1.0+3974+90eded84.x86_64",
        "Installed: libsepol-devel-2.9-1.el8.x86_64",
        "Installed: perl-Memoize-1.03-416.el8.noarch"
    ]
}

在php主机上使用yum模块安装php*服务

[root@my ansible]# ansible php -m dnf -a 'name=php* state=present'
192.168.47.156 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: libtool-2.4.6-25.el8.x86_64",
        "Installed: autoconf-2.69-27.el8.noarch",
        "Installed: libzip-1.5.1-2.module+el8.1.0+3202+af5476b9.x86_64",
        "Installed: libpq-12.1-3.el8.x86_64",
        "Installed: m4-1.4.18-7.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",
        "Installed: httpd-tools-2.4.37-21.module+el8.2.0+5008+cca404a3.x86_64",
        "Installed: glibc-devel-2.28-101.el8.x86_64",
        "Installed: pcre-cpp-8.42-4.el8.x86_64",
        "Installed: pcre-devel-8.42-4.el8.x86_64",
        "Installed: pcre-utf16-8.42-4.el8.x86_64",
        "Installed: automake-1.16.1-6.el8.noarch",
        "Installed: pcre-utf32-8.42-4.el8.x86_64",
        "Installed: net-snmp-1:5.8-14.el8.x86_64",
        "Installed: php-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: net-snmp-agent-libs-1:5.8-14.el8.x86_64",
        "Installed: php-bcmath-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-cli-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-common-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-dba-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-dbg-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-devel-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-embedded-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-enchant-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: cpp-8.3.1-5.el8.x86_64",
        "Installed: php-fpm-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-gd-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: mod_http2-1.11.3-3.module+el8.2.0+4377+dc421495.x86_64",
        "Installed: nginx-filesystem-1:1.14.1-9.module+el8.0.0+4108+af250afe.noarch",
        "Installed: php-gmp-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-intl-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-json-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: enchant-1:1.6.0-21.el8.x86_64",
        "Installed: isl-0.16.1-6.el8.x86_64",
        "Installed: php-ldap-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-mbstring-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: kernel-headers-4.18.0-193.el8.x86_64",
        "Installed: php-mysqlnd-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-odbc-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: tokyocabinet-1.4.48-10.el8.x86_64",
        "Installed: php-opcache-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-pdo-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-pear-1:1.10.5-9.module+el8.1.0+3202+af5476b9.noarch",
        "Installed: php-pecl-apcu-5.1.12-2.module+el8.1.0+3202+af5476b9.x86_64",
        "Installed: php-pecl-apcu-devel-5.1.12-2.module+el8.1.0+3202+af5476b9.x86_64",
        "Installed: apr-1.6.3-9.el8.x86_64",
        "Installed: php-pecl-zip-1.15.3-1.module+el8.1.0+3186+20164e6f.x86_64",
        "Installed: apr-util-1.6.1-6.el8.x86_64",
        "Installed: php-pgsql-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: apr-util-bdb-1.6.1-6.el8.x86_64",
        "Installed: php-process-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: perl-Thread-Queue-3.13-1.el8.noarch",
        "Installed: php-recode-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: mariadb-connector-c-3.0.7-1.el8.x86_64",
        "Installed: libxcrypt-devel-4.1.1-4.el8.x86_64",
        "Installed: mariadb-connector-c-config-3.0.7-1.el8.noarch",
        "Installed: apr-util-openssl-1.6.1-6.el8.x86_64",
        "Installed: php-snmp-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-soap-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-xml-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: php-xmlrpc-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64",
        "Installed: recode-3.6-47.el8.x86_64",
        "Installed: gcc-8.3.1-5.el8.x86_64",
        "Installed: gcc-c++-8.3.1-5.el8.x86_64",
        "Installed: unixODBC-2.3.7-1.el8.x86_64",
        "Installed: libstdc++-devel-8.3.1-5.el8.x86_64",
        "Installed: lm_sensors-libs-3.4.0-21.20180522git70f7e08.el8.x86_64",
        "Installed: redhat-logos-httpd-81.1-1.el8.noarch",
        "Installed: glibc-headers-2.28-101.el8.x86_64"
    ]
}

使用script模块为所有受管主机添加host解析

[root@my ansible]# cat host.sh 
#!/bin/bash

echo 192.168.47.147 apache >> /etc/hosts
echo 192.168.47.152 mysql >> /etc/hosts
echo 192.168.47.156 php >> /etc/hosts
[root@my ansible]# chmod +x host.sh 
[root@my ansible]# ll host.sh 
-rwxr-xr-x. 1 root root 132 719 15:13 host.sh
[root@my ansible]# pwd
/etc/ansible
[root@my ansible]# ansible all -m script -a '/etc/ansible/host.sh'
192.168.47.147 | CHANGED => {
    "changed": true,
    "rc": 0,
    "stderr": "Shared connection to 192.168.47.147 closed.\r\n",
    "stderr_lines": [
        "Shared connection to 192.168.47.147 closed."
    ],
    "stdout": "",
    "stdout_lines": []
}
192.168.47.152 | CHANGED => {
    "changed": true,
    "rc": 0,
    "stderr": "Shared connection to 192.168.47.152 closed.\r\n",
    "stderr_lines": [
        "Shared connection to 192.168.47.152 closed."
    ],
    "stdout": "",
    "stdout_lines": []
}
192.168.47.156 | CHANGED => {
    "changed": true,
    "rc": 0,
    "stderr": "Shared connection to 192.168.47.156 closed.\r\n",
    "stderr_lines": [
        "Shared connection to 192.168.47.156 closed."
    ],
    "stdout": "",
    "stdout_lines": []
}

使用service模块为apche、mariadb、php服务设置开机自启

[root@my ansible]# ansible apache -m service -a 'name=httpd state=started enabled=yes'
192.168.47.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "enabled": true,
[root@my ansible]# ansible php -m service -a 'name=php-fpm state=started enabled=yes'
192.168.47.156 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "enabled": true,
    "name": "php-fpm",
    "state": "started",
    "status": {
[root@my ansible]# ansible mysql -m service -a 'name=mariadb state=started enabled=yes'
192.168.47.152 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "enabled": true,
    "name": "mariadb",
    "state": "started",
    "status": {
        "ActiveEnterTimestampMonotonic": "0",
        "ActiveExitTimestampMonotonic": "0",
        "ActiveState": "inactive",

使用shell、lineinfile、copy模块来修改apache的配置

[root@my ansible]# ansible apache -m shell -a 'sed -i "/DirectoryIndex/s/index.html/index.php index.html/g" /etc/httpd/conf/httpd.conf'
192.168.47.147 | CHANGED | rc=0 >>
[root@my ansible]# ansible apache -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="AddType application/x-gzip.gz.tgz" line="AddType application/x-httpd-php .php"'

192.168.47.147 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": false,
    "msg": ""
}
[root@my ansible]# ansible apache -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="AddType application/x-gzip .gz.tgz" line="AddType application/x-httpd-php-source.phps"'

192.168.47.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}
[root@my ansible]# ansible apache -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="# LoadModule foo_module modules/mod_foo.so" line="LoadModule proxy_module modules/mod_proxy.so"'

192.168.47.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}
[root@my ansible]# ansible apache -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="# LoadModule foo_module modules/mod_foo.so" line="LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so"'

192.168.47.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}

把虚拟站点文件传输到apache服务器上

[root@my ansible]# cat /root/httpd.conf 
<VirtualHost *:80>
    DocumentRoot "/var/www/html/"
    ServerName www.my.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.47.156:9000/www/html/$1
</VirtualHost>
[root@my ansible]# ansible apache -m copy -a 'src=/root/httpd.conf dest=/etc/httpd/conf.d/'
192.168.47.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "checksum": "25b1035a0550f093ce52e42ae6a4f462556b9d1d",
    "dest": "/etc/httpd/conf.d/httpd.conf",
    "gid": 0,
 [root@my ansible]# vim /etc/httpd/conf/httpd.conf 
# LoadModule foo_module modules/mod_foo.so
 58 LoadModule proxy_module modules/mod_proxy.so
 59 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
 60 Include conf.modules.d/*.conf
 

使用lineinfile模块来修改php的配置文件

[root@my ansible]# ansible php -m lineinfile -a 'path=/etc/php-fpm.d/www.conf regexp="listen = /usr" line="listen = 0.0.0.0:9000"'
192.168.47.156 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}
[root@my ansible]# ansible php -m lineinfile -a 'path=/etc/php-fpm.d/www.conf regexp="listen.allowed_clients = 127.0.0.1" line="listen.allowed_clients = 192.168.47.147"'

192.168.47.156 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line replaced"
}

把php测试文件index.php放到php服务器上

[root@my ~]# ansible php -m copy -a 'src=index.php dest=/www/html/'
192.168.47.156 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "checksum": "b3297c8ddc22e97b622dace5e84c4e990bac811b",
    "dest": "/www/html/index.php",

网站源码要放在php服务端的/var/www/html目录
httpd服务配置添加远程调用php服务

[root@node1 html]# vim /etc/httpd/conf/httpd.conf

292     # AddHandler allows you to map certain file extensions to "handlers":
293     # actions unrelated to filetype. These can be either built into the server
294     # or added with the Action directive (see below)
288     AddType application/x-compress .Z
289     AddType application/x-gzip .gz .tgz
290     AddType application/x-httpd-php-source .phps
291     AddType application/x-httpd-php .php
292     Proxyrequests Off
293     ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.47.156:9000/var/www/html/$1
294 

修改php服务监听方式

[root@node3 ~]# vim /etc/php-fpm.d/www.conf 

37 ; Note: This value is mandatory.
 38 listen = /run/php-fpm/www.sock
 39 listen = 9000
 40 

使用service模块重启服务

[root@my ~]# ansible apache -m service -a 'name=httpd state=restarted'
192.168.47.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "httpd",
    "state": "started",
    "status": {
[root@my ansible]# ansible php -m service -a 'name=php-fpm state=restarted'
192.168.47.156 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
[root@my ansible]# ansible mysql -m service -a 'name=mariadb state=restarted'

192.168.47.152 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "mariadb",
    "state": "started",
    "status": {

访问IP验证
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值