Zabbix安装部署

修改镜像源为默认镜像源

  1. [root@server2 ~]#cd /etc/yum.repos.d/
  2. [root@server2 ~]#cp CentOS-Base.repo_bak CentOS-Base.repo
  3. [root@server2 ~]#yum clean all
  4. [root@server2 ~]#yum makecache
  5. [root@server2 ~]#yum -y update

node1服务端

  • 服务组件:Zabbix_Server & Zabbix_web & Mysql
  • Linux我们也用的Centos7.因为免费好用.我们可以先改一下yum源到阿里云上面.这样安装速度快一点,访问国外的yum实在是太慢了.
  1. [root@server2 ~]# yum install -y wget
  2. [root@server2 ~]#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
  3. [root@server2 ~]#ls /etc/yum.repos.d/
  4. [root@server2 ~]#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  5. [root@server2 ~]#yum makecache
  6. [root@server2 ~]# yum -y update
  7. [root@server2 ~]#cat /etc/yum.repos.d/CentOS-Base.repo
  • 安装zabbix
  1. [root@server2 ~]# wget https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
  2. [root@server2 ~]# rpm -ivh zabbix-release-4.0-2.el7.noarch.rpm
  • 修改相关源配置文件
  1. [root@server2 ~]# vi /etc/yum.repos.d/zabbix.repo
  2. [zabbix]
  3. name=Zabbix Official Repository - $basearch
  4. baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/$basearch/
  5. enabled=1
  6. gpgcheck=1
  7. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  8. [zabbix-debuginfo]
  9. name=Zabbix Official Repository debuginfo - $basearch
  10. baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/$basearch/debuginfo/
  11. enabled=0
  12. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  13. gpgcheck=1
  14. [zabbix-non-supported]
  15. name=Zabbix Official Repository non-supported - $basearch
  16. baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/
  17. enabled=1
  18. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
  19. gpgcheck=1
  • 安装组件
  1. [root@server2 ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
  • 安装数据库
  1. ####因为我们一开始修改了镜像源,直接下载是会下载不成功的,所以我们要在目录下创建一个mariadb的镜像文件,并进行配置(这里我们选择中科大镜像)
  2. [root@server2 ~]# vi /etc/yum.repos.d/mariadb.repo
  3. [mariadb-main]
  4. name = MariaDB Server
  5. #baseurl = https://downloads.mariadb.com/MariaDB/mariadb-10.4/yum/rhel/$releasever/$basearch
  6. baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64
  7. #gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
  8. gpgkey = https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
  9. gpgcheck = 1
  10. enabled = 1
  11. [root@server2 ~]# yum install mariadbserver y
  12. #####国外镜像源
  13. [mariadb]
  14. name = MariaDB
  15. baseurl = http://yum.mariadb.org/10.1/centos7-amd64
  16. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  17. gpgcheck=1
  • 数据库启动和设置开机自启动
  1. [root@server2 ~]# systemctl start mariadb.service
  2. [root@server2 ~]# systemctl enable mariadb.service
  • 数据库安全初始化
  1. [root@server2 ~]# mysql_secure_installation
  2. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  3. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  4. In order to log into MariaDB to secure it, we'll need the current
  5. password for the root user. If you've just installed MariaDB, and
  6. haven't set the root password yet, you should just press enter here.
  7. Enter current password for root (enter for none):
  8. 。。。。。。
  9. Remove anonymous users? [Y/n] y
  10. 。。。。。
  11. Disallow root login remotely? [Y/n] y
  12. 。。。。。
  13. Remove test database and access to it? [Y/n] y
  14. 。。。。。
  15. Reload privilege tables now? [Y/n] y
  16. 。。。。。
  17. Thanks for using MariaDB!
  • 创建zabbix相关数据库
  1. MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
  2. Query OK, 1 row affected (0.001 sec)
  3. MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by '123456';
  4. Query OK, 0 rows affected (0.001 sec
  • 导入zabbix表结构和初始数据
  1. root@server2 ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123456 zabbix
  • 配置zabbix-server连接数据库
  1. [root@server2 ~]# cat /etc/zabbix/zabbix_server.conf | grep -Ev "^$|^#"
  2. LogFile=/var/log/zabbix/zabbix_server.log
  3. LogFileSize=0
  4. PidFile=/var/run/zabbix/zabbix_server.pid
  5. SocketDir=/var/run/zabbix
  6. DBHost=localhost
  7. DBName=zabbix
  8. DBUser=zabbix
  9. DBPassword=123456
  10. SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
  11. Timeout=4
  12. AlertScriptsPath=/usr/lib/zabbix/alertscripts
  13. ExternalScripts=/usr/lib/zabbix/externalscripts
  14. LogSlowQueries=3000
  15. [root@server2 ~]# systemctl start zabbix-server
  16. [root@server2 ~]# systemctl enable zabbix-server
  • 关闭防火墙等,然后Windows访问zabbix
  1. [root@server2 ~]# setenforce 0
  2. [root@server2 ~]# systemctl stop firewalld
  • 这时候我们需要修改时区
  1. [root@server2 ~]# cat /etc/httpd/conf.d/zabbix.conf
  2. <IfModule mod_php5.c>
  3. php_value max_execution_time 300
  4. php_value memory_limit 128M
  5. php_value post_max_size 16M
  6. php_value upload_max_filesize 2M
  7. php_value max_input_time 300
  8. php_value max_input_vars 10000
  9. php_value always_populate_raw_post_data -1
  10. php_value date.timezone Asia/Shanghai
  11. </IfModule>
  12. [root@server2 ~]# systemctl restart httpd