LNMP+Zabbix部署文档
概述
基于centos6.5系统rpm包部署mysql5.7,yum部署的nginx和php,源码部署的zabbix
详细步骤
Nginx
[root@server01 ~]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel -y [root@server01 ~]# vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1 [root@server01 ~]# yum install nginx [root@server01 ~]# service nginx start
PHP
[root@server01 ~]# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@server01 ~]# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
[root@server01 ~]# yum install --enablerepo=remi --enablerepo=remi-php56 php php-mysql php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common
[root@server01 ~]# php --version
[root@server01 ~]# yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm
[root@server01 ~]# vi /etc/nginx/conf.d/default.conf
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
location ~ .php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@server01 ~]# /etc/init.d/php-fpm start
[root@server01 ~]# vi /usr/share/nginx/html/index.php
[root@server01 ~]# nginx -s reload
出现如下页面表示到此部署成功

zabbix
安装依赖软件
[root@server01 ~]# yum -y install libxml2-devel libevent unixODBC-devel net-snmp-devel libxml2-devel libcurl-devel libevent-devel OpenIPMI-devel
解压编译
[root@server01 ~]# tar -xf zabbix-3.4.15.tar.gz -C /usr/src/ [root@server01 ~]# cd /usr/src/zabbix-3.4.15/ [root@server01 ~]#./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-openipmi [root@server01 ~]# make && make install
创建用户并导入数据
[root@server01 ~]# mysql -uroot -pxx mysql> create database zabbix character set utf8 collate utf8_bin; mysql> grant all on *.* to 'zabbix'@'%' identified by 'zabbix'; mysql> use zabbix; mysql> source /usr/src/zabbix-3.4.15/database/mysql/schema.sql; mysql> source /usr/src/zabbix-3.4.15/database/mysql/images.sql; mysql> source /usr/src/zabbix-3.4.15/database/mysql/data.sql;
创建linux用户并修改配置
[root@server01 ~]# cd /usr/local/zabbix [root@server01 ~]# groupadd zabbix [root@server01 ~]# useradd -r -g zabbix zabbix [root@server01 ~]# mkdir logs [root@server01 ~]# chown -R zabbix:zabbix /usr/local/zabbix [root@server01 ~]# vi /usr/local/zabbix/etc/zabbix_server.conf LogFile=/usr/local/zabbix/logs/zabbix_server.log PidFile=/tmp/zabbix_server.pid DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix DBSocket=/tmp/mysql.sock
拷贝zabbix页面到nginx html目录
[root@server01 ~]# cd /usr/src/zabbix-3.4.15/frontends/php [root@server01 php]# mkdir /usr/share/nginx/html/zabbix [root@server01 php]# rsync -av ./* /usr/share/nginx/html/zabbix/ ... ... locale/zh_TW/LC_MESSAGES/ locale/zh_TW/LC_MESSAGES/frontend.mo locale/zh_TW/LC_MESSAGES/frontend.po styles/ styles/blue-theme.css styles/dark-theme.css sent 36925066 bytes received 16938 bytes 10554858.29 bytes/sec total size is 36860023 speedup is 1.00 [root@server01 php]# vim /etc/ld.so.conf /mysql/base/lib [root@server01 php]# chown zabbix.zabbix -R /usr/local/zabbix [root@server01 php]# ln -s /mysql/base/lib/libmysqlclient.so.20 /usr/lib/ [root@server01 php]# ldconfig
修改php配置文件参数,配置文件中;为注释符号有些配置可以直接改,有些配置需要打开注释
[root@server01 php]# vi /etc/php.ini post_max_size = 32M upload_max_filesize = 50M date.timezone=Asia/Shanghai max_execution_time = 300 max_input_time = 300 memory_limit = 256M always_populate_raw_post_data = -1
[root@server01 php]# /etc/init.d/php-fpm restart
检查一下
[root@server01 php]# cat /etc/php.ini |grep post_max_size [root@server01 php]# cat /etc/php.ini |grep upload_max_filesize [root@server01 php]# cat /etc/php.ini |grep date.timezone [root@server01 php]# cat /etc/php.ini |grep max_execution_time [root@server01 php]# cat /etc/php.ini |grep max_input_time [root@server01 php]# cat /etc/php.ini |grep memory_limit [root@server01 php]# cat /etc/php.ini |grep always_populate_raw_post_data
创建server启动脚本
[root@server01 php]# vi /etc/init.d/zabbix_server
#!/bin/sh
# Zabbix
# Copyright (C) 2001-2018 Zabbix SIA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Start/Stop the Zabbix server daemon.
# Place a startup script in /sbin/init.d, and link to it from /sbin/rc[023].d
SERVICE="Zabbix server"
DAEMON=/usr/local/zabbix/sbin/zabbix_server
PIDFILE=/tmp/zabbix_server.pid
case $1 in
'start')
if [ -x ${DAEMON} ]
then
$DAEMON
# Error checking here would be good...
echo "${SERVICE} started."
else
echo "Can't find file ${DAEMON}."
echo "${SERVICE} NOT started."
fi
;;
'stop')
if [ -s ${PIDFILE} ]
then
if kill `cat ${PIDFILE}` >/dev/null 2>&1
then
echo "${SERVICE} terminated."
rm -f ${PIDFILE}
fi
fi
;;
'restart')
$0 stop
sleep 10
$0 start
;;
*)
echo "Usage: $0 start|stop|restart"
;;
esac
[root@server01 ~]# vi /etc/init.d/zabbix_server [root@server01 ~]# chmod +x /etc/init.d/zabbix_server [root@server01 ~]# /etc/init.d/zabbix_server start Zabbix server started. [root@server01 ~]# netstat -tnlp| grep 10051 tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 12545/zabbix_server tcp 0 0 :::10051 :::* LISTEN 12545/zabbix_server
创建自带agent的启动脚本
[root@server01 ~]# vi /etc/init.d/zabbix_agentd
#!/bin/sh
# Zabbix
# Copyright (C) 2001-2018 Zabbix SIA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Start/Stop the Zabbix agent daemon.
# Place a startup script in /sbin/init.d, and link to it from /sbin/rc[023].d
SERVICE="Zabbix agent"
DAEMON=/usr/local/zabbix/sbin/zabbix_agentd
PIDFILE=/tmp/zabbix_agentd.pid
case $1 in
'start')
if [ -x ${DAEMON} ]
then
$DAEMON
# Error checking here would be good...
echo "${SERVICE} started."
else
echo "Can't find file ${DAEMON}."
echo "${SERVICE} NOT started."
fi
;;
'stop')
if [ -s ${PIDFILE} ]
then
if kill `cat ${PIDFILE}` >/dev/null 2>&1
then
echo "${SERVICE} terminated."
rm -f ${PIDFILE}
fi
fi
;;
'restart')
$0 stop
sleep 10
$0 start
;;
*)
echo "Usage: $0 start|stop|restart"
;;
esac
[root@server01 ~]# chmod +x /etc/init.d/zabbix_agentd [root@server01 ~]# /etc/init.d/zabbix_agentd start Zabbix agent started. [root@server01 ~]# netstat -tnlp| grep 10050 tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 12587/zabbix_agentd tcp 0 0 :::10050 :::* LISTEN 12587/zabbix_agentd [root@server01 ~]# /etc/init.d/nginx restart
网页输入URL:http://10.4.7.3:10049/zabbix/setup.php

zabbix页面配置


下面报错需要按照它说明的步骤下载文件,之后保存到指定位置

之后刷新完成

默认用户名:Admin
默认密码:zabbix
点击右上角进行中文配置,到此完成搭建工作。

Zabbix解决中文乱码

在C:WindowsFonts中复制想要的字体,后缀为ttf,若本身问大写,请改成小写的文件后缀ttf,并上传至zabbix服务器的/usr/local/nginx/html/zabbix/fonts/目录中使用sed命令替换/usr/local/nginx/html/zabbix/include/defines.inc.php文件中DejaVuSans.ttf字段(两处,也可直接进入文件搜索DejaVuSans字符进行替换,替换时仅写文件名不写后缀名)(也可以将DejaVuSans.ttf 进行重命名为DejaVu)
需要替换一下文件内容
[root@server01 ~]# sed -i 's/DejaVuSans/simkai/g' /usr/local/nginx/html/zabbix/include/defines.inc.php