LAMP分离部署
环境准备
系统 | IP | 名称 | 安装的服务 |
---|---|---|---|
RedHat 8 | 192.168.159.5 | master | 主机 |
RedHat 8 | 192.168.159.3 | node1 | httpd |
RedHat 8 | 192.168.159.6 | node2 | mysql |
RedHat 8 | 192.168.159.7 | node3 | php |
安装过程
//添加受管主机
[root@master ansible]# vim inventory
[root@master ansible]# cat inventory
[httpd]
192.168.159.3
[mysql]
192.168.159.6
[php]
192.168.159.7
//检测是否连通
[root@master ansible]# ansible all -m ping
192.168.159.6 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
192.168.159.7 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
192.168.159.3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
//添加免密登录
[root@master ansible]# ssh-copy-id root@192.168.159.3
/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.159.3's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.159.3'"
and check to make sure that only the key(s) you wanted were added.
[root@master ansible]# ssh-copy-id root@192.168.159.6
/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.159.6's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.159.6'"
and check to make sure that only the key(s) you wanted were added.
[root@master ansible]# ssh-copy-id root@192.168.159.7
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.159.7 (192.168.159.7)' can't be established.
ECDSA key fingerprint is SHA256:RbgGlOEmXjS4Pr0v5S+XiuM2tcIEQjWI5t6QBN+/aCE.
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.159.7's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.159.7'"
and check to make sure that only the key(s) you wanted were added.
//关闭防火墙
[root@master ansible]# ansible all -m shell -a 'systemctl stop firewalld && systemctl disable firewalld '
192.168.159.3 | CHANGED | rc=0 >>
192.168.159.6 | CHANGED | rc=0 >>
192.168.159.7 | CHANGED | rc=0 >>
//关闭SELINUX
[root@master ansible]# ansible all -m lineinfile -a 'path=/etc/selinux/config regexp="^SELINUX=" line="SELINUX=disabled"'
192.168.159.7 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": false,
"msg": ""
}
192.168.159.6 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": false,
"msg": ""
}
192.168.159.3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": false,
"msg": ""
}
//在node1上安装HTTPD服务
[root@master ansible]# ansible httpd -m yum -a "name=httpd"
192.168.159.3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"msg": "Nothing to do",
"rc": 0,
"results": []
}
//在node2上安装MySQL服务
[root@master ansible]# ansible mysql -m yum -a 'name=mariadb*'
192.168.159.6 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: libcom_err-1.45.6-1.el8.x86_64",
"Installed: libcom_err-devel-1.45.6-1.el8.x86_64",
"Installed: perl-Memoize-1.03-419.el8.noarch",
"Installed: openssl-1:1.1.1g-15.el8_3.x86_64",
"Installed: openssl-devel-1:1.1.1g-15.el8_3.x86_64",
"Installed: perl-Test-Simple-1:1.302135-1.el8.noarch",
"Installed: openssl-libs-1:1.1.1g-15.el8_3.x86_64",
"Installed: mariadb-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: mariadb-common-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: mariadb-connector-c-3.1.11-2.el8_3.x86_64",
"Installed: mariadb-connector-c-config-3.1.11-2.el8_3.noarch",
"Installed: perl-Time-HiRes-4:1.9758-2.el8.x86_64",
"Installed: mariadb-connector-c-devel-3.1.11-2.el8_3.x86_64",
"Installed: mariadb-connector-odbc-3.0.7-1.el8.x86_64",
"Installed: mariadb-devel-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: zlib-1.2.11-17.el8.x86_64",
"Installed: mariadb-embedded-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: zlib-devel-1.2.11-17.el8.x86_64",
"Installed: mariadb-embedded-devel-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: keyutils-libs-devel-1.5.10-6.el8.x86_64",
"Installed: mariadb-java-client-2.2.5-3.el8.noarch",
"Installed: pcre2-devel-10.32-2.el8.x86_64",
"Installed: mariadb-oqgraph-engine-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: pcre2-utf16-10.32-2.el8.x86_64",
"Installed: pcre2-10.32-2.el8.x86_64",
"Installed: pcre2-utf32-10.32-2.el8.x86_64",
"Installed: mariadb-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: krb5-devel-1.18.2-8.el8.x86_64",
"Installed: mariadb-server-galera-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: krb5-libs-1.18.2-8.el8.x86_64",
"Installed: mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: mariadb-test-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: libverto-devel-0.3.0-5.el8.x86_64",
"Installed: python3-libselinux-2.9-5.el8.x86_64",
"Installed: e2fsprogs-1.45.6-1.el8.x86_64",
"Installed: e2fsprogs-libs-1.45.6-1.el8.x86_64",
"Installed: java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.x86_64",
"Installed: libaio-devel-0.3.112-1.el8.x86_64",
"Installed: libselinux-2.9-5.el8.x86_64",
"Installed: libselinux-devel-2.9-5.el8.x86_64",
"Installed: libselinux-utils-2.9-5.el8.x86_64",
"Installed: libsepol-2.9-2.el8.x86_64",
"Installed: Judy-1.0.5-18.module_el8.3.0+757+d382997d.x86_64",
"Installed: libsepol-devel-2.9-2.el8.x86_64",
"Installed: galera-25.3.32-1.module_el8.3.0+757+d382997d.x86_64",
"Installed: tzdata-java-2021a-1.el8.noarch",
"Installed: lksctp-tools-1.0.18-3.el8.x86_64",
"Installed: libkadm5-1.18.2-8.el8.x86_64",
"Installed: perl-Env-1.04-395.el8.noarch",
"Installed: javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch",
"Installed: libss-1.45.6-1.el8.x86_64",
"Installed: copy-jdk-configs-3.7-4.el8.noarch",
"Installed: unixODBC-2.3.7-1.el8.x86_64",
"Removed: libselinux-utils-2.9-3.el8.x86_64",
"Removed: e2fsprogs-1.45.4-3.el8.x86_64",
"Removed: e2fsprogs-libs-1.45.4-3.el8.x86_64",
"Removed: libsepol-2.9-1.el8.x86_64",
"Removed: openssl-1:1.1.1c-15.el8.x86_64",
"Removed: krb5-libs-1.17-18.el8.x86_64",
"Removed: openssl-libs-1:1.1.1c-15.el8.x86_64",
"Removed: zlib-1.2.11-13.el8.x86_64",
"Removed: libcom_err-1.45.4-3.el8.x86_64",
"Removed: libss-1.45.4-3.el8.x86_64",
"Removed: python3-libselinux-2.9-3.el8.x86_64",
"Removed: pcre2-10.32-1.el8.x86_64",
"Removed: libselinux-2.9-3.el8.x86_64"
]
}
//在node3上安装php服务
[root@master ansible]# ansible php -m yum -a "name=php*"
192.168.159.7 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"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: glibc-devel-2.28-101.el8.x86_64",
"Installed: redhat-logos-httpd-81.1-1.el8.noarch",
"Installed: glibc-headers-2.28-101.el8.x86_64",
"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: 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"
]
}
//创建脚本文件
[root@master ansible]# touch zc.sh
[root@master ansible]# vim zc.sh
[root@master ansible]# cat zc.sh
#! /bin/bash
echo 102.168.159.3 apache >> /etc/hosts
echo 192.168.159.6 mysql >> /etc/hosts
echo 192.168.159.7 php >> /etc/hosts
//解析
[root@master ansible]# ansible all -m script -a '/etc/ansible/zc.sh'
192.168.159.3 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.159.3 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.159.3 closed."
],
"stdout": "",
"stdout_lines": []
}
192.168.159.6 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.159.6 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.159.6 closed."
],
"stdout": "",
"stdout_lines": []
}
192.168.159.7 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.159.7 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.159.7 closed."
],
"stdout": "",
"stdout_lines": []
}
//启动httpd、mysql、php服务,并设置开机自启
[root@master ansible]# ansible httpd -m service -a "name=httpd state=started enabled=yes"
192.168.159.3 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"enabled": true,
"name": "httpd",
"state": "started",
"status": {
"ActiveEnterTimestampMonotonic": "0",
"ActiveExitTimestampMonotonic": "0",
----------省略----------
[root@master ansible]# ansible mysql -m service -a "name=mariadb state=started enabled=yes"
192.168.159.6 | 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",
"After": "basic.target sysinit.target tmp.mount systemd-journald.socket -.mount network.target system.slice systemd-tmpfiles-setup.service",
"AllowIsolate": "no",
"AllowedCPUs": "",
"AllowedMemoryNodes": "",
"AmbientCapabilities": "",
"AssertResult": "no",
"AssertTimestampMonotonic": "0",
"Before": "shutdown.target",
----------省略----------
[root@master ansible]# ansible php -m service -a "name=php-fpm state=started enabled=yes"
192.168.159.7 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"enabled": true,
"name": "php-fpm",
"state": "started",
"status": {
"ActiveEnterTimestampMonotonic": "0",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "inactive",
"After": "systemd-journald.socket system.slice -.mount sysinit.target tmp.mount systemd-tmpfiles-setup.service syslog.target basic.target network.target",
"AllowIsolate": "no",
"AllowedCPUs": "",
"AllowedMemoryNodes": "",
"AmbientCapabilities": "",
----------省略----------
//使用shell、lineinfile、copy模块来修改httpd的配置
[root@master ansible]# ansible httpd -m shell -a 'sed -i "/DirectoryIndex/s/index.html/index.php index.html/g" /etc/httpd/conf/httpd.conf'
192.168.159.3 | CHANGED | rc=0 >>
[root@master ansible]# ansible httpd -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.159.3 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
[root@master ansible]# ansible httpd -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.159.3 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
[root@master ansible]# ansible httpd -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.159.3 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
[root@master ansible]# ansible httpd -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.159.3 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
//把虚拟站点文件传输到apache服务器上
[root@master ansible]# vim /root/httpd.conf
[root@master ansible]# cat /root/httpd.conf
<VirtualHost *:80>
DocumentRoot "/var/www/html/"
ServerName www.dzc.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.159.7:8800/www/html/$1
</VirtualHost>
[root@master ansible]# ansible httpd -m copy -a 'src=/root/httpd.conf dest=/etc/httpd/conf.d/'
192.168.159.3 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"checksum": "5a597093d4bf92c2e665617ed27ec562b8579897",
"dest": "/etc/httpd/conf.d/httpd.conf",
"gid": 0,
"group": "root",
"md5sum": "2b88cc4227f1ba7496547e6c54904b97",
"mode": "0644",
"owner": "root",
"secontext": "system_u:object_r:httpd_config_t:s0",
"size": 175,
"src": "/root/.ansible/tmp/ansible-tmp-1626690927.0724106-630092-271105761600897/source",
"state": "file",
"uid": 0
}
[root@node3 ~]# vim /etc/httpd/conf/httpd.conf
[root@node3 ~]# cat /etc/httpd/conf/httpd.conf
58 LoadModule proxy_module modules/mod_proxy.so
59 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
60
61 #
62 Include conf.modules.d/*.conf
63
//使用lineinfile模块来修改php的配置文件
[root@master ansible]# ansible php -m lineinfile -a 'path=/etc/php-fpm.d/www.conf regexp="listen = /usr" line="listen = 0.0.0.0:8800"'
192.168.159.7 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": true,
"msg": "line added"
}
[root@master 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.159.7"'
192.168.159.7 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"backup": "",
"changed": false,
"msg": ""
}
//把php测试文件index.php放到php服务器上
[root@master ansible]# ansible php -m copy -a 'src=/root/php/index.php dest=/www/html/'
192.168.159.7 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"checksum": "b3297c8ddc22e97b622dace5e84c4e990bac811b",
"dest": "/www/html/index.php",
"gid": 0,
"group": "root",
"md5sum": "24f1084a4efde84a9884c917c92e80da",
"mode": "0644",
"owner": "root",
"size": 682,
"src": "/root/.ansible/tmp/ansible-tmp-1626691822.549803-664956-261321929722785/source",
"state": "file",
"uid": 0
}
//网站源码要放在php服务端的/var/www/html目录
//httpd服务配置添加远程调用php服务
[root@node1 html]# vim /etc/httpd/conf/httpd.conf
286 # probably should define those extensions to indicate media types:
287 #
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.159.7:8800/var/www/html/$1
//修改php服务监听方式
[root@node3 ~]# vim /etc/php-fpm.d/www.conf
34 ; 'port' - to listen on a TCP socket to all addresses
35 ; (IPv6 and IPv4-mapped) on a specific port;
36 ; '/path/to/unix/socket' - to listen on a unix socket.
37 ; Note: This value is mandatory.
38 listen = /run/php-fpm/www.sock
39 listen = 8800
//使用service模块重启服务
[root@master ansible]# ansible httpd -m service -a 'name=httpd state=restarted'
192.168.159.3 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"name": "httpd",
"state": "started",
"status": {
"ActiveEnterTimestamp": "Mon 2021-07-19 18:24:04 CST",
"ActiveEnterTimestampMonotonic": "15072609966",
"ActiveExitTimestamp": "Mon 2021-07-19 18:58:20 CST",
"ActiveExitTimestampMonotonic": "17128610899",
"ActiveState": "failed",
"After": "network.target systemd-tmpfiles-setup.service basic.target system.slice systemd-journald.socket tmp.mount nss-lookup.target httpd-init.service remote-fs.target sysinit.target -.mount",
"AllowIsolate": "no",
----------省略----------
[root@master ansible]# ansible php -m service -a 'name=php-fpm state=restarted'
192.168.159.7 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"name": "php-fpm",
"state": "started",
"status": {
"ActiveEnterTimestamp": "Tue 2021-07-20 02:26:26 CST",
"ActiveEnterTimestampMonotonic": "1428810622",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "active",
"After": "syslog.target -.mount tmp.mount systemd-journald.socket basic.target system.slice systemd-tmpfiles-setup.service sysinit.target network.target",
"AllowIsolate": "no",
"AllowedCPUs": "",
"AllowedMemoryNodes": "",
----------省略----------
[root@master ansible]# ansible mysql -m service -a 'name=mariadb state=restarted'
192.168.159.6 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"name": "mariadb",
"state": "started",
"status": {
"ActiveEnterTimestamp": "Tue 2021-07-20 02:25:09 CST",
"ActiveEnterTimestampMonotonic": "12549188421",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "active",
"After": "network.target systemd-tmpfiles-setup.service basic.target -.mount systemd-journald.socket sysinit.target tmp.mount system.slice",
"AllowIsolate": "no",
"AllowedCPUs": "",
"AllowedMemoryNodes": "",
----------省略----------
部署结果
至此,全部配置皆已完成,接下来访问网站试试:
配置文件的问题,不代表服务不可以用
评论区