Saltstack (十) ---使用saltstack 远程部署 zabbix-server

Rhel7.5下 zabbix 4.4 的安装可以参考:https://blog.csdn.net/qq_35887546/article/details/104863668#t6

首先准备zabbix-server的安装包及依赖:

[root@server1 zabbix]# ls 4.4/
apache-tomcat-8.5.24.tar.gz                  php-pdo-5.4.16-46.el7.x86_64.rpm
fping-3.10-1.el7.x86_64.rpm                  php-xml-5.4.16-46.el7.x86_64.rpm
jdk-8u121-linux-x64.rpm                      simkai.ttf
oneitsm_zabbix_release-1.2.0.tar.gz          zabbix-agent-4.4.1-1.el7.x86_64.rpm
percona-zabbix-templates-1.1.8-1.noarch.rpm  zabbix-get-4.4.1-1.el7.x86_64.rpm
php-5.4.16-46.el7.x86_64.rpm                 zabbix-java-gateway-4.4.1-1.el7.x86_64.rpm
php-bcmath-5.4.16-46.el7.x86_64.rpm          zabbix-proxy-mysql-4.4.1-1.el7.x86_64.rpm
php-cli-5.4.16-46.el7.x86_64.rpm             zabbix-sender-4.4.1-1.el7.x86_64.rpm
php-common-5.4.16-46.el7.x86_64.rpm          zabbix-server-mysql-4.4.1-1.el7.x86_64.rpm
php-gd-5.4.16-46.el7.x86_64.rpm              zabbix-web-4.4.1-1.el7.noarch.rpm
php-ldap-5.4.16-46.el7.x86_64.rpm            zabbix-web-mysql-4.4.1-1.el7.noarch.rpm
php-mbstring-5.4.16-46.el7.x86_64.rpm        zbx_percona_mysql_template_20200312_191902.xml
php-mysql-5.4.16-46.el7.x86_64.rpm           zbx_percona_mysql_template.xml
[root@server1 zabbix]# pwd
/srv/salt/zabbix

准备数据库sql语句(创建zabbix数据库,创建zabbix用户及授权):

[root@server1 zabbix]# cat zabbix.sql 
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@'localhost' identified by 'redhat';
grant all privileges on zabbix.* to zabbix@'%' identified by 'redhat';

准备zabbix-web配置文件:


[root@server1 zabbix]# cat zabbix.conf 

#
# Zabbix monitoring system php web frontend
#

Alias /zabbix /usr/share/zabbix

<Directory "/usr/share/zabbix">
    Options FollowSymLinks
    AllowOverride None
    Require all granted

    <IfModule mod_php5.c>
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value max_input_vars 10000
        php_value always_populate_raw_post_data -1
        php_value date.timezone Asia/Shanghai
    </IfModule>
</Directory>

<Directory "/usr/share/zabbix/conf">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/app">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/include">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/local">
    Require all denied
</Directory>

准备zabbix-server配置文件(可以复制更改):

[root@server1 zabbix]# cat zabbix_server.conf
只需更改124行:
 124 DBPassword=redhat		#zabbix用户的密码

接下来最重要的sls文件:

[root@server1 zabbix]# cat init.sls 
zabbix:
  pkg.installed:
    - pkgs:
      - mariadb-server

  file.managed:
    - name: ~/zabbix.sql
    - source: salt://zabbix/zabbix.sql

  cmd.run:
    - name: cd /root/4.4/ && yum install zabbix-server-mysql-4.4.1-1.el7.x86_64.rpm zabbix-web-mysql-4.4.1-1.el7.noarch.rpm zabbix-web-4.4.1-1.el7.noarch.rpm php-* fping-3.10-1.el7.x86_64.rpm -y &> /dev/null && systemctl start mariadb && cd /root/ && mysql < zabbix.sql && zcat /usr/share/doc/zabbix-server-mysql-4.4.1/create.sql.gz | mysql -uzabbix -predhat zabbix
    - require:
      - file: ~/zabbix.sql 

  service.running:
    - name: 
      - zabbix-server
    - enable: true
    - reload: true
    - require:
      - file: /etc/zabbix/zabbix_server.conf

httpd:
  service.running:
    - enable: true
    - reload: true
    - require:
      - file: /etc/httpd/conf.d/zabbix.conf

/etc/zabbix/zabbix_server.conf:
  file.managed:
    - source: salt://zabbix/zabbix_server.conf
    - require:
      - file: /etc/httpd/conf.d/zabbix.conf

/etc/httpd/conf.d/zabbix.conf:
  file.managed:
    - source: salt://zabbix/zabbix.conf

首先将安装包与依赖性推送过去:

[root@server1 zabbix]# salt server5 cp.get_dir salt://zabbix/4.4/ ~

最后直接推送即可:

[root@server1 zabbix]# salt server5 state.sls zabbix

推送成功后在浏览器访问:http://172.25.63.5/zabbix

在这里插入图片描述可以看出部署成功,接下来的操作与参考博客相同,最后结果:

在这里插入图片描述

你可能感兴趣的:(企业实战,zabbix,运维,linux,服务器,saltstack)