1. 程式人生 > >CentOS6原始碼安裝zabbix伺服器

CentOS6原始碼安裝zabbix伺服器

 

1、下載安裝包並解壓

2、預環境搭建

3、建立zabbix使用者,編譯安裝zabbix

4、配置mysql

5、配置zabbix-server

6、配置apache和php

7、新增開機自啟動

 1 yum install wget -y
 2 wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
 3 tar -zxf zabbix-4.0.3.tar.gz 
 4 cd zabbix-4.0.3
 5 
 6
yum -y install httpd mysql-server 7 rpm -i https://mirror.webtatic.com/yum/el6/latest.rpm 8 yum -y install php55w php55w-mysql php55w-cli php55w-xml php55w-gd php55w-common php55w-bcmath php55w-pdo php55w-mbstring 9 yum -y install gcc mysql-devel libxml2-devel net-snmp-devel libevent-devel libcurl-devel pcre-devel
10 11 useradd zabbix -s /sbin/nologin -M -u 200 12 ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 13 make install 14 15 /etc/init.d/mysqld start 16 mysql 17 create database zabbix4 character set utf8; 18 grant all on zabbix4.* to 'zbxuser'@'10.0.0.%
' identified by 'zbxpass'; 19 grant all on zabbix4.* to 'zbxuser'@'localhost' identified by 'zbxpass'; 20 flush privileges; 21 quit 22 mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/schema.sql 23 mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/images.sql 24 mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/data.sql 25 26 sed "s/.*DBHost=.*/DBHost=localhost/g" /usr/local/etc/zabbix_server.conf -i 27 sed "s/^DBName=.*/DBName=zabbix4/g" /usr/local/etc/zabbix_server.conf -i 28 sed "s/^DBUser=.*/DBUser=zbxuser/g" /usr/local/etc/zabbix_server.conf -i 29 sed "s/.*DBPassword=.*/DBPassword=zbxpass/g" /usr/local/etc/zabbix_server.conf -i 30 zabbix_server 31 32 \cp -r ~/zabbix-4.0.3/frontends/php /var/www/html/zabbix 33 \cp /etc/php.ini{,.bak} 34 sed -i '/post_max_size =/ s/=.*M$/= 16M/g' /etc/php.ini 35 sed -i '/max_execution_time =/ s/=.*/= 300/g' /etc/php.ini 36 sed -i '/max_input_time =/ s/=.*/= 300/g' /etc/php.ini 37 sed -i '/date.timezone =/ adate.timezone = Asia/Shanghai' /etc/php.ini 38 chown -R apache. /var/www/html/zabbix/conf/ 39 /etc/init.d/httpd restart 40 zabbix_agentd 41 42 chkconfig httpd on 43 chkconfig mysqld on 44 echo "/usr/local/sbin/zabbix_server" >>/etc/rc.local 45 echo "/usr/local/sbin/zabbix_agentd" >>/etc/rc.local 46 netstat -lntp
zabbix4.0.3原始碼安裝指令碼

 

 

 

 

 

1、下載安裝包並解壓

    zabbix4.0.3原始碼包地址:https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz

# 安裝wget
yum install wget -y

# 下載zabbix原始碼包
wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz

# 解壓縮並切換到zabbix-4.0.3目錄下
tar -zxf zabbix-4.0.3.tar.gz 
cd zabbix-4.0.3

 

2、預環境搭建

# 安裝lamp環境(3.x以上版本的zabbix需要5.4以上版本的php支援,CentOS6預設yum源php最高版本為php5.3)
# 安裝apache和mysql-server
yum -y install httpd mysql-server
# 安裝高版本php的yum源
rpm -i https://mirror.webtatic.com/yum/el6/latest.rpm
# 安裝php5.5
yum -y install php55w php55w-mysql php55w-cli php55w-xml php55w-gd php55w-common php55w-bcmath php55w-pdo php55w-mbstring

# 安裝所需的編譯工具或相關類庫
yum -y install gcc mysql-devel libxml2-devel net-snmp-devel libevent-devel libcurl-devel pcre-devel

 

3、建立zabbix使用者,編譯安裝zabbix

# 建立zabbix使用者用以啟動相關程序
useradd zabbix -s /sbin/nologin -M -u 200

# 配置zabbix需要安裝的功能
./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

# 安裝
make install

 

4、配置mysql

# 啟動mysqld服務
/etc/init.d/mysqld start

# 進入資料庫
mysql
# 建立zabbix4資料庫
create database zabbix4 character set utf8;
# 授權
grant all on zabbix4.* to 'zbxuser'@'10.0.0.%' identified by 'zbxpass';
grant all on zabbix4.* to 'zbxuser'@'localhost' identified by 'zbxpass';
# 更新配置使其實時生效
flush privileges;
# 檢視資料庫是否建立成功
show databases;
# 退出
quit

# 將zabbix的相關表匯入到zabbix4資料庫中
mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/schema.sql
mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/images.sql
mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/data.sql
# 驗證
mysql zabbix4
show tables;
quit


5、配置zabbix-server

# 配置DBHost
sed "s/.*DBHost=.*/DBHost=localhost/g" /usr/local/etc/zabbix_server.conf -i

# 配置DBName
sed "s/^DBName=.*/DBName=zabbix4/g" /usr/local/etc/zabbix_server.conf -i

# 配置DBUser
sed "s/^DBUser=.*/DBUser=zbxuser/g" /usr/local/etc/zabbix_server.conf -i

# 配置DBPassword
sed "s/.*DBPassword=.*/DBPassword=zbxpass/g" /usr/local/etc/zabbix_server.conf -i

# 檢視配置更改情況
cat /usr/local/etc/zabbix_server.conf |grep -E "DBHost=|DBName=|DBUser=|DBPassword="

# 啟動zabbix_server服務
zabbix_server

# 檢視zabbix_server是否啟動成功
netstat -lntp

 

6、配置apache和php

# 將前端檔案拷貝到Apache響應目錄下
\cp -r ~/zabbix-4.0.3/frontends/php /var/www/html/zabbix

# 配置php.ini
\cp /etc/php.ini{,.bak}
sed -i '/post_max_size =/ s/=.*M$/= 16M/g' /etc/php.ini
sed -i '/max_execution_time =/ s/=.*/= 300/g' /etc/php.ini
sed -i '/max_input_time =/ s/=.*/= 300/g' /etc/php.ini
sed -i '/date.timezone =/ adate.timezone = Asia/Shanghai' /etc/php.ini
cat /etc/php.ini |grep -E "post_max_size =|max_execution_time =|max_input_time =|date.timezone ="

# 授權
chown -R apache. /var/www/html/zabbix/conf/
ls -ld /var/www/html/zabbix/conf/

# 啟動httpd
/etc/init.d/httpd restart

# 啟動zabbix_agentd
zabbix_agentd

# 檢視服務啟動埠監聽情況
netstat -lntp

 

7、新增開機自啟動

chkconfig httpd on
chkconfig mysqld on
echo "/usr/local/sbin/zabbix_server" >>/etc/rc.local
echo "/usr/local/sbin/zabbix_agentd" >>/etc/rc.local