部署zabbix
一、安装mysql
1.server3安装mysql测试
[root@server1 ~]# cp /etc/my.cnf /srv/salt/mysql/ #复制数据库配置文件
[root@server1 salt]# mkdir mysql
[root@server1 salt]# cd mysql/
[root@server1 mysql]# vim init.sls
[root@server1 mysql]# ls
init.sls my.cnf
[root@server1 mysql]# cat init.sls
mysql-install:
pkg.installed:
- pkgs:
- mariadb-server
- MySQL-python
file.managed:
- name: /etc/my.cnf
- source: salt://mysql/my.cnf
service.running:
- name: mariadb
- enable: true
- watch:
- file: mysql-install
[root@server1 mysql]# vim my.cnf ##添加行
11 log-bin=mysql-bin
12 character-set-server=utf8
[root@server1 mysql]# salt server3 state.sls mysql #响应,给server3安装并配置数据库
[root@server3 conf]# mysql
MariaDB [(none)]> show variables like 'char%';
2.创建用户
[root@server1 mysql]# vim init.sls ##添加行
mysql-config:
mysql_database.present:
- name: zabbix
mysql_user.present:
- name: zabbix
- host: localhost
- password: "westos"
[root@server1 mysql]# salt server3 state.sls mysql #执行
[root@server3 ~]# mysql
MariaDB [(none)]> show variables like 'char%';
MariaDB [(none)]> select * from mysql.user;
[root@foundation50 ~]# mysql -h 172.25.15.3 -u zabbix -p #连接机器也需要装mysql
Enter password: westos
3.授权
[root@server1 yum.repos.d]# cd /usr/share/doc/zabbix-server-mysql-4.0.5/
[root@server1 zabbix-server-mysql-4.0.5]# scp create.sql.gz server1:/srv/salt/mysql/
[root@server1 mysql]# gunzip create.sql.gz
[root@server1 mysql]# ls
create.sql my.cnf
[root@server1 mysql]# vim init.sls ##添加行
mysql_grants.present:
- grant: all privileges
- database: zabbix.*
- user: zabbix
- host: localhost ##授予的用户
file.managed:
- name: /mnt/create.sql
- source: salt://mysql/create.sql
cmd.run:
- name: mysql zabbix < /mnt/create.sql && touch /mnt/zabbix.lock
- creates: /mnt/zabbix.lock
[root@server1 mysql]# salt server3 state.sls mysql #执行
[root@server3 ~]# cd /mnt
[root@server3 mnt]# ls
create.sql nginx-1.20.1 nginx-1.20.1.tar.gz testfile zabbix.lock
[root@server3 ~]# mysql
MariaDB [(none)]> use zabbix
MariaDB [zabbix]> show tables;
二、远程安装zabbix
1.远程配置zabbix仓库
[root@server1 apache]# cd /srv/salt/
[root@server1 salt]# mkdir zabbix-server
[root@server1 salt]# cd zabbix-server/
[root@server1 zabbix-server]# ls
[root@server1 zabbix-server]# vim init.sls
[root@server1 zabbix-server]# cat init.sls
zabbix-server:
pkgrepo.managed:
- name: zabbix
- humanname: zabbix 4.0
- baseurl: http://172.25.15.250/zabbix/4.0
- gpgcheck: 0
[root@server1 zabbix-server]# salt server2 state.sls zabbix-server #响应,部署仓库
[root@server2 yum.repos.d]# yum repolist
server2查看仓库是否完成
2.部署zabbix
[root@server1 zabbix-server]# vim init.sls
zabbix-server:
pkgrepo.managed:
- name: zabbix
- humanname: zabbix 4.0
- baseurl: http://172.25.15.3/zabbix/4.0
- 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/zabbix_server.conf
service.running:
- name: zabbix-server
- enable: true
- watch:
- file: zabbix-server
zabbix-agent:
service.running
[root@server1 zabbix-server]# cd /etc/zabbix/
[root@server1 zabbix]# ls
zabbix_server.conf
[root@server1 zabbix]# cp zabbix_server.conf /srv/salt/zabbix-server/
[root@server1 zabbix]# ls
zabbix_server.conf
[root@server1 zabbix]# cd /srv/salt/zabbix-server/
[root@server1 zabbix-server]# ls
init.sls zabbix_server.conf
[root@server1 zabbix-server]# vim zabbix_server.conf
91 DBHost=172.25.15.3
124 DBPassword=westos
[root@server1 zabbix-server]# salt server2 state.sls zabbix-server
Server2查看
[root@server2 ~]# yum install -y mariadb
[root@server2 zabbix]# mysql -h 172.25.15.3 -u zabbix -p
MariaDB [(none)]> use zabbix
MariaDB [zabbix]> show tables;
3. web前端
[root@server1 conf.d]# yum install -y zabbix-web
[root@server1 conf.d]# cd /etc/httpd/conf.d/
[root@server1 conf.d]# ls
autoindex.conf php.conf README userdir.conf welcome.conf zabbix.conf
[root@server1 conf.d]# cp zabbix.conf /srv/salt/zabbix-server/
[root@server1 conf.d]# cd /srv/salt/zabbix-server/
[root@server1 zabbix-server]# ls
init.sls zabbix.conf zabbix_server.conf
[root@server1 zabbix-server]# vim zabbix.conf
21 php_value date.timezone Asia/Shanghai
[root@server1 zabbix-server]# vim init.sls ##添加行
zabbix-web:
file.managed:
- name: /etc/httpd/conf.d/zabbix.conf
- source: salt://zabbix-server/zabbix.conf
service.running:
- name: httpd
- enable: true
- watch:
- file: zabbix-web
[root@server1 zabbix-server]# salt server2 state.sls zabbix-server
在server2上部署zabbix
vim init.sls
zabbix-server:
pkgrepo.managed:
- name: zabbix
- humanname: zabbix 4.0
- baseurl: http://172.25.15.250/zabbix/4.0
- 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/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/zabbix.conf
service.running:
- name: httpd
- enable: true
- watch:
- file: zabbix-web
在server2上部署mysql
vim /srv/salt/mysql/init.sls
mysql-install:
pkg.installed:
- pkgs:
- mariadb-server
- MySQL-python
file.managed:
- name: /etc/my.cnf
- source: salt://mysql/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: localhost
- password: "westos"
mysql_grants.present:
- grant: all privileges
- database: zabbix.*
- user: zabbix
- host: '%'
file.managed:
- name: /mnt/create.sql
- source: salt://mysql/create.sql
cmd.run:
- name: mysql zabbix < /mnt/create.sql && touch /mnt/zabbix.lock
- creates: /mnt/zabbix.lock