Ansible 一键配置安装Keepalived+Nginx作为前端,httpd+php作为后端

一、环境:

 Ansible控制机:172.16.0.6        
        Ansible nginx:172.16.0.{2|4}
        Ansible Keepalived: 172.16.0.{2|4}
        Ansible httpd: 172.16.0.{128|129}
        Keepalived IP:192.168.220.5/32
除控制机全部采用Linux Cento7,外网统一192.168.220.0/27
一般生产机我们会把Yum仓库指向自己搭建的,这里我们使用ail以及163的Yum仓库
  • {2|4}使用ail仓库源
[email protected] nginx]# cat /etc/yum.repos.d/ail.repo 
	[centos7]
	name=centeros7 base
	baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
	gpgcheck=0
	[epel]
	name=epel base
	baseurl=http://mirrors.aliyun.com/epel/7/x86_64
	gpgcheck=0
[[email protected] yum.repos.d]# cat /etc/yum.repos.d/CentOS7-Base-163.repo 
	# CentOS-Base.repo
	...
	[base]
	name=CentOS-$releasever - Base - 163.com
	#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
	baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
	gpgcheck=1
	gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

	...
二、Ansible控制机目录结构:
[[email protected] ansible]# tree .
        .          
        ├── ansible.cfg					#Ansible配置文件
	├── hosts					#Ansible主机清单
	├── roles					#Ansible 角色目录
	│   ├── httpd					#httpd角色
	│   │   ├── default				#定义默认配置yml
	│   │   ├── files				#copy模块用到的目录
	│   │   │   ├── index.html
	│   │   │   └── index.php
	│   │   ├── handlers			        #nodify触发用到的目录
	│   │   │   └── main.yml
	│   │   ├── meta
	│   │   ├── tasks				#任务用到的目录
	│   │   │   ├── install_httpd.yml
	│   │   │   ├── main.yml
	│   │   │   └── remove_httpd.yml
	│   │   ├── templates			        #模块用到的目录
	│   │   │   └── httpd.conf.j2
	│   │   └── vars				#表里用到的目录
	│   │       └── main.yml
	│   ├── keepalived
	│   │   ├── default
	│   │   ├── files
	│   │   ├── handlers
	│   │   │   └── main.yml
	│   │   ├── meta
	│   │   ├── tasks
	│   │   │   ├── install_keepalived.yml
	│   │   │   ├── main.yml
	│   │   │   └── remove_keepalived.yml
	│   │   ├── templates
	│   │   │   ├── keepalived.conf.j2
	│   │   │   └── keepalived.conf.j2.bak
	│   │   └── vars
	│   ├── memcached
	│   │   ├── default
	│   │   ├── files
	│   │   │   └── memcached.j2
	│   │   ├── handlers
	│   │   ├── meta
	│   │   ├── tasks
	│   │   │   ├── install_memcached.yml
	│   │   │   ├── main.yml
	│   │   │   └── remove_memcached.yml
	│   │   ├── templates
	│   │   │   ├── main.yml
	│   │   │   └── memcached.j2
	│   │   └── vars
	│   │       └── main.yml
	│   └── nginx
	│       ├── default
	│       ├── files
	│       │   └── index.html
	│       ├── handlers
	│       │   └── main.yml
	│       ├── meta
	│       ├── tasks
	│       │   ├── install_nginx.yml
	│       │   ├── main.yml
	│       │   └── remove_nginx.yml
	│       ├── templates
	│       │   └── nginx.conf.j2
	│       └── vars
	│           └── main.yml
	├── service.retry
	└── service.yml					#定义主机以及远程用户
三、问件分析:
  • ansible.cfg:这里使用的是默认
  • hosts:
[[email protected] ansible]# cat hosts[nginx]
#定义nginx主机清单列表,下面mb,prioroty为变量
	172.16.0.2   mb=MASTER prioroty=100  
	172.16.0.4   mb=BACKUP prioroty=98

	[httpd]		#定义httpd主机清单,hname为变量
	172.16.0.128 hname=httpd128	172.16.0.129 hname=httpd129

	[dbserver]	#定义dbserver主机清单,这里我没有去安装
	172.16.0.5 hname=dbserver
  • server.yml:
[[email protected] ansible]# cat service.yml 
	- hosts: all 			#定义hosts范围	  
	remote_user: root		#定义远程用户
	  roles:			#使用roles
	  - nginx			#nginx列表,就是roles目录下的nginx目录	  
	  - httpd			#httpd列表,就是roles目录下的httpd目录	  
	  - keepalived			#keepalived列表,就是roles目录下的keepalived目录
[[email protected] ansible]# cat service.retry 	#执行后自动生成,无需理会
	172.16.0.2
	172.16.0.4
  • roles:
[[email protected] ansible]# ls roles/			#每一个文件目录名称为一个角色
	httpd  keepalived  memcached  nginx
  • nginx
    每个角色结构如下,上面解释过就不介绍,下面介绍配置文件
[[email protected] ansible]# tree roles/nginx/
	roles/nginx/
	├── default
	├── files
	│   └── index.html
	├── handlers
	│   └── main.yml
	├── meta
	├── tasks
	│   ├── install_nginx.yml
	│   ├── main.yml
	│   └── remove_nginx.yml
	├── templates
	│   └── nginx.conf.j2
	└── vars
		└── main.yml7 directories, 7 files
  1. files/index.html:存放copy所用到的文件
  2. handlers/main.yml:
[[email protected] ansible]# cat roles/nginx/handlers/main.yml 
		- name: restart nginx				#与nodify:定义的名字保持一致
		  service: name=nginx state=restarted		#定义使用service Module采取的动作为重启,对应的程序为nginx
  1. tasks/install_nginx.yml:
[[email protected] ansible]# cat roles/nginx/tasks/install_nginx.yml 
		- name: install nginx
		   #定义一个输出名称为install nginx 
		  yum: name=nginx state=present
		   #使用yum Module 安装nginx
		- name: install nginx index.html
		  copy: src=index.html dest=/usr/share/nginx/html/index.html   
		   #使用copy Module 复制files/index.html文件到远程服务器
		  notify: restart nginx
		   #使用notify Module 定义一个引用
		  tags: modify nginx config copy
		   #定义一个tags,使用ansible-playbook可以使用-t "XXXX"指定执行的区域命令
		- name: install config		  template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
		   #使用template Module 引用template/nginx.conf.j2模块
		  notify: restart nginx
		   #定义notify
		  tags: modify nginx config
		   #定义tags
		- name: start nginx
		  service: name=nginx state=started enabled=true
		   #定义使用service Module采取的动作为重启,对应的程序为nginx 并开机自动启动
  1. tasks/remove_nginx.yml:
[[email protected] ansible]# cat roles/nginx/tasks/remove_nginx.yml 
		- name: remove nginx
		  yum: name=nginx state=absent
		   #使用yum Module采取的动作为删除,对应程序为nginx
  1. tasks/main.yml:
[[email protected] ansible]# cat roles/nginx/tasks/main.yml 
		- include: tasks/install_nginx.yml
		   #使用include包含我们之前定义的.yml文件
		  tags: install 
		   #定义tags
		  when:  ansible_eth1.ipv4.address == ‘172.16.0.4‘ or ansible_eth1.ipv4.address == ‘172.16.0.2‘
		   #定义只有等于{2|4}才执行
		- include: tasks/remove_nginx.yml
		   #使用include包含我们之前定义的.yml文件
		  tags: remove 
		   #定义tags
		  when:  ansible_eth1.ipv4.address == ‘172.16.0.4‘ or ansible_eth1.ipv4.address == ‘172.16.0.2‘
		   #定义只有等于{2|4}才执行
  1. template/nginx.conf.j2:
[[email protected] ansible]# cat roles/nginx/templates/nginx.conf.j2 
		...

		user {{ runuser }}; 
		 #我们在vars/main.yml定义的变量
		worker_processes {{ ansible_processor_vcpus-1 }};
		 #setup获取的fastc变量

		...

			server {
				listen        {{ nginx_prot }} default_server;
				 #我们在vars/main.yml定义的变量
    	...

7.vars/main.yml:

[[email protected] ansible]# cat roles/nginx/vars/main.yml 
	runuser: daemon			#定义变量
	nginx_prot: 80			#定义变量
  • httpd

    每个角色结构如下,上面解释过就不介绍,下面介绍配置文件

[[email protected] ansible]# tree roles/httpd/	#httpd角色目录结构
	roles/httpd/
	├── default
	├── files
	│   ├── index.html
	│   └── index.php
	├── handlers
	│   └── main.yml
	├── meta
	├── tasks
	│   ├── install_httpd.yml
	│   ├── main.yml
	│   └── remove_httpd.yml
	├── templates
	│   └── httpd.conf.j2
	└── vars
		└── main.yml7 directories, 8 files
[[email protected] ansible]# cat roles/httpd/files/index.html 
	<h1>Test file.</h1>

[[email protected] ansible]# cat roles/httpd/files/index.php 
	<?php
		phpinfo();
	?>
[[email protected] ansible]# cat roles/httpd/handlers/main.yml 
	- name: restart httpd
	  service: name=httpd state=restarted
[[email protected] ansible]# cat roles/httpd/tasks/install_httpd.yml 
	- name: install httpd
	  yum: name=httpd state=present
	- name: install php
	  yum: name=php state=present
	- name: install httpd  index.html 
	  copy: src=index.html dest=/var/www/html/index.html 
	  notify: restart httpd
	  tags: modify httpd  config copy
	- name: install httpd  index.php
	  copy: src=index.php dest=/var/www/html/index.php 
	  notify: restart httpd
	  tags: modify httpd  config copy
	- name: install config	  template: src=httpd.conf.j2 dest=/etc/nginx/httpd.conf
	  notify: restart httpd
	  tags: modify httpd config
	- name: start httpd
	  service: name=httpd state=started enabled=true
[[email protected] ansible]# cat roles/httpd/tasks/remove_httpd.yml 
	- name: remove httpd
	  yum: name=httpd state=absent
	- name: remove php
	  yum: name=php state=absent
[[email protected] ansible]# cat roles/httpd/tasks/main.yml 
	- include: tasks/install_httpd.yml
	  when:  ansible_eth0.ipv4.address == ‘172.16.0.128‘ or ansible_eth0.ipv4.address == ‘172.16.0.129‘
	  tags: install 
	- include: tasks/remove_httpd.yml	  tags: remove 
	  when:  ansible_eth0.ipv4.address == ‘172.16.0.128‘ or ansible_eth0.ipv4.address == ‘172.16.0.129‘
[[email protected] ansible]# cat roles/httpd/templates/httpd.conf.j2
 #默认配置,里面可以定义变量就懒得贴了
[[email protected] ansible]# cat roles/httpd/vars/main.yml 
	index:
	- index.php
	- index.html
[[email protected] ansible]# tree roles/keepalived/	#keepalived角色目录结构
	roles/keepalived/
	├── default
	├── files
	├── handlers
	│   └── main.yml
	├── meta
	├── tasks
	│   ├── install_keepalived.yml
	│   ├── main.yml
	│   └── remove_keepalived.yml
	├── templates
	│   ├── keepalived.conf.j2
	│   └── keepalived.conf.j2.bak
└── vars7 directories, 6 files
[[email protected] ansible]# cat roles/keepalived/handlers/main.yml 
	- name: restart keepalived
	  service: name=keepalived state=restarted
[[email protected] ansible]# cat roles/keepalived/tasks/install_keepalived.yml 
	- name: install keepalived
	  yum: name=keepalived state=present
	- name: install keepalived config
	  template: src=keepalived.conf.j2 dest=/etc/keepalived/keepalived.conf
	  notify: restart keepalived
	  tags: modify keepalived config
	- name: start keepalived 
	  service: name=keepalived state=started enabled=true
[[email protected] ansible]# cat roles/keepalived/tasks/remove_keepalived.yml 
	- name: remove keepalived
	  yum: name=keepalived state=absent
[[email protected] ansible]# cat roles/keepalived/tasks/main.yml 
	- include: tasks/install_keepalived.yml
	  tags: install 
	  when:  ansible_eth1.ipv4.address == ‘172.16.0.4‘ or ansible_eth1.ipv4.address == ‘172.16.0.2‘
	- include: tasks/remove_keepalived.yml
	  tags: remove 
	  when:  ansible_eth1.ipv4.address == ‘172.16.0.4‘ or ansible_eth1.ipv4.address == ‘172.16.0.2‘
[[email protected] ansible]# cat roles/keepalived/templates/keepalived.conf.j2
	! Configuration File for keepalived

	global_defs {
	   notification_email {
		[email protected]
	   }
	   notification_email_from [email protected]
	   smtp_server 127.0.0.1
	   smtp_connect_timeout 30
	   router_id LVS_DEVEL
	   vrrp_mcast_group4 224.0.100.18
	}

	vrrp_instance VI_1 {
		state {{ mb }}
		interface eth0
		virtual_router_id 51
		priority {{ prioroty }}
		advert_int 1
		authentication {
			auth_type PASS
			auth_pass 1111
		}
		virtual_ipaddress {		192.168.220.5/24
		}
	}
四、执行ansible-playbook
[[email protected] ansible]# pwd		#查看所在目录
	/etc/ansible
[[email protected] ansible]# ls		#查看有没有service.tml文件
	ansible.cfg  hosts  roles  service.retry  service.yml
[[email protected] ansible]# ansible-playbook -t "install" --check service.yml 
 #执行前测试使用--check ,-t指定我要所需要的tags这里选择"install"在每个tasks/main.yml都有定义另外一个是"remove"
	statically included: /etc/ansible/roles/nginx/tasks/install_nginx.yml
	statically included: /etc/ansible/roles/nginx/tasks/remove_nginx.yml
	statically included: /etc/ansible/roles/httpd/tasks/install_httpd.yml
	statically included: /etc/ansible/roles/httpd/tasks/remove_httpd.yml
	statically included: /etc/ansible/roles/keepalived/tasks/install_keepalived.yml
	statically included: /etc/ansible/roles/keepalived/tasks/remove_keepalived.yml

	PLAY [all] *********************************************************************

	TASK [setup] *******************************************************************
	ok: [172.16.0.2]
	ok: [172.16.0.128]
	ok: [172.16.0.4]
	ok: [172.16.0.129]
	ok: [172.16.0.5]

	TASK [nginx : install nginx] ***************************************************
	 #定义的- name: install nginx的名称就是这里用的
	skipping: [172.16.0.128]
	 #skipping,因为我们使用了when判断
	skipping: [172.16.0.5]
	skipping: [172.16.0.129]
	changed: [172.16.0.4]
	 #符合我们的判断才执行
	changed: [172.16.0.2]

	TASK [nginx : install nginx index.html] ****************************************
	skipping: [172.16.0.5]
	skipping: [172.16.0.128]
	skipping: [172.16.0.129]
	changed: [172.16.0.4]
	changed: [172.16.0.2]

	TASK [nginx : install config] **************************************************
	skipping: [172.16.0.129]
	skipping: [172.16.0.5]
	skipping: [172.16.0.128]
	changed: [172.16.0.2]
	changed: [172.16.0.4]

	TASK [nginx : start nginx] *****************************************************
	skipping: [172.16.0.128]
	skipping: [172.16.0.5]
	skipping: [172.16.0.129]
	changed: [172.16.0.2]
	changed: [172.16.0.4]

	TASK [httpd : install httpd] ***************************************************
	skipping: [172.16.0.2]
	skipping: [172.16.0.4]
	skipping: [172.16.0.5]
	changed: [172.16.0.128]
	changed: [172.16.0.129]

	TASK [httpd : install php] *****************************************************
	skipping: [172.16.0.2]
	skipping: [172.16.0.4]
	skipping: [172.16.0.5]
	changed: [172.16.0.129]
	changed: [172.16.0.128]

	TASK [httpd : install httpd  index.html] ***************************************
	skipping: [172.16.0.2]
	skipping: [172.16.0.5]
	skipping: [172.16.0.4]
	ok: [172.16.0.128]
	ok: [172.16.0.129]

	TASK [httpd : install httpd  index.php] ****************************************
	skipping: [172.16.0.2]
	skipping: [172.16.0.4]
	skipping: [172.16.0.5]
	ok: [172.16.0.128]
	ok: [172.16.0.129]

	TASK [httpd : install config] **************************************************
	skipping: [172.16.0.2]
	skipping: [172.16.0.4]
	skipping: [172.16.0.5]
	ok: [172.16.0.128]
	ok: [172.16.0.129]

	TASK [httpd : start httpd] *****************************************************
	skipping: [172.16.0.4]
	skipping: [172.16.0.2]
	skipping: [172.16.0.5]
	changed: [172.16.0.129]
	changed: [172.16.0.128]

	TASK [keepalived : install keepalived] *****************************************
	skipping: [172.16.0.129]
	skipping: [172.16.0.5]
	skipping: [172.16.0.128]
	changed: [172.16.0.2]
	changed: [172.16.0.4]

	TASK [keepalived : install keepalived config] **********************************
	skipping: [172.16.0.128]
	skipping: [172.16.0.5]
	skipping: [172.16.0.129]
	changed: [172.16.0.2]
	changed: [172.16.0.4]

	TASK [keepalived : start keepalived] *******************************************
	skipping: [172.16.0.128]
	skipping: [172.16.0.5]
	skipping: [172.16.0.129]
	changed: [172.16.0.4]
	changed: [172.16.0.2]

	RUNNING HANDLER [nginx : restart nginx] ****************************************
	fatal: [172.16.0.2]: FAILED! => {"changed": false, "failed": true, "msg": "systemd could not find the requested service \"‘nginx‘\": "}
	#请注意查看提示报错,systemd could not find the requested service \"‘nginx‘\,因为我们这里是测试而且是由定义配置触发的handlers
	fatal: [172.16.0.4]: FAILED! => {"changed": false, "failed": true, "msg": "systemd could not find the requested service \"‘nginx‘\": "}
	#请注意查看提示报错,systemd could not find the requested service \"‘nginx‘\,因为我们这里是测试而且是由定义配置触发的handlers

	RUNNING HANDLER [keepalived : restart keepalived] ******************************

	NO MORE HOSTS LEFT *************************************************************
		to retry, use: --limit @/etc/ansible/service.retry

	PLAY RECAP *********************************************************************	#显示测试的返回统计,没什么问题
	172.16.0.128               : ok=7    changed=3    unreachable=0    failed=0   
	172.16.0.129               : ok=7    changed=3    unreachable=0    failed=0   
	172.16.0.2                 : ok=8    changed=7    unreachable=0    failed=1   
	172.16.0.4                 : ok=8    changed=7    unreachable=0    failed=1   
	172.16.0.5                 : ok=1    changed=0    unreachable=0    failed=0
[[email protected] ansible]# ansible-playbook -t "install"  service.yml 
 #执行去掉--check ,-t指定我要所需要的tags这里选择"install"在每个tasks/main.yml都有定义另外一个是"remove"
		statically included: /etc/ansible/roles/nginx/tasks/install_nginx.yml
		statically included: /etc/ansible/roles/nginx/tasks/remove_nginx.yml
		statically included: /etc/ansible/roles/httpd/tasks/install_httpd.yml
		statically included: /etc/ansible/roles/httpd/tasks/remove_httpd.yml
		statically included: /etc/ansible/roles/keepalived/tasks/install_keepalived.yml
		statically included: /etc/ansible/roles/keepalived/tasks/remove_keepalived.yml

		PLAY [all] *********************************************************************

		TASK [setup] *******************************************************************
		ok: [172.16.0.2]
		ok: [172.16.0.129]
		ok: [172.16.0.4]
		ok: [172.16.0.128]
		ok: [172.16.0.5]

		TASK [nginx : install nginx] ***************************************************
		skipping: [172.16.0.5]
		skipping: [172.16.0.129]
		skipping: [172.16.0.128]
		changed: [172.16.0.4]
		changed: [172.16.0.2]

		TASK [nginx : install nginx index.html] ****************************************
		skipping: [172.16.0.128]
		skipping: [172.16.0.5]
		skipping: [172.16.0.129]
		changed: [172.16.0.2]
		changed: [172.16.0.4]

		TASK [nginx : install config] **************************************************
		skipping: [172.16.0.128]
		skipping: [172.16.0.5]
		skipping: [172.16.0.129]
		changed: [172.16.0.4]
		changed: [172.16.0.2]

		TASK [nginx : start nginx] *****************************************************
		skipping: [172.16.0.128]
		skipping: [172.16.0.5]
		skipping: [172.16.0.129]
		changed: [172.16.0.4]
		changed: [172.16.0.2]

		TASK [httpd : install httpd] ***************************************************
		skipping: [172.16.0.2]
		skipping: [172.16.0.4]
		skipping: [172.16.0.5]
		changed: [172.16.0.129]
		changed: [172.16.0.128]

		TASK [httpd : install php] *****************************************************
		skipping: [172.16.0.4]
		skipping: [172.16.0.2]
		skipping: [172.16.0.5]
		changed: [172.16.0.129]
		changed: [172.16.0.128]

		TASK [httpd : install httpd  index.html] ***************************************
		skipping: [172.16.0.4]
		skipping: [172.16.0.2]
		skipping: [172.16.0.5]
		ok: [172.16.0.129]
		ok: [172.16.0.128]

		TASK [httpd : install httpd  index.php] ****************************************
		skipping: [172.16.0.2]
		skipping: [172.16.0.4]
		skipping: [172.16.0.5]
		ok: [172.16.0.129]
		ok: [172.16.0.128]

		TASK [httpd : install config] **************************************************
		skipping: [172.16.0.2]
		skipping: [172.16.0.4]
		skipping: [172.16.0.5]
		ok: [172.16.0.128]
		ok: [172.16.0.129]

		TASK [httpd : start httpd] *****************************************************
		skipping: [172.16.0.4]
		skipping: [172.16.0.2]
		skipping: [172.16.0.5]
		changed: [172.16.0.128]
		changed: [172.16.0.129]

		TASK [keepalived : install keepalived] *****************************************
		skipping: [172.16.0.5]
		skipping: [172.16.0.128]
		skipping: [172.16.0.129]
		changed: [172.16.0.4]
		changed: [172.16.0.2]

		TASK [keepalived : install keepalived config] **********************************
		skipping: [172.16.0.128]
		skipping: [172.16.0.5]
		skipping: [172.16.0.129]
		changed: [172.16.0.4]
		changed: [172.16.0.2]

		TASK [keepalived : start keepalived] *******************************************
		skipping: [172.16.0.128]
		skipping: [172.16.0.5]
		skipping: [172.16.0.129]
		changed: [172.16.0.2]
		changed: [172.16.0.4]

		RUNNING HANDLER [nginx : restart nginx] ****************************************
		changed: [172.16.0.2]
		changed: [172.16.0.4]

		RUNNING HANDLER [keepalived : restart keepalived] ******************************
		changed: [172.16.0.4]
		changed: [172.16.0.2]

		PLAY RECAP *********************************************************************
		172.16.0.128               : ok=7    changed=3    unreachable=0    failed=0   
		172.16.0.129               : ok=7    changed=3    unreachable=0    failed=0   
		172.16.0.2                 : ok=10   changed=9    unreachable=0    failed=0   
		172.16.0.4                 : ok=10   changed=9    unreachable=0    failed=0   
		172.16.0.5                 : ok=1    changed=0    unreachable=0    failed=0
五、验证服务
[[email protected] ansible]# ansible all -m shell -a "ss -tnlp| grep ‘nginx\|httpd\|keepalived‘"
	172.16.0.129 | SUCCESS | rc=0 >>
	LISTEN     0      128         :::80                      :::*                   users:(("httpd",pid=15560,fd=4),("httpd",pid=15559,fd=4),("httpd",pid=15558,fd=4),("httpd",pid=15557,fd=4),("httpd",pid=15556,fd=4),("httpd",pid=15554,fd=4))

	172.16.0.5 | FAILED | rc=1 >>	172.16.0.2 | SUCCESS | rc=0 >>
	LISTEN     0      128          *:80                       *:*                   users:(("nginx",pid=44210,fd=6),("nginx",pid=44209,fd=6))

	172.16.0.4 | SUCCESS | rc=0 >>
	LISTEN     0      128          *:80                       *:*                   users:(("nginx",pid=44424,fd=6),("nginx",pid=44423,fd=6))

	172.16.0.128 | SUCCESS | rc=0 >>
	LISTEN     0      128         :::80                      :::*                   users:(("httpd",pid=16300,fd=4),("httpd",pid=16299,fd=4),("httpd",pid=16298,fd=4),("httpd",pid=16297,fd=4),("httpd",pid=16296,fd=4),("httpd",pid=16294,fd=4))
[[email protected] ansible]# curl 192.168.220.5
	<h1>Test file.</h1>
[[email protected] ansible]# curl 192.168.220.5/index.php | grep Centos7
	  % Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
	    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0<tr><td class="e">System </td><td class="v">Linux Centos7 3.10.0-327.el7.x86_64 
	    #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 </td> </tr>	100 53535    0 53535    0     0  1376k      0 --:--:-- --:--:-- --:--:-- 1493k

ps:其它的可以自行研究~

时间: 2025-01-31 03:58:02

Ansible 一键配置安装Keepalived+Nginx作为前端,httpd+php作为后端的相关文章

Keepalived+Nginx提供前端负载均衡+主从双机热备+自动切换

原文链接:http://unun.in/linux/156.html 方案: 采用两台Nginx服务器作为前端,提供静态web内容,分发web请求,一主一从,Keepalived实现状态监测,保证 Nginx正常对外提供服务,即主Nginx服务进程死掉之后,keepalived能够通过脚本或者程序检测机制,将网站的访问切换到从Nginx上 来.后端的web应用服务器的监控由Nginx负责,keepalived只监控Nginx的健康状况. 性能:大约是硬件负载均衡器的10% 优势:虽然性能远弱于L

通过nginx部署前端代码实现前后端分离

实现前后端分离,可以让前后端独立开发.独立部署.独立单测,双方通过JSON进行数据交互. 对于前端开发人员来说,不用每次调试都需要启动或配置Java/Tomcat运行环境:对于后端开发人员来说 ,也不用在需要往JSP页面注入数据. 通过nginx来部署前端代码,可以帮助前端实现以下基本需求: 1.请求转发,解决请求跨域的问题 server { listen       7777; location /{ root   /Users/xiaoyun/git/someproject/dist; }

生产环境模拟实现keepalived+Nginx调度器+httpd的高可用集群

具体过程是用Nginx做负载均衡,可以将Nginx和主机放在同一台机子上,也可以分开放置,只不过分开的话要指明RS是Nginx的主机地址.至于直接将虚拟地址配置在Nginx主机上我暂时还未成功 下面附上我的双主模型的主keepalived服务器的配置 ! Configuration File for keepalived global_defs {    notification_email {     [email protected]     vrrp_mcast_group4  224.0

P4语言环境安装(一)前端编译器p4c、后端编译器p4c-bm2-ss

这个P4安装环境是在2020-2-8安装的,安装环境卡了我好几天,把遇到的问题记录下来,有需要的同学可以参考一下,要是说错了或者有问题的话,评论或mail:[email protected]联系我都可以. P4语言组织官网:https://p4.org/ 本文安装代码就是从官网引导的p4language上下载的. 介绍 我看P4是刚看了三四十小时,大都用在安装环境了,觉得它就是一个控制修改数据流的语言,提供一个标准的结构,方便用户对控制平面和数据平面进行修改. 我理解的P4开发流程就是四步 程序

ansible-playbook自动化安装Keepalived实现Nginx服务双机热备自动化配置

脚本实现通过ansible-playbook自动化安装Keepalived和配置,主要解决问题如下: Keepalived自动化安装: keepalived_vrid配置,自动根据vip获取最后一段作为vrid,确保同一网段不会出现vrid冲突导致HA切换失败的问题: 自动配置Keepalived: HA检测脚本自定义,根据脚本内容,来做redis或nginx或其他软件的双机热备: 自动配置vip给Keepalived 设置Keepalived开机启动,加入系统服务: Keepalived安装脚

LVS+Nginx(LVS + Keepalived + Nginx安装及配置)

(也可以每个nginx都挂在上所有的应用服务器) nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广泛接受还要早7年,并且已经被红帽作为了系统内置软件,可谓很牛了.lvs相对于nginx来说配置上就要相对复杂一些. 但是,有时候我们会看到大牛们分享的经验里面是lvs+nginx作为负载均衡了,一直想不明白这是个什么道理. 为什么会出现两者被同时使用呢?其实,这要从两者的各自优势来说了. nginx用

架构设计:负载均衡层设计方案(7)——LVS + Keepalived + Nginx安装及配置

1.概述 上篇文章<架构设计:负载均衡层设计方案(6)--Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/article/details/47130609) 我们解说了Nginx的故障切换.而且承诺各位读者会尽快解说 LVS + Keepalived + Nginx的安装和配置.在中间由于工作的原因.我又插写了三篇关于zookeeper的原理使用的文章.今天这边文章我们回归主题.为各位读者解说LVS + Keepalive

LVS + Keepalived + Nginx安装及配置

1.概述 上篇文章<架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/article/details/47130609) 我们讲解了Nginx的故障切换,并且承诺各位读者会尽快讲解 LVS + Keepalived + Nginx的安装和配置.在中间由于工作的原因,我又插写了三篇关于zookeeper的原理使用的文章.今天这边文章我们回归主题,为各位读者讲解 LVS + Keepaliv

keepalived+nginx安装配置

软件版本: pcre8.36 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz keepalived1.2.19 http://www.keepalived.org/software/keepalived-1.2.19.tar.gz nginx1.8.0 http://nginx.org/download/nginx-1.8.0.tar.gz <pre name="code" class=