參考網站:
https://www.cnblogs.com/xiewenming/p/7732144.html
https://www.cnblogs.com/clsn/p/7885990.html Zabbix 3.0 從入門到精通(zabbix使用詳解)
https://yq.aliyun.com/articles/43308
https://yq.aliyun.com/articles/94733
https://www.zabbix.com/documentation/3.0/manual/installation 附 官方英文版文檔
說明:根據zabbix server3.0官方要求,目前zabbix server3.0在centos6 OS上不能進行yum安裝。如果一定要在centos6 OS上進行安裝zabbix server3.0的話,強烈建議通過源碼方式進行編譯安裝,同時還需要注意PHP的版本。考慮到這些因素,所以在此我們是在centos7 OS上進行yum安裝zabbix server3.0。
在centos7上安裝zabbix server3.0之前,我們首先搭建zabbix所需要的lamp環境。
准備一台虛擬機Centos7 172.16.160.94
yum update -y yum repolist 列出yum倉庫 yum clean all 清理yum 緩存 yum makecache 緩存yum倉庫。
一,關閉selinux和iptables
[root@linux-node2 ~]# systemctl stop firewalld.service 永久關閉selinux防火牆 [root@zabbix zabbix]# vi /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=enforcing SELINUX=disabled # 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@linux-node2 ~]# setenforce 0 setenforce: SELinux is disabled 查看是否關閉 [root@zabbix zabbix]# getenforce Permissive
二,安裝Zabbix rpm包倉庫
#安裝zabbix源、aliyun YUM源 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
或以下命令:
wget -P /etc/yum.repos.d http://mirrors.aliyun.com/repo/Centos-7.repo
三,安裝zabbix-server-mysql和zabbix-web-mysql
[root@linux-node2 ~]# yum install -y zabbix-server-mysql zabbix-web-mysql
四,安裝並且啟動mariadb
現在開始安裝lamp環境,使用如下命令:
yum -y install mariadb mariadb-server php php-mysql httpd
lamp安裝完畢后,我們現在來配置mysql數據庫。
設置開機自啟動mysql,並啟動mysql,使用如下命令:
systemctl enable mariadb
systemctl start mariadb
初始化mysql數據庫,並配置root用戶密碼。使用如下命令:
mysql_secure_installation
我們直接敲回車鍵即可。因為centos7上mysql的默認root用戶密碼為空。
五,創建zabbix數據庫,創建zabbix賬號
mysql初始化完畢后,我們現在來創建zabbix數據庫及其用戶,使用如下命令:
[root@linux-node2 ~]# mysql -uroot -p ... mysql> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) mysql> grant all privileges on zabbix.* to 'root'@'localhost' identified by 'zabbix'; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'zabbix'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
六,導入默認的zabbix數據庫信息
[root@linux-node2 zabbix-server-mysql-3.0.12]# zcat /usr/share/doc/zabbix-server-mysql-3.0.19/create.sql.gz | mysql zabbix -uzabbix -pzabbix
七,修改zabbix_server.conf的配置文件
[root@linux-node2 ~]# grep ^DB /etc/zabbix/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix
或:
#配置zabbixserver連接mysql sed -i.ori '115a DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
八,修改配置文件/etc/httpd/conf.d/zabbix.conf,時區改成 Asia/Shanghai
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 always_populate_raw_post_data -1 php_value date.timezone Asia/Shanghai
或:
#添加時區 sed -i.ori '18a php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
九,啟動apache/zabbix-server服務並設置為開機啟動
解決中文亂碼 yum -y install wqy-microhei-fonts cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
[root@linux-node2 ~]# systemctl start httpd [root@linux-node2 ~]# systemctl enable httpd [root@linux-node2 ~]# netstat -an |grep 80 tcp 0 0 192.168.56.11:80 0.0.0.0:* LISTEN [root@linux-node2 ~]# systemctl start zabbix-server [root@linux-node2 ~]# systemctl enable zabbix-server
或:
#寫入開機自啟動 chmod +x /etc/rc.d/rc.local cat >>/etc/rc.d/rc.local<<EOF systemctl start mariadb.service systemctl start httpd systemctl start zabbix-server EOF
#輸出信息 echo "瀏覽器訪問 http://`hostname -I|awk '{print $1}'`/zabbix"
查看zabbix-server日志
[root@linux-node1 ~]# tailf /var/log/zabbix/zabbix_server.log
zabbix-server的web目錄
[root@linux-node1 zabbix]# ls /usr/share/zabbix
十,訪問網站,例如:http://本機IP/zabbix,如下圖所示:
十一,選擇下一步,Check of pre-requisites,如圖所示:
十二,選擇下一步,配置zabbix server detail,如下圖所示:
十三,選擇下一步,配置zabbix server detail,如下圖所示:
十四:點擊下一步,便完成安裝,安裝完成的界面如下圖所示:
十五,安裝完成,如下圖所示:
十六:Zabbix·server的默認賬號Admin 密碼zabbix,如圖所示:
十七,默認登陸首頁,如下圖所示:
十八,移除或改名web目錄下面的setup.php文件
[root@linux-node2 zabbix]# pwd /usr/share/zabbix [root@linux-node2 zabbix]# mv setup.php setup.php.bak
十九,更改web登陸的Admin默認密碼
二十,設置新的密碼,這里也可以設置界面的主題、語言和登陸后顯示的默認界面等
至此安裝部分結束
二十一,安裝zabbix客戶端
yum install zabbix-agent -y sed -i.ori 's#Server=127.0.0.1#Server=172.16.160.94#' /etc/zabbix/zabbix_agentd.conf systemctl start zabbix-agent.service
二十二,服務端安裝zabbix-get檢測工具
[root@zabbix zabbix]# yum install zabbix-get -y
二十二,在服務端進行測試
#注意:只能在服務端進行測試 [root@zabbix zabbix]# zabbix_get -s 172.16.160.94 -p 10050 -k "system.cpu.load[all,avg1]" 0.030000 [root@zabbix zabbix]#
[root@zabbix tmp]# zabbix_get -s 172.16.160.35 -p 10050 -k "system.uname" Linux amoyzhu 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 [root@zabbix tmp]#