实验环境
ip | 服务 | 备注 |
---|---|---|
192.168.1.11 | Docker swarm service(nginx+php) | swarm-manager |
192.168.1.12 | Docker swarm service(nginx+php) | node1 |
192.168.1.13 | Docker swarm service(nginx+php) | node2 |
192.168.1.14 | mysql+haproxy | mysql-haproxy |
需要单独在主控端,写一个nginx启动脚本和php测试页面,用来传文件,nginx用copy,php用模板,用copy也行
[root@localhost ~]# vim nginx.yml
- hosts: dbserver
remote_user: root
tasks:
- name: install nginx
unarchive: src=/root/nginx-1.11.1.tar.gz dest=/usr/src
- name: yum install pcre* openssl*
yum: name=pcre-devel,openssl-devel,gcc,gcc-c++,zlib-devel
- name: make install nginx
# 以下表示进行shell操作时,先进入/usr/src/nginx-1.11.1目录
shell: ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-pcre && make && make install
args:
chdir: /usr/src/nginx-1.11.1
- name: lnfile
file: src=/usr/local/nginx/sbin/nginx dest=/usr/local/sbin/nginx state=link
- name: create nginx user
user: name=nginx create_home=no shell=/sbin/nologin state=present
- name: nginx start script
copy: src=/root/nginx dest=/etc/init.d/nginx
- name: xp
file: path=/etc/init.d/nginx mode=0755
- name: add system service
shell: chkconfig --add nginx
- name: open system auto started
shell: systemctl enable nginx
- name: start nginx
service: name=nginx state=started
[root@localhost ~]# ansible-playbook nginx.yml
LNMP是Linux+Nginx+Mysql+PHP的组合方式
使用LNMP的主要原因还是因为Nginx体积小,方便后期对于网络的环境变换(灵活)、切换和方便调试,比较符合轻量级, 相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,也可作为负载均衡及反向代理服务器,做到动静分离
Only one也就是LNMP全部都安装在一台Linux服务器