//在opt下创建一个inventory的主机清单
[root@localhost opt]# vim inventory[httpd]
192.168.200.147
[mysql]
192.168.200.145
[php]
192.168.200.146
//使absible主机能ping通这三台被控主机
//生成密钥
[root@localhost opt]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter fileinwhich 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:KjMrbnZ0/ldh0KsKmPrMMXeNMODdbqiq12bSgMqcI04 root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| . |
| . . |
| . . . |
| . o . + |
| . .o+ S o . |
|. . + o* o. . |
|+E.**o+.=... |
|+=Bo*X.o. . |
|+B+O* ... |
+----[SHA256]-----+
//传递密钥
[root@localhost opt]# ssh-copy-id root@192.168.200.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.200.147's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.200.147'"
and check to make sure that only the key(s) you wanted were added.
.......
//使用平模块看是否能ping通
[root@localhost opt]# ansible all -m ping
192.168.200.145 | SUCCESS =>{"ansible_facts":{"discovered_interpreter_python":"/usr/libexec/platform-python"},
"changed": false,
"ping":"pong"}
192.168.200.146 | SUCCESS =>{"ansible_facts":{"discovered_interpreter_python":"/usr/libexec/platform-python"},
"changed": false,
"ping":"pong"}
192.168.200.147 | SUCCESS =>{"ansible_facts":{"discovered_interpreter_python":"/usr/libexec/platform-python"},
"changed": false,
"ping":"pong"}
//三台主机全部ping通
3.在ansible这台主机上搭建lamp架构
//拉取一个网络仓库
[root@localhost opt]# wget -o CentOS8-Base-163.repo http://mirrors.163.com/.help/CentOS8-Base-163.repo
//安装httpd
[root@localhost opt]# yum -y install httpd
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:9:45:23 前,执行于 2021年07月19日 星期一 00时07分08秒。
依赖关系解决。
========================================================
软件包 架构 版本 仓库 大小
========================================================
安装:
httpd x86_64 2.4.37-39.module_el8.4.0+778+c970deab
.........
[root@localhost opt]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
//编写httpd的服务文件
[root@www conf]# vim httpd.conf<VirtualHost *:9000>
DocumentRoot "/var/www/html/"
ServerName www.192.168.200.147.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.200.146:9000/var/www/html/$1<Directory "/var/www/html/">
Options none
AllowOverride none
Require all granted
</Directory></VirtualHost>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .phtml .php3
SetHandler application/x-httpd-php
DirectoryIndex index.html index.php
//安装mysql
[root@localhost opt]# yum -y install mariadb mariadb-server
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:9:46:13 前,执行于 2021年07月19日 星期一 00时07分08秒。
依赖关系解决。
========================================================
软件包 架构 版本 仓库 大小
========================================================
安装:
mariadb x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d
AppStream 6.0 M
........[root@localhost opt]# chown -R mysql:mysql /var/lib/mysql/[root@localhost opt]# systemctl start mariadb
//安装php
[root@localhost opt]# yum -y install php php-mysqlnd
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:9:48:45 前,执行于 2021年07月19日 星期一 00时07分08秒。
依赖关系解决。
========================================================
软件包 架构 版本 仓库 大小
========================================================
安装:
php x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66
AppStream 1.5 M
php-mysqlnd x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66
//编写配置文件
[root@localhost opt]# echo "<?php phpinfo();?>" > /var/www/html/index.php[root@localhost fpm-d]# vim www.conf
listen = 192.168.58.40:9000
listen.allowed_clients = 192.168.58.40
//访问ansibel主机发现lamp架构已经搭建完成