自动化部署脚本结构
1.软件仓库模块
[root@server1 salt]# cat repos/init.sls
zabbix:
pkgrepo.managed:
- baseurl: http://172.25.3.250/4.0
- gpgcheck: 0
2.数据库配置模块
思路:安装数据库,创建zabbix数据库并授权,然后将zabbix-server数据模板导入数据库
[root@server1 salt]# cat mariadb/init.sls
db-install:
pkg.installed:
- pkgs:
- mariadb-server
- mariadb
- MySQL-python
service.running:
- name: mariadb
db-configure:
mysql_database.present:
- name: zabbix
- character_set: utf8
- collate: utf8_bin
- connection_user: root
- connection_pass:
mysql_user.present:
- name: zabbix
- host: localhost
- password: westos
- connection_user: root
- connection_pass:
mysql_grants.present:
- grant: all privileges
- database: zabbix.*
- user: zabbix
- connection_user: root
- connection_pass:
file.managed:
- name: /mnt/create.sql.gz
- source: salt://file/create.sql.gz
cmd.wait:
- name: zcat /mnt/create.sql.gz | mysql -uroot zabbix
- watch:
- mysql_database: db-configure
3.zabbix配置模块
安装zabbix-server、zabbix-agent,修改server主配置文件/添加DBPasswd
[root@server1 salt]# cat zabbix-server/init.sls
server-install:
pkg.installed:
- pkgs:
- zabbix-server-mysql
- zabbix-agent
- zabbix-web-mysql
file.managed:
- name: /etc/zabbix/zabbix_server.conf
- source: salt://file/zabbix_server.conf
zabbix-server:
service.running:
- reload: true
- enable: true
- watch:
- file: server-install
zabbix-agent:
service.running:
- reload: true
- enable: true
- watch:
- file: server-install
4.zabbix-web-mysql模块
安装zabbix-web-mysql,修改主配内时区,并启动httpd
[root@server1 salt]# cat web/init.sls
web-install:
pkg.installed:
- pkgs:
- zabbix-web-mysql
file.managed:
- name: /etc/httpd/conf.d/zabbix.conf
- source: salt://file/zabbix.conf
httpd:
service.running:
- reload: true
- enable: true
- watch:
- file: server-install
5.highstate调用
[root@server1 salt]# cat top.sls
base:
'server3':
- repos
- mariadb
- zabbix-server
- web
查看效果
执行命令:
salt server3 state.highstate
结果:
访问网页:
成功