0%

小白学爬虫-批量部署Splash负载集群

部署公司生产环境的Splash集群无奈节点太多 差点被搞死·· 还好我有运维神器Ansible,一次编撰终生可用啊!而且这玩意儿 等幂特性 扩容回滚 So Easy!! 闲话少说开搞!

安装Ansible:

看官方文档去:http://www.ansible.com.cn/index.html 好像这个主控端不支持Windows? 大家虚拟机装个Ubuntu吧。

闲话少扯直接上干货:

整体目录如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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两个分组如下:

1
2
3
4
5
6
7
study@study:~/文档/ansible-examples$ cat /etc/ansible/inventory/splash 
[docker]
1.1.1.1
[haproxy]
10.253.20.25

[splash_ports]

主控端新建SSH秘钥并发布到你你需要配置的所有主机!!!!(一定要注意如果本机当前工作用户在远程主机不存在额时候,需要指定remote_user这个参数):

1
2
3
4
5
study@study:~/文档/ansible-examples$ cat /etc/ansible/ansible.cfg 
[defaults]
inventory= /etc/ansible/inventory/

remote_user=root

好了开始执行:

1
study@study:~/文档/ansible-examples/Splash_Load_balancing_cluster$ ansible-playbook site.yml

效果就像这样:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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分组下 重新执行一遍就可以了! 需要注意如果SSH非默认的22端口还需要指定你的端口号!怎么指定 看看文档去 以上完毕!!! 完整的看这儿:https://github.com/thsheep/ansible-examples