一.配置環境
1.1 Linux環境說明
zabbix 安裝要求 https://www.zabbix.com/documentation/4.0/zh/manual/installation/requirements [root@localhost bw]# cat /etc/redhat-release 查看系統版本信息 CentOS Linux release 7.4.1708 (Core) [root@localhost bw]# systemctl stop firewalld.service 關閉防火牆 [root@localhost bw]# systemctl disable firewalld.service 開機禁止啟動防火牆 [root@localhost bw]# vim /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled #永久關閉selinux # SELINUXTYPE= can take one of three two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted [root@localhost bw]#setenforce 0 臨時關閉 [root@localhost bw]#getenforce 結果為Disabled 為關閉 檢查selinux是否關閉
1.2 搭建LAMP環境
Zabbix是建立在LAMP或者LNMP環境之上,在此為了方便就使用yum安裝LAMP環境。
# 建立倉庫 [root@localhost bw]#yum -y install epel-release [root@localhost bw]#yum -y install createrepo --downloadonly --downloaddir=/home/bw/repo [root@localhost bw]# cd repo [root@localhost repo]#yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash --downloadonly --downloaddir=/home/bw/repo [root@localhost repo]# yum localinstall -y ./* 安裝后檢查應用版本 [root@localhost repo]# rpm -qa httpd php mariadb 安裝后檢查應用版本 httpd-2.4.6-89.el7.centos.x86_64 mariadb-5.5.60-1.el7_5.x86_64 php-5.4.16-46.el7.x86_64 # 編輯httpd [root@localhost repo]# vim /etc/httpd/conf/httpd.conf 95 ServerName www.aihuidi.com:80 修改主機名,URL 164 DirectoryIndex index.html index.php 修改首頁文件格式 # 編輯配置PHP,配置中國時區 [root@localhost repo]# vim /etc/php.ini 878 date.timezone = PRC # 啟動mysqld [root@localhost repo]# systemctl start mariadb 啟動數據庫 [root@localhost repo]# systemctl enable mariadb 加入開機自啟動 Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@localhost repo]# systemctl status mariadb 查看運行狀態 ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2019-06-13 00:31:21 CST; 11s ago Main PID: 2490 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─2490 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─2653 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/ma... Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: MySQL manual for more instructions. Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: Please report any problems at http://mariadb.org/jira Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: The latest information about MariaDB is available at http://mariadb.org/. Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: You can find additional information about the MySQL part at: Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: http://dev.mysql.com Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: Consider joining MariaDB's strong and vibrant community: Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: https://mariadb.org/get-involved/ Jun 13 00:31:19 node2 mysqld_safe[2490]: 190613 00:31:19 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. Jun 13 00:31:19 node2 mysqld_safe[2490]: 190613 00:31:19 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql Jun 13 00:31:21 node2 systemd[1]: Started MariaDB database server. [root@localhost repo]# netstat -lntup|grep mysqld 查看服務端口是否存在 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2653/mysqld 6370/mysqld # 初始化數據庫,並設置root用戶密碼 [root@localhost repo]# mysqladmin -u root password 123456 設置數據庫密碼 [root@localhost repo]# mysql -uroot -p 登錄數據庫 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin; #創建zabbix數據庫 Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; #刷新權限 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> select user,host from mysql.user; +--------+-----------+ | user | host | +--------+-----------+ | zabbix | % | | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | node2 | | root | node2 | +--------+-----------+ 7 rows in set (0.00 sec) MariaDB [(none)]> drop user ''@localhost; # 刪除空用戶 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> select user,host from mysql.user; +--------+-----------+ | user | host | +--------+-----------+ | zabbix | % | | root | 127.0.0.1 | | root | ::1 | | root | localhost | | | node2 | | root | node2 | +--------+-----------+ 6 rows in set (0.00 sec) MariaDB [(none)]> quit; Bye
二.安裝zabbix
安裝依賴包+組件
[root@localhost repo]# yum -y install net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel libevent-devel.x86_64 javacc.noarch javacc-javadoc.noarch javacc-maven-plugin.noarch javacc* --downloadonly --downloaddir=/home/bw/repo [root@localhost repo]# yum install php-bcmath php-mbstring -y --downloadonly --downloaddir=/home/bw/repo 安裝php支持zabbix組件 [root@localhost repo]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm 安裝zabbix yum源 ,本地下載,上傳到虛擬機上 [root@localhost repo]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y --downloadonly --downloaddir=/home/bw/repo 安裝zabbix組件 #報錯的話添加yum源 cat <<EOF > /etc/yum.repos.d/zabbix.repo [zabbix] name=Zabbix Official Repository - \$basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-non-supported] name=Zabbix Official Repository non-supported - \$basearch baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1 EOF # 添加密鑰 curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \ -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX \ -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
yum localinstall -y ./* # 本地安裝
安裝zabbix agent篇(centos7)
[root@localhost repo]# wget http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.9-3.el7.x86_64.rpm [root@localhost repo]# yum localinstall -y ./* [root@localhost repo]# hostname
xxxxx [root@localhost repo]# firewall-cmd --state
not running [root@localhost repo]# vi /etc/zabbix/zabbix_agentd.conf Server=xx.xx.xx.xx #zabbix-server地址 ServerActive=xx.xx.xx.xx #zabbix-server地址 Hostname=agent1 #這台安裝zabbix-agent的主機名,可以通過hostname命令查看主機名 [root@localhost repo]# systemctl start zabbix-agent.service [root@localhost repo]]# systemctl enable zabbix-agent.service Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service. [root@localhost repo]# systemctl status zabbix-agent.service [root@localhost repo]# cat /var/log/zabbix/zabbix_agentd.log
導入初始架構和數據,系統將提示您輸入新創建的密碼
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix Enter password: #導入數據到數據庫zabbix中(最后一個zabbix是數據庫zabbix),且因為用戶zabbix是%(任意主機),密碼是用戶zabbix登陸密碼zabbix
配置zabbix-server
[root@localhost repo]# vim /etc/zabbix/zabbix_server.conf 配置數據庫密碼 38:LogFile=/var/log/zabbix/zabbix_server.log 49:LogFileSize=0 72:PidFile=/var/run/zabbix/zabbix_server.pid 82:SocketDir=/var/run/zabbix 100:DBName=zabbix 116:DBUser=zabbix 124:DBPassword=123456 把注釋打開寫zabbix庫的密碼 356:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log 473:Timeout=4 516:AlertScriptsPath=/usr/lib/zabbix/alertscripts 527:ExternalScripts=/usr/lib/zabbix/externalscripts 563:LogSlowQueries=3000 [root@localhost repo]# vim /etc/httpd/conf.d/zabbix.conf 修改時區 php_value date.timezone Asia/Shanghai [root@localhost repo]# systemctl enable zabbix-server 啟動zabbix服務並加入開機自啟動 Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service. [root@localhost repo]# systemctl start zabbix-server [root@localhost repo]# systemctl start httpd 啟動httpd服務並加入開機自啟動 [root@localhost repo]# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@localhost repo]#
google 瀏覽器訪問 http://ip/zabbix即可
zabbix離線包下載
# 鏈接:https://pan.baidu.com/s/1texfmbV-Y97gbGDamL_Ggg
# 提取碼:hmir 下載離線包以后直接解壓,然后切換到解壓的目錄下, 執行 yum localinstall -y ./* 即可完成安裝,然后按照上面的步驟配置即可。
參考鏈接1:https://blog.csdn.net/weixin_43822878/article/details/91569016
參考鏈接2: https://blog.csdn.net/GongMeiyan/article/details/104079380
