Article directory
To be perfect...
The directory structure is as follows
[root@server1 srv]# pwd /srv [root@server1 srv]# ls pillar salt [root@server1 srv]# tree . . ├── pillar │ ├── top.sls │ └── zabbix.sls └── salt ├── mariadb │ ├── files │ │ └── create.sql.gz │ └── install.sls ├── repos │ └── zabbix.sls ├── top.sls ├── zabbix-agent │ ├── files │ │ └── zabbix_agentd.conf │ └── install.sls ├── zabbix-server │ ├── files │ │ └── zabbix_server.conf │ └── install.sls └── zabbix-web ├── files │ └── zabbix.conf └── install.sls 11 directories, 12 files
The contents and explanations of each document are as follows
The installation and configuration files of mariadb are as follows:
[root@server1 salt]# cd mariadb/ [root@server1 mariadb]# ls files install.sls [root@server1 mariadb]# cat install.sls db-install: pkg.installed: - pkgs: - mariadb - mariadb-server - MYSQL-python service.running: - name: mariadb-server cmd.run: - name: mysql -e "DELETE FROM mysql.user WHERE User='';" && "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');" && "DROP DATABASE IF EXISTS test;" && "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" && "FLUSH PRIVILEGES;" #Writing Initialization Script Based on mariadb - onlyif : mysql -e "show databases;" mysql_user.present: - name: root - password: westos db-configure: file.manaed: - name: /mnt/create.sql.gz - source: salt://mariadb/files/create.sql.gz mysql_database.present: - name: zabbix - character_set: utf8 - collate: utf8_bin - connection_user: root - connection_pass: westos mysql_user.present: - name: zabbix - host: localhost - password: westos - connection_user: root - connection_pass: westos mysql_grants.present: - grant: all privileges - database: zabbix.* - user: zabbix - connection_user: root - connection_pass: westos cmd.wait: - name: zcat /mnt/create.sql.gz | mysql -pwestos zabbix - watch: - mysql_database: db-configure
Note: mariadb initialization script view method:
[root@foundation11 ~]# which mysql_secure_installation /bin/mysql_secure_installation [root@foundation11 ~]# vim /bin/mysql_secure_installation
- The files directory is the database to be imported.
[root@server1 mariadb]# ls files install.sls [root@server1 mariadb]# ls files/ create.sql.gz
The configuration directory and files of yum source are as follows:
[root@server1 salt]# cd repos/ [root@server1 repos]# ls zabbix.sls [root@server1 repos]# cat zabbix.sls zabbix: pkgrepo.managed: - baseurl: http://172.25.11.250/zabbix/4.0 - gpgcheck: 0
The top.sls file is as follows:
[root@server1 salt]# cat top.sls base: 'server1': - mariadb.install - zabbix-server.install - zabbix-web.install 'server2': - zabbix-agent.install
The installation files of zabbix-agent are as follows:
[root@server1 salt]# cd zabbix-agent/ [root@server1 zabbix-agent]# ls files install.sls [root@server1 zabbix-agent]# cat install.sls include: - repos.zabbix agent-install: pkg.installed: - name: zabbix-agent file.managed: - name: /etc/zabbix/zabbix_agentd.conf - source: salt://zabbix-agent/files/zabbix_agentd.conf - template: jinja - context: zabbixserver: {{ pillar['ZABBIX-SERVER'] }} hostname: {{ grains['fqdn'] }} service.running: - name: zabbix-agent - watch: - file: agent-install
Modify 3 parts in the template file:
[root@server1 files]# vim zabbix_agentd.conf 98 Server= {{ zabbixserver }} 139 ServerActive={{ zabbixserver }} 150 Hostname={{ hostname }}
The installation files of zabbix-server are as follows:
[root@server1 salt]# cd zabbix-server/ [root@server1 zabbix-server]# ls files install.sls [root@server1 zabbix-server]# cat install.sls include: - repos.zabbix server-install: pkg.installed: - zabbix-server-mysql - zabbix-agent file.managed: - name: /etc/zabbix/zabbix_server.conf - source: salt://zabbix-server/files/zabbix_server.conf - template: jinja - context: dbpasswd: {{ pillar['DBPASSWD'] }} service.running: - name: zabbix-server - watch: - file: server-install zabbix-agent: service.running
Modification of template file 2:
[root@server1 zabbix-server]# cd files/ [root@server1 files]# ls zabbix_server.conf [root@server1 files]# vim zabbix_server.conf 124 DBPassword={{ dbpasswd }}
The web front-end interface zabbix-web is as follows:
[root@server1 salt]# cd zabbix-web/ [root@server1 zabbix-web]# ls files install.sls [root@server1 zabbix-web]# cat install.sls include: - repos.zabbix web-install: pkg.installed: - pkgs: - zabbix-web-mysql - zabbix-web - httpd - php - php-mysql file.managed: - name: /etc/httpd/conf.d/zabbix.conf - source: salt://zabbix-web/files/zabbix.conf service.running: - name: httpd - watch: - file: web-install
Template file modification time zone:
[root@server1 files]# ls zabbix.conf [root@server1 files]# vim zabbix.conf 20 php_value date.timezone Asia/Shanghai
Under pillar directory:
[root@server1 srv]# ls pillar salt [root@server1 srv]# cd pillar/ [root@server1 pillar]# ls top.sls zabbix.sls [root@server1 pillar]# cat top.sls base: '*': - zabbix [root@server1 pillar]# cat zabbix.sls {% if grains['fqdn'] == 'server1' %} DBPASSWD: westos {% else %} ZABBIX-SERVER: 172.25.11.1 {% endif %}
Advanced push:
[root@server1 pillar]# salt '*' state.highstate
After completion, browser input access.