saltstacksaltstack一键部署keepalived和zabbix自动监控平台
Posted dezasseis
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了saltstacksaltstack一键部署keepalived和zabbix自动监控平台相关的知识,希望对你有一定的参考价值。
一、saltstack自动部署keepalived
01_配置
vim /srv/salt/apache/files/httpd.conf
Listen {{ port }}
-
建立keepalived目录
mkdir /srv/salt/keepalived
mkdir /srv/salt/keepalived/files
-
编辑引导文件
vim /srv/salt/keepalived/init.sls
kp-install:
pkg.installed:
- name: keepalived
file.managed:
- name: /etc/keepalived/keepalived.conf
- source: salt://keepalived/files/keepalived.conf
- template: jinja
- context:
STATE: {{ pillar['state'] }}
VRID: {{ pillar['vrid'] }}
PRI: {{ pillar['pri'] }}
service.running:
- name: keepalived
- enable: true
- reload: true
- watch:
- file: kp-install
vim /srv/pillar/package.sls
{% if grains['fqdn'] == 'server3' %}
package: nginx
state: BACKUP
vrid: 51
pri: 50
{% elif grains['fqdn'] == 'server2' %}
port: 80
bind: 192.168.17.2
state: MASTER
vrid: 51
pri: 100
{% endif %}
vim /srv/salt/top.sls
base:
'*':
- package
vim /srv/salt/keepalived/files/keepalived.conf
:编辑jinja模板
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state {{ STATE }}
interface eth0
virtual_router_id {{ VRID }}
priority {{ PRI }}
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.25.2.100
}
}
salt '*' state.highstate
02_测试
- 查看实验结果
- 当停掉server2的keepalived时,BACKUP端(server3)自动开启
- 再次
salt '*' state.highstate
,server2的keepalived自动开启,自动添加VIP
二、saltstack自动部署zabbix
master端:server1:172.25.2.1
zabbix-server端:server2:172.25.2.2
zabbix-数据库端:server3:172.25.2.3
01_文件结构
mkdir -p /srv/salt/zabbix-server/files
mkdir -p /srv/salt/mysql/files
02_模板文件
server2文件可通过如下命令得到
salt server2 state.sls zabbix-server
server3文件可通过如下命令得到
salt server3 state.sls mysql
-
my.cnf
scp server3:/etc/my.cnf /srv/salt/mysql/files/
vim /srv/salt/mysql/files/my.cnf
log-bin=mysql-bin
character-set-server=utf8
-
create.sql
cd /srv/salt/mysql/files/
scp server2:/usr/share/doc/zabbix-server-mysql-4.0.5/create.sql.gz .
gunzip create.sql.gz
-
zabbix_server.conf
scp server2:/etc/zabbix/zabbix_server.conf /srv/salt/zabbix-server/files/
vim /srv/salt/zabbix-server/files/zabbix_server.conf
91 DBHost=192.168.17.3#数据库端IP
100 DBName=zabbix
116 DBUser=zabbix
124 DBPassword=westos
-
zabbix.conf
scp server2:/etc/httpd/conf.d/zabbix.conf /srv/salt/zabbix-server/files/
vim /srv/salt/zabbix-server/files/zabbix.conf:修改时区为:Asia/Shanghai
-
zabbix.conf.php:初始化文件(避免初始化)
scp server2:/etc/zabbix/web/zabbix.conf.php /srv/salt/zabbix-server/files/
(在zabbix平台部署好之后,在前端页面初始化即可在zabbix-server端生成该文件)
03_编写.sls文件
/srv/salt/zabbix-server/init.sls
zabbix-server:
pkgrepo.managed:
- name: zabbix
- humanname: zabbix 4.0
- baseurl: http://172.25.2.250/4.0/#在172.25.2.250的/var/www/html下有此目录
- gpgcheck: 0
pkg.installed:
- pkgs:
- zabbix-server-mysql
- zabbix-agent
- zabbix-web-mysql
file.managed:
- name: /etc/zabbix/zabbix_server.conf
- source: salt://zabbix-server/files/zabbix_server.conf
service.running:
- name: zabbix-server
- enable: true
- watch:
- file: zabbix-server
zabbix-agent:
service.running
zabbix-web:
file.managed:
- name: /etc/httpd/conf.d/zabbix.conf
- source: salt://zabbix-server/files/zabbix.conf
service.running:
- name: httpd
- enable: true
- watch:
- file: zabbix-web
/etc/zabbix/web/zabbix.conf.php:
file.managed:
- source: salt://zabbix-server/files/zabbix.conf.php
/srv/salt/mysql/init.sls
mysql-install:
pkg.installed:
- pkgs:
- mariadb-server
- MySQL-python
file.managed:
- name: /etc/my.cnf
- source: salt://mysql/files/my.cnf
service.running:
- name: mariadb
- enable: true
- watch:
- file: mysql-install
mysql-config:
mysql_database.present:
- name: zabbix
mysql_user.present:
- name: zabbix
- host: '%'
- password: "westos"
mysql_grants.present:
- grant: all privileges
- database: zabbix.*
- user: zabbix
- host: '%'
file.managed:
- name: /mnt/create.sql
- source: salt://mysql/files/create.sql
cmd.run:
- name: mysql zabbix < /mnt/create.sql && touch /mnt/zabbix.lock
- creates: /mnt/zabbix.lock
/srv/salt/top.sls
base:
'roles:apache':
- match: grain
- apache
- zabbix-server
'roles:nginx':
- match: grain
- nginx
- mysql
以上是关于saltstacksaltstack一键部署keepalived和zabbix自动监控平台的主要内容,如果未能解决你的问题,请参考以下文章
saltstacksaltstack自动化运维(master与minion配置远程执行sls文件modulesgrainsjinjapillar)