ZABBIX搭建

ZABBIX搭建

搭建環境

Centos7。2

zabbix3。4

php7

nginx1。102

不想自己找嫌麻煩的可以私信我回復【zabbix】我這裡有打包好的包

第一部分:安裝MySQL

安裝

yum install mysql mysql-server

2。 安裝完成之後啟動並檢視MySQL狀態:

service mysqld start

service mysqld status

3 手動驗證MySQL安裝的版本:

mysql ——version

4。 使用新設定的密碼連線MySQL:

mysql -u root -p

第二部門 安裝Nginx

1。 首先下載Nginx的最新穩定版下載之後解壓壓縮包:

tar zxvf nginx-1。10。1。tar。gz

2。 進入解壓之後的Nginx目錄,執行configure

。/configure ——prefix=/usr/local/nginx ——with-http_ssl_module ——with-http_stub_status_module ——with-pcre

3。 編譯安裝

makemake install

4。 測試Nginx

/usr/local/nginx/sbin/nginx -t

第三部分 安裝PHP

1。 首先安裝開發軟體包:

yum -y groupinstall “Development Tools”

2。 下載PHP最新穩定版,解壓安裝包,

tar -zxvf php-5。6。25。tar。gz

3。 切換到PHP目錄,執行configure:

。/configure -prefix=/usr/local/php -with-config-file-path=/usr/local/php/etc -with-bz2 -with-curl -enable-ftp -enable-sockets -disable-ipv6 -with-gd -with-jpeg-dir=/usr/local -with-png-dir=/usr/local -with-freetype-dir=/usr/local -enable-gd-native-ttf -with-iconv-dir=/usr/local -enable-mbstring -enable-calendar -with-gettext -with-libxml-dir=/usr/local -with-zlib -with-pdo-mysql=mysqlnd -with-mysqli=mysqlnd -with-mysql=mysqlnd -enable-dom -enable-xml -enable-fpm -with-libdir=lib64 -enable-bcmath

4。

make make install

我用的機器記憶體1G比較小正常不會出現問題,如果報錯記憶體小——disable-fileinfo把這個引數加上就行

5。 複製安裝包中的php。ini-production到 /usr/local/php/etc/php。ini

cp php。ini-production /usr/local/php/etc/php。ini

cp /usr/local/php/etc/php-fpm。conf。default。conf php-fpm。conf

6。 測試PHP安裝是否成功。

/usr/local/php/sbin/php-fpm -t

7。 測試成功之後啟動PHP

cp /usr/local/src/php-5。3。27/sapi/fpm/init。d。php-fpm /etc/init。d/php-fpm

chmod 755 /etc/init。d/php-fpm

systemctl start php-fpm

8。 新增到開機啟動

chkconfig php-fpm on

9。 檢查是否啟動

ps aux |grep php-fpm

netstat -ant |grep 9000

第四部分 配置Nginx執行PHP

1。 修改Nginx配置檔案如下,先備份一下nginx配置檔案然後清空後直接把這段複製進去就行

vim /usr/local/nginx/conf/nginx。conf

user nobody nobody;

worker_processes 2;

error_log /usr/local/nginx/logs/nginx_error。log crit;

pid /usr/local/nginx/logs/nginx。pid;

worker_rlimit_nofile 51200;

events

{

use epoll;

worker_connections 6000;

}

http

{

include mime。types;

default_type application/octet-stream;

server_names_hash_bucket_size 3526;

server_names_hash_max_size 4096;

log_format combined_realip ‘$remote_addr $http_x_forwarded_for [$time_local]’

‘$host “$request_uri” $status’

‘“$http_referer” “$http_user_agent”’;

sendfile on;

tcp_nopush on;

keepalive_timeout 30;

client_header_timeout 3m;

client_body_timeout 3m;

send_timeout 3m;

connection_pool_size 256;

client_header_buffer_size 1k;

large_client_header_buffers 8 4k;

request_pool_size 4k;

output_buffers 4 32k;

postpone_output 1460;

client_max_body_size 10m;

client_body_buffer_size 256k;

client_body_temp_path /usr/local/nginx/client_body_temp;

proxy_temp_path /usr/local/nginx/proxy_temp;

fastcgi_temp_path /usr/local/nginx/fastcgi_temp;

fastcgi_intercept_errors on;

tcp_nodelay on; gzip on;

gzip_min_length 1k;

gzip_buffers 4 8k;

gzip_comp_level 5;

gzip_http_version 1。1;

gzip_types text/plain application/x-javascript text/css text/htm application/xml;

server

{

listen 80;

server_name localhost;

index index。html index。htm index。php;

root /usr/local/nginx/html;

location ~ \。php$ {

include fastcgi_params;

fastcgi_pass 127。0。0。1:9000;

fastcgi_index index。php;

fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;

}

}

}

2。 建立PHP測試網頁

vim /usr/local/nginx/html/test。php

<?php phpinfo();?>

3。 在瀏覽器中輸入localhost/test。php,測試php頁面

正常可以看到紫藍相間的php預設網頁

4。 配置PHP引數,Zabbix的硬體要求

vim /usr/local/php/etc/php。ini

max_execution_time = 300max_input_time = 300memory_limit = 128M

post_max_size = 16M

upload_max_filesize = 2Mdate。timezone = Asia/Shanghai

always_populate_raw_post_data = -1

5。 重啟PHP

systemctl restart php-fpm

第五部分 安裝Zabbix

1。 下載安裝zabbix的YUM源

rpm -ivh http://repo。zabbix。com/zabbix/3。4/rhel/7/x86_64/zabbix-release-3。4-1。el7。centos。noarch。rpm

2。 安裝Zabbix

yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-get zabbix-agent

3。 安裝之後進入MySQL資料庫,建立Zabbix資料庫

create database zabbix character set utf8 collate utf8_bin;grant all privileges on zabbix。* to ‘zabbix’@‘%’ identified by ‘zabbixpass’;

flush privileges;

4。 匯入Zabbix到資料庫

cd /usr/share/doc/zabbix-server-mysql-3。41/zcat create。sql。gz | mysql -u root -p zabbix

5。 配置zabbix使用者

groupadd zabbix

useradd -g zabbix -s /bin/false zabbix

6。 配置Zabbix伺服器端

vim /etc/zabbix/zabbix_server。conf

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbixpass

cd /usr/share/cp -r zabbix /usr/local/nginx/htmlchown -R zabbix:zabbix /etc/zabbixchown -R zabbix:zabbix /usr/share/zabbixchown -R zabbix:zabbix /usr/lib/zabbix

7。 Zabbix加入開機啟動並啟動

systemctl enable zabbix-server

systemctl start zabbix-server

完成後在網頁輸入http://ip/zabbix

按步驟設定即可

遇到的問題

問題,執行Zabbix時出現“

FastCGI sent in stderr: “PHP message: PHP Warning: require_once(/etc/zabbix/web/maintenance。inc。php): failed to open stream: Permission denied in /app/nginx/html/zabbix/include/classes/core/ZBase。php on line 292

PHP message: PHP Fatal error: require_once(): Failed opening required ‘/etc/zabbix/web/mainte

解決方法:

chmod -R 755 /etc/zabbix/web

重置zabbix密碼

進到資料庫, select * from zabbix。user\G;

mysql> use zabbix;

mysql> update users set passwd=’5fce1b3e34b520afeffb37ce08c7cd66‘ where userid=’1‘;

解釋一下5fce1b3e34b520afeffb37ce08c7cd66 zabbix密碼是用MD5值加密的,這串代表zabbix意思

也可以

echo -n 密碼 | openssl md5 用這個生成一個自己的密碼吧密碼位置換成自己想設定的密碼就行