zabbix的安裝配置

lusklusklusk發表於2018-08-31

ZABBIX服務端安裝

zabbix伺服器端需要LAMP環境,即linux、appache、mysql、php

linux:CentOS release 6.5

appache:2.2.15

mysql:5.6

php:5.6.13

zabbix:3.0.3



1、安裝appache

CentOS6預設安裝了appache,不需要重新安裝

[root@oatest ~]# httpd -v

Server version: Apache/2.2.15 (Unix)

Server built:   Oct 19 2017 16:43:38

[root@oatest ~]# apachectl -v

Server version: Apache/2.2.15 (Unix)

Server built:   Oct 19 2017 16:43:38



2.安裝PHP

Zabbix 3.0對PHP的要求最低為5.4,而CentOS6預設為5.3.3,完全不滿足要求,故需要利用第三方源,將PHP升級到5.6,下載地址

[root@oatest ~]# cat /etc/issue

CentOS release 6.5 (Final)

[root@oatest ~]# rpm -qa|grep -i php

php-common-5.3.3-49.el6.x86_64

php-cli-5.3.3-49.el6.x86_64

php-5.3.3-49.el6.x86_64

[root@oatest ~]# rpm -e php-5.3.3-49.el6.x86_64

[root@oatest ~]# rpm -e php-cli-5.3.3-49.el6.x86_64

[root@oatest ~]# rpm -e php-common-5.3.3-49.el6.x86_64

[root@oatest ~]# cd /u01/software/

[root@oatest software]# tar -zxvf php-5.6.13.tar.gz

[root@oatest software]# cd php-5.6.13

[root@oatest php-5.6.13]# ./configure --prefix=/usr/local/php  --with-apxs2=/usr/local/apache/bin/apxs  --with-mysqli

--報錯/usr/local/apache/bin/apxs: No such file or directoryconfigure

[root@oatest php-5.6.13]# find / -name apxs

--沒有結果

[root@oatest php-5.6.13]# yum install -y httpd-devel

[root@oatest php-5.6.13]# find / -name apxs

--顯示結果/usr/sbin/apxs

[root@oatest php-5.6.13]# ./configure --prefix=/usr/local/php  --with-apxs2=/usr/sbin/apxs  --with-mysqli

[root@oatest php-5.6.13]# make

--提示Don't forget to run 'make test'

--不需要執行這段make test

[root@oatest php-5.6.13]# make install

[root@oatest php-5.6.13]# php -version

[root@oatest php-5.6.13]# vi /etc/httpd/conf/httpd.conf

找到:

  AddType application/x-compress .Z

  AddType application/x-gzip .gz .tgz

在後面新增:

  AddType application/x-httpd-php .php #(使Apcche支援PHP)

  AddType application/x-httpd-php-source .php5 

[root@oatest php-5.6.13]# service httpd restart

--在/var/www/html/目錄下建立一個檔案index.php,內容如下

<?php

phpinfo();

?>

檢視appche是否可以正常顯示php的內容

可以看到php.ini的路徑,Configuration File (php.ini) Path /usr/local/php/lib


[root@oatest php-5.6.13]# cp php.ini-development  /usr/local/php/lib/php.ini

[root@oatest php-5.6.13]# vi /usr/local/php/lib/php.ini

新增如下

date.timezone = Asia/Shanghai

post_max_size = 32M

max_execution_time = 300

max_input_time = 300

always_populate_raw_post_data = -1



3.安裝MySQL

MySQL建議使用5.6版本,CentOS6預設為5.1,不建議使用

[root@oatest ~]# cat /etc/issue

CentOS release 6.5 (Final)

[root@oatest ~]# rpm -qa|grep -i mysql

mysql-libs-5.1.71-1.el6.x86_64

[root@oatest ~]# rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps

[root@oatest ~]# cd /u01/software/

[root@oatest software]# rpm -ivh MySQL-client-5.6.10-1.rhel5.x86_64.rpm MySQL-server-5.6.10-1.rhel5.x86_64.rpm MySQL-devel-5.6.10-1.el6.x86_64.rpm MySQL-shared-5.6.10-1.el6.x86_64.rpm MySQL-shared-compat-5.6.10-1.el6.x86_64.rpm

--必須安裝MySQL-devel,要不後面的zabbix安裝的configure中會報錯configure: error: MySQL library not found

--必須安裝MySQL-shared,要不後面的zabbix安裝的configure中會報錯configure: error: Not found mysqlclient library

[root@oatest software]# service mysql start

[root@oatest software]# cat /root/.mysql_secret

# The random password set for the root user at Tue Aug 28 18:14:24 2018 (local time): kmRkDSXX

[root@oatest software]# mysql -u root -p

Enter password:輸入上面的kmRkDSXX

mysql> SET PASSWORD = PASSWORD('123456');

mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;

mysql> GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbix';

mysql> flush privileges;



4.安裝Zabbix

zabbix下載地址%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz

[root@oatest ~]# cd /u01/software/

[root@oatest software]# useradd zabbix

[root@oatest software]# tar -zxvf zabbix-3.0.3.tar.gz

[root@oatest software]# cd zabbix-3.0.3

[root@oatest zabbix-3.0.3]# /usr/bin/mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql

[root@oatest zabbix-3.0.3]# /usr/bin/mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql

[root@oatest zabbix-3.0.3]# /usr/bin/mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql

[root@oatest zabbix-3.0.3]# ./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix/ --enable-server --enable-agent --with-net-snmp --with-libcurl --with-mysql --with-libxml2 --with-ldap

--出現報錯configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config

--出現報錯configure: error: Curl library not found

[root@oatest zabbix-3.0.3]# yum install net-snmp-devel

[root@oatest zabbix-3.0.3]# yum install curl-devel

[root@oatest zabbix-3.0.3]# ./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix/ --enable-server --enable-agent --with-net-snmp --with-libcurl --with-mysql --with-libxml2

[root@oatest zabbix-3.0.3]# make install



5、zabbix和appache配置

[root@oatest zabbix-3.0.3]# vi /etc/zabbix/zabbix_server.conf

修改

DBPassword=zabbix

ListenIP=127.0.0.1,192.168.30.173

--此處192.168.30.173為zabbix server ip


[root@oatest zabbix-3.0.3]# ln -s /usr/local/zabbix/sbin/* /usr/sbin/

[root@oatest zabbix-3.0.3]# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/

[root@oatest zabbix-3.0.3]# chmod +x /etc/init.d/zabbix_*

[root@oatest zabbix-3.0.3]# sed -i "s@BASEDIR=/usr/local@BASEDIR=/usr/local/zabbix@g" /etc/init.d/zabbix_server


[root@oatest zabbix-3.0.3]# vi /etc/httpd/conf/httpd.conf

ServerName 127.0.0.1

ServerName 192.168.30.173

DocumentRoot  "/var/www/html"


[root@oatest zabbix-3.0.3]# mkdir -p /var/www/html/zabbix

[root@oatest zabbix-3.0.3]# cp -r frontends/php/* /var/www/html/zabbix/

[root@oatest zabbix-3.0.3]# chown -R apache.apache /var/www/html/zabbix/

[root@oatest zabbix-3.0.3]# chkconfig zabbix_server on

[root@oatest zabbix-3.0.3]# service zabbix_server start

[root@oatest zabbix-3.0.3]# service httpd restart


編譯php如果 make clean後重新make和make install,都需要重新配置一下/usr/local/php/lib/php.ini



6、zabbix的WEB頁面配置

登入使用者/密碼Admin/zabbix


遇到錯誤會有提示,比如PHP bcmath extension missing (PHP configuration parameter --enable-bcmath)

解決方法,make clean後重新make和make install編譯php,加上引數--enable-bcmath


遇到如下錯誤的解決方法

先安裝jpeg和freetype再make clean後重新make和make install編譯php,加上引數--with-jpeg-dir --with-freetype-dir


PHP gd JPEG image support missing.

PHP gd FreeType support missing.

JPEG下載地址

FreeType下載地址


[root@oatest zabbix-3.0.3]# cd /u01/software/

[root@oatest software]# tar -zxvf jpegsrc.v9b.tar.gz

[root@oatest software]# cd jpeg-9b/

[root@oatest jpeg-9b]# mkdir /usr/local/freetype

[root@oatest jpeg-9b]#./configure --prefix=/usr/local/jpeg --enable-shared

[root@oatest jpeg-9b]# make

[root@oatest jpeg-9b]# make install


[root@oatest jpeg-9b]# cd /u01/software/

[root@oatest software]# tar -zxvf freetype-2.6.5.tar.gz

[root@oatest software]# cd freetype-2.6.5

[root@oatest freetype-2.6.5]# mkdir /usr/local/freetype

[root@oatest freetype-2.6.5]# ./configure --prefix=/usr/local/freetype/

[root@oatest freetype-2.6.5]# make

[root@oatest freetype-2.6.5]# make install


[root@oatest freetype-2.6.5]# cd /u01/software/php-5.6.13

[root@oatest php-5.6.13]# ./configure --prefix=/usr/local/php  --with-apxs2=/usr/sbin/apxs  --with-mysqli --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-jpeg-dir --with-freetype-dir

[root@oatest php-5.6.13]# make clean

--必須清除原來的編譯配置,重新編譯php

[root@oatest php-5.6.13]# make

[root@oatest php-5.6.13]# make install

[root@oatest php-5.6.13]# cp php.ini-development /usr/local/php/lib/php.ini

[root@oatest php-5.6.13]# vi /usr/local/php/lib/php.ini

新增如下

date.timezone = Asia/Shanghai

post_max_size = 32M

max_execution_time = 300

max_input_time = 300

always_populate_raw_post_data = -1


Configure DB connection如下報錯時

Error connecting to database: No such file or directory

ln -s /var/lib/mysql/mysql.sock /tmp/

vi /usr/local/php/lib/php.ini新增一行,如下:

mysqli.default_socket = /var/lib/mysql/mysql.sock


[root@oatest php-5.6.13]# service httpd restart






ZABBIX客戶端安裝

方法1:使用原始碼檔案,即需要configure

安裝客戶端的時候,軟體包和伺服器端是同一個,只是 configure 的配置引數不同而已

useradd zabbix

tar -zxvf zabbix-3.0.3.tar.gz

cd zabbix-3.0.3

./configure --prefix=/usr --sysconfdir=/etc/zabbix  --enable-agent

make

make install

mkdir /var/log/zabbix

chown zabbix.zabbix /var/log/zabbix

cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/

chmod 755 /etc/init.d/zabbix_agentd

sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#g"  /etc/init.d/zabbix_agentd


新增zabbix 到系統服務檔案

vi /etc/services 

zabbix-agent 10050/tcp #ZabbixAgent 

zabbix-agent 10050/udp #ZabbixAgent 

zabbix-trapper 10051/tcp #ZabbixTrapper 

zabbix-trapper 10051/udp #ZabbixTrapper


vi /etc/zabbix/zabbix_agentd.conf

修改Server、ServerActive和Hostname


service zabbix_agentd start


服務端執行如下,返回值即可

/usr/local/zabbix/bin/zabbix_get -s 客戶端IP -p 10050 -k "system.uptime"



方法2:直接使用二進位制檔案

1. tar -zxvf zabbix_agents_2.4.0.linux2_6.amd64.tar.gz

2. mkdir /etc/zabbix/

3. mv bin/zabbix_get /usr/bin/

4. mv bin/zabbix_sender /usr/bin/

5. mv sbin/zabbix_agent /usr/bin/

6. mv sbin/zabbix_agentd /usr/bin/

7. mv conf/zabbix_agentd.conf /etc/zabbix/

8. 修改zabbix_agentd.conf

Hostname=zabbix-client1 ###這裡的hostname要與客戶端的hostname一致,而且與監控主機中的名字一致!

ServerActive=192.168.254.153 ####zabbix server的ip

Server=192.168.254.153####zabbix server的ip

9. groupadd -r zabbix

useradd -g zabbix -s /sbin/nologin zabbix

10. zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf ####指定配置檔案啟動

11. ps –ef|grep zabbix

lsof -i:10050

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2213289/,如需轉載,請註明出處,否則將追究法律責任。

相關文章