使用ad-hoc模式搭建lamp示例

使用ad-hoc模式搭建lamp示例

1.准备文件

1)准备httpd配置文件

[root@m01 ~]# yum install -y httpd
[root@m01 ~]# vim /etc/httpd/conf/httpd.conf
User www
Group www

2)准备php安装包

[root@m01 ~]# ll
-rw-r--r--  1 root root 19889622 Nov 22 15:52 php.tar.gz

3)准备PHP配置文件

[root@m01 ~]# tar xf php.tar.gz -C /tmp/
[root@m01 tmp]# yum localinstall -y *.rpm
[root@m01 tmp]# vim /etc/php-fpm.d/www.conf
user = www
group = www
[root@m01 tmp]# vim /etc/php.ini
upload_max_filesize = 200M
post_max_size = 200M

4)准备代码文件

[root@m01 ~]# ll kaoshi.zip 
-rw-r--r-- 1 root root 26995 Nov 22 16:47 kaoshi.zip

2.编写ansible命令

#1.安装httpd
ansible web_group -m yum -a 'name=httpd state=present' &&\
#2.创建www用户组
ansible web_group,nfs -m group -a 'name=www gid=666 state=present' &&\
#3.创建www用户
ansible web_group,nfs -m user -a 'name=www uid=666 group=www shell=/sbin/nologin create_home=false' &&\
#4.配置httpd
ansible web_group -m copy -a 'src=/etc/httpd/conf/httpd.conf dest=/etc/httpd/conf/' &&\
#5.解压php安装包到web服务器
ansible web_group -m unarchive -a 'src=/root/php.tar.gz dest=/tmp/' &&\
#6.安装php
ansible web_group -m shell -a 'yum localinstall -y /tmp/*.rpm' &&\
#7.配置php
ansible web_group -m copy -a 'src=/etc/php-fpm.d/www.conf dest=/etc/php-fpm.d/' &&\
ansible web_group -m copy -a 'src=/etc/php.ini dest=/etc/' &&\
#8.启动php
ansible web_group -m systemd -a 'name=php-fpm state=started enabled=yes' &&\
#9.启动httpd
ansible web_group -m systemd -a 'name=httpd state=started enabled=yes' &&\
#10.解压代码
ansible web_group -m unarchive -a 'src=/root/kaoshi.zip dest=/var/www/html/ owner=www group=www' &&\
#11.站点目录授权
ansible web_group -m file -a 'path=/var/www/ state=directory owner=www group=www recurse=yes' &&\
#12.安装NFS
ansible nfs -m yum -a 'name=nfs-utils state=present' &&\
#13.安装rpcbind
ansible web_group,nfs -m yum -a 'name=rpcbind state=present' &&\
#14.配置nfs
ansible nfs -m copy -a 'content="/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)" dest=/etc/exports' &&\
#15.创建挂载目录
ansible nfs -m file -a 'path=/data state=directory owner=www group=www' &&\
#16.启动nfs
ansible nfs -m systemd -a 'name=nfs state=started' &&\
#17.启动rpcbind
ansible nfs -m systemd -a 'name=rpcbind state=started' &&\
#18.创建web端挂载的目录
ansible web_group -m file -a 'path=/var/www/html/upload state=directory owner=www group=www' &&\
#19.挂载
ansible web_group -m mount -a 'src=172.16.1.31:/data path=/var/www/html/upload fstype=nfs opts=defaults state=mounted'
上一篇
下一篇
Copyright © 2022 Egon的技术星球 egonlin.com 版权所有 帮助IT小伙伴学到真正的技术