安装Ansible:
看官方文档去:http://www.ansible.com.cn/index.html
好像这个主控端不支持Windows? 大家虚拟机装个Ubuntu吧。
闲话少扯直接上干货:
整体目录如下:
study@study:~/文档/ansible-examples$ tree Splash_Load_balancing_cluster
Splash_Load_balancing_cluster
├── group_vars
│ └── all
├── roles
│ ├── common
│ │ ├── files
│ │ │ ├── CentOS-Base.repo
│ │ │ ├── docker-ce.repo
│ │ │ ├── epel.repo
│ │ │ ├── ntp.conf
│ │ │ └── RPM-GPG-KEY-EPEL-7
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── templates
│ ├── docker
│ │ ├── handlers
│ │ │ └── main.yml
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── templates
│ │ └── daemon.json.j2
│ ├── haproxy
│ │ ├── handlers
│ │ │ └── main.yml
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── templates
│ │ └── haproxy.cfg.j2
│ └── splash
│ ├── files
│ │ ├── filters
│ │ │ └── default.txt
│ │ ├── js-profiles
│ │ ├── lua_modules
│ │ └── proxy-profiles
│ │ └── proxy.ini
│ └── tasks
│ └── main.yml
├── site.retry
└── site.yml
Group_vars: 里面定义全局使用的变量
Roles: 存放所有的规则目录
Roles/common :所有服务器初始化配置部署
Roles/common/filters :需要使用的文件或者文件夹
Roles/common/task:部署任务(main.yml为入口必须要有)
Roles/common/templates :配置模板(jinja2模板语法 用于可变更的配置文件,可获取定义在Group_vars中的变量)
Roles/Docker :Docker的安装配置
Roles/HAproxy : HAproxy的负载均衡配置
Roles/Splash : Splash的镜像拉取配置部署以及启动
site.yml : 启动入口
使用方法:
在你的Inventory文件定义好主机分组:
必须包括HaProxy、和Docker两个分组如下:
study@study:~/文档/ansible-examples$ cat /etc/ansible/inventory/splash
[docker]
1.1.1.1
[haproxy]
10.253.20.25
[splash_ports]
主控端新建SSH秘钥并发布到你你需要配置的所有主机!!!!(一定要注意如果本机当前工作用户在远程主机不存在额时候,需要指定remote_user这个参数):
study@study:~/文档/ansible-examples$ cat /etc/ansible/ansible.cfg
[defaults]
inventory= /etc/ansible/inventory/
remote_user=root
好了开始执行:
study@study:~/文档/ansible-examples/Splash_Load_balancing_cluster$ ansible-playbook site.yml
效果就像这样:
PLAY [all] **********************************************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************************************
ok: [10.1.4.101]
ok: [10.1.4.100]
TASK [common : Copy the CentOS repository definition] ***************************************************************************************************************************************
ok: [10.1.4.100]
ok: [10.1.4.101]
TASK [common : Copy the Docker repository definition] ***************************************************************************************************************************************
ok: [10.1.4.100]
ok: [10.1.4.101]
TASK [common : Create the repository for EPEL] **********************************************************************************************************************************************
ok: [10.1.4.100]
ok: [10.1.4.101]
TASK [common : Create the GPG key for EPEL] *************************************************************************************************************************************************
ok: [10.1.4.100]
ok: [10.1.4.101]
TASK [common : Firewalld service stop] ******************************************************************************************************************************************************
ok: [10.1.4.100]
ok: [10.1.4.101]
TASK [common : Chronyd service stop] ********************************************************************************************************************************************************
ok: [10.1.4.100]
ok: [10.1.4.101]
TASK [common : Install Ansible Base package] ************************************************************************************************************************************************
ok: [10.1.4.100] => (item=['libselinux-python', 'libsemanage-python', 'ntp'])
ok: [10.1.4.101] => (item=['libselinux-python', 'libsemanage-python', 'ntp'])
TASK [common : Configure SELinux to disable] ************************************************************************************************************************************************
[WARNING]: SELinux state change will take effect next reboot
ok
: [10.1.4.100]
ok: [10.1.4.101]
TASK [common : Change TimeZone] *************************************************************************************************************************************************************
ok: [10.1.4.100]
ok: [10.1.4.101]
TASK [common : Copy NTP conf] ***************************************************************************************************************************************************************
ok: [10.1.4.100]
ok: [10.1.4.101]
TASK [common : NTP Start] *******************************************************************************************************************************************************************
ok: [10.1.4.100]
ok: [10.1.4.101]
PLAY [docker] *******************************************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************************************
ok: [10.1.4.101]
TASK [docker : Install Docker package] ******************************************************************************************************************************************************
ok: [10.1.4.101] => (item=['yum-utils', 'device-mapper-persistent-data', 'lvm2', 'docker-ce'])
TASK [docker : Start Docker] ****************************************************************************************************************************************************************
ok: [10.1.4.101]
TASK [docker : Create Docker Speed Configuration file] **************************************************************************************************************************************
ok: [10.1.4.101]
TASK [docker : Restart Docker] **************************************************************************************************************************************************************
changed: [10.1.4.101]
TASK [splash : pull splash] *****************************************************************************************************************************************************************
changed: [10.1.4.101]
TASK [splash : Copy Splash module] **********************************************************************************************************************************************************
ok: [10.1.4.101] => (item=filters)
ok: [10.1.4.101] => (item=js-profiles)
ok: [10.1.4.101] => (item=lua_modules)
ok: [10.1.4.101] => (item=proxy-profiles)
静静等着跑完 就可以愉快的使用啦 ! 需要增加节点的话直接把IP加载Docker分组下 重新执行一遍就可以了!