lnmp+zabbix

cenots6.5x64mini-nginx+msyql5.6.7+php5.6.20+zabbix3.0

系统环境 centos6.5 x64 mini

关闭防火墙

关闭selinux

Service iptables stop    //个人习惯性关闭防火墙
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

 

1,安装nginx

https://blog.wojc.cn/104.html

2,安装mysql

https://blog.wojc.cn/106.html

3,安装php

安装依赖包

yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel –y

安装epel源

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel mcrypt mhash libxslt-devel

安装libiconv

tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/lcoal/libiconv
make && make install

解压安装包

tar -zxvf php-5.6.20.tar.gz

配置编译安装
cd php-5.6.20

./configure  \
--prefix=/usr/local/php-5.6.20 \
--with-config-file-path=/usr/local/php-5.6.20/etc \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-bz2 \
--with-curl \
--with-gd \
--with-mcrypt \
--with-openssl \
--with-mhash \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir=/usr/local/libiconv \
--with-gettext \
--with-libxml-dir=/usr/local \
--with-zlib \
--with-xsl \
--with-pdo-mysql=mysqlnd \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-libdir=lib64 \
--enable-dom \
--enable-xml \
--enable-fpm \
--enable-bcmath \
--enable-ftp \
--enable-sockets \
--disable-ipv6 \
--enable-mbregex \
--enable-mbstring \
--enable-calendar \
--enable-gd-native-ttf \
--enable-static \

make
make install
cp php.ini-production /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf
cd /usr/local/php/
mkdir -p /usr/local/php/log

编辑配置文件

Vim /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = error
rlimit_files = 32768
events.mechanism = epoll

[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 1024
pm.start_servers = 16
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.process_idle_timeout = 15s;
pm.max_requests = 2048
slowlog = log/$pool.log.slow
request_slowlog_timeout = 10

创建启动停止脚本:

vim /etc/init.d/php-fpm
#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN --daemonize $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
status)
if [ ! -r $php_fpm_PID ] ; then
echo "php-fpm is stopped"
exit 0
fi
PID=`cat $php_fpm_PID`
if ps -p $PID | grep -q $PID; then
echo "php-fpm (pid $PID) is running..."
else
echo "php-fpm dead but pid file exists"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
configtest)
$php_fpm_BIN -t
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
exit 1
;;
esac

 

赋予权限

chmod +x /etc/init.d/php-fpm

启动

[root@zabbix-server php-5.6.20]# service php-fpm start
Starting php-fpm  done

查看监听端口
[root@zabbix-server php-5.6.20]# netstat -anpt |grep php-fpm
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      16070/php-fpm

配置nginx 支持php

打开配置文件在server区块加入下面内容(这里是虚拟主机,网站根目录也在jinchuang下面)

server {
listen       80;
server_name  www.jinchuang.com jinchuang.com;
charset utf-8;
#access_log      logs/access_jinchuang.log main;
access_log  logs/access_jinchuang.log;

location / {
            root   html/jinchuang;
            index  index.php index.html index.htm;
           }

error_page   500 502 503 504  /50x.html;

location = /50x.html {
            root   html;
            }

location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME   /usr/local/nginx/html/jinchuang$fastcgi_script_name;
            include        fastcgi_params;
        }

}

 

4安装zabbix

依赖包

yum -y install *snmp* --skip-broken
yum -y install mysql-devel

解压配置安装

tar -zxvf zabbix-3.0.3.tar.gz
cd zabbix-3.0.3
./configure  --prefix=/usr/local/zabbix-server --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
make && make install

创建数据库

mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'your password'; #只允许localhost 连接,也可指设置为单个ip,ip段
mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'your password';   #允许所以主机连接
mysql> flush privileges;
mysql> quit;

导入数据库

mysql -uroot -proot zabbix<./database/mysql/schema.sql
mysql -uroot -proot zabbix<./database/mysql/images.sql
mysql -uroot -proot zabbix<./database/mysql/data.sql

修改配置文件

vi /usr/local/zabbix-server/etc/zabbix_server.conf
#数据库名称
DBName=zabbix
#数据库用户名
DBUser=zabbix
#数据库密码
DBPassword=yourpassword
#zabbix运行脚本(报警脚本)存放目录
AlertScriptsPath=/usr/local/zabbix-server/share/zabbix/alertscripts

修改权限
chown -R zabbix.zabbix /usr/local/zabbix-server/

#复制启动脚本
cp /home/zabbix-3.0.0rc1/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
cp /home/zabbix-3.0.0rc1/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd

vim /etc/rc.d/init.d/zabbix_server
将FULLPATH=$BASEDIR/sbin/$BINARY_NAME替换为FULLPATH=$BASEDIR/zabbix-server/sbin/$BINARY_NAME

vim /etc/rc.d/init.d/zabbix_agentd
将FULLPATH=$BASEDIR/sbin/$BINARY_NAME替换为FULLPATH=$BASEDIR/zabbix-server/sbin/$BINARY_NAME

启动zabbix

service zabbix_server start
service zabbix_agentd start

如果遇到报错

[root@zabbix-server ~]# service zabbix_server start
Starting zabbix_server:  /usr/local/zabbix-server/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[FAILED]

解决办法:
[root@zabbix-server ~]# vim /etc/ld.so.conf
添加一行
/usr/local/mysql/lib/


保存退出
ldconfig 生效下

 

#查看端口是否监听

[root@zabbix-server ~]# netstat -anpt |grep zabbix
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      28309/zabbix_agentd
tcp        0      0 192.168.16.251:10051        0.0.0.0:*                   LISTEN      28197/zabbix_server
tcp        0      0 :::10050                    :::*                        LISTEN      28309/zabbix_agentd

如果没有10051端口,查看日志报错
 10326:20170325:063941.203 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/lnmp/lnmp/mysql/mysql.sock' (2)
 10326:20170325:063941.203 database is down: reconnecting in 10 seconds

是因为zabbix去找默认mysql.sock 来连接了,我们修改下配置文件,启用修改下你的mysql.sock 文件路径然后保存重启
DBSocket=/lnmp/lnmp/mysql/data/mysql.sock

创建站点目录

mkdir -p /usr/local/nginx/html/jinchuang/zabbix

拷贝程序文件到站点目录下面

cp -rf /home/zabbix-3.0.0rc1/frontends/php/* /usr/local/nginx/html/jinchuang/zabbix/
chown -R nginx.nginx /usr/local/nginx/html/jinchuang/

访问http://192.168.16.251/zabbix

我这里一直报php.ini文件错误,修改后重启服务不生效。后来在phpinfo信息中看到,php.ini文件应该在/usr/lcoal/php-5.6.20/etc 中。拷贝修改的php.ini到此目录重启服务生效。
lnmp+zabbix

关于安装检查页面报错:只用把对应的php.ini参数修改为提示参数值即可重启php!

lnmp+zabbix关于mysql数据库连接错误:检查防火墙,和是否授权ip可以连接!
lnmp+zabbix

这里可自行修改服务器端名称也可以不修改使用默认的!

lnmp+zabbixlnmp+zabbix

如果下一步会报错误,配置文件无法创建,或者提示手动创建(检查程序目录权限是否为nginx,修改为nginx用户权限)

如果ok跳过此步骤:

下载配置文件放到/usr/local/nginx/html/zabbix/conf 下面。然后刷新页面

默认用户名 Admin

默认密码   zabbix

 

zabbix监控项文字乱码解决

拷贝windows下面字体到 zabbix 程序目录中 fonts目录下面,备份原来字体。重新命名。

mv DejaVuSans.ttf DejaVuSans.ttf.bak

mv SIMKAI.TTF DejaVuSans.ttf

 

相关文章:Zabbix 4.0版本安装

分享