码迷,mamicode.com
首页 > 其他好文 > 详细

细化如何安装LNMP + Zabbix 监控安装文档以及故障排除

时间:2016-09-05 09:06:22      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

1.LNMP所需安装包:

上传如下软件包到/soft目录中

mysql- 5.1.71(centos6.5 64位自带)也可根据版本自行挑选,前提你了解这个版本

pcre-8.36.tar.gz

nginx-1.6.2.tar.gz

jpegsrc.v9a.tar.gz

libmcrypt-2.5.8.tar.gz

php-5.6.3.tar.gz

2.配置系统YUM源

cd /etc/yum.repos.d/

vim install.repo

[LOCALYUMSOURCE]

name=PD307

baseurl=http://192.168.100.254/1 #本地ISO挂载目录写法为:file:///mnt mnt是挂载目录

        http://192.168.100.254/2

gpgcheck=0

3.安装LNMP环境依赖包

yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng* libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libX* libtiff libtiff*  make mpfr ncurses* ntp openssl nasm nasm* openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib*  wget zlib-devel

4.安装Mysql

如果是按照编译安装mysql5.7,请参考点击http://www.cnblogs.com/renfanzi/p/5613431.html

yum install mysql*

安装目录:/var/lib/mysql/

拷贝mysql64位库文件至32位目录

cp /usr/lib64/mysql/* /usr/lib/mysql/,如果服务器没有/usr/lib/mysql/ 目录,则在/usr/lib/目录下创建mysql目录即可

5.安装pcre

tar  zxvf pcre-8.36.tar.gz    

cd pcre-8.36     

./configure --prefix=/usr/local/pcre

make    

make install

6.安装 nginx

了解安装nginx,请点击http://www.cnblogs.com/renfanzi/p/5686540.html

groupadd www  #添加www组    
useradd -g www www -s /bin/false  #创建nginx运行账户www并加入到www组,不允许www用户直接登录系统    
tar zxvf nginx-1.6.2.tar.gz    
cd nginx-1.6.2    
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/soft/pcre-8.36
#注意:--with-pcre=/soft/pcre-8.30指向的是源码包解压的路径,而不是安装的路径,否则会报错    
make    
make install

7.编写Nginx启动脚本:

vi /etc/rc.d/init.d/nginx    #设置nginx开启启动,编辑启动文件添加下面内容

技术分享
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse #               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /www/wdlinux/nginx/conf/nginx.conf
# pidfile:     /www/wdlinux/nginx/logs/nginx.pid
# Url http://www.wdlinux.cn
# Last Updated 2010.06.01

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    #service php-fpm start
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: "
    $nginx -s stop
    echo_success
    retval=$?
    echo
    #service php-fpm stop
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    $nginx -s reload
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac 
View Code

chmod 775  /etc/rc.d/init.d/nginx  #赋予文件执行权限    

chkconfig nginx on    #设置开机启动

8.配置Nginx

egrep -v "#" /usr/local/nginx/conf/nginx.conf

#此为参考配置示例

技术分享
user  www www; #取消注释,修改为www用户和www组
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        root         /usr/local/nginx/html;            #修改nginx默认目录
        index        index.php index.html index.htm;  #添加nginx支持php索引
        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  $document_root$fastcgi_script_name;   #修改为$document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
View Code

/etc/rc.d/init.d/nginx restart   #重启

9.安装jpeg

cd /soft/jpeg-9a/
tar zxf jpegsrc.v9a.tar.gz 
cd jpeg-9a/
./configure --prefix=/usr/local/jpeg
make && make install

10.安装libmcrypt

cd /soft #libmcrypt-2.5.8.tar.gz 软件包路径
tar -zxvf libmcrypt-2.5.8.tar.gz
cd /usr/local/src/libmcrypt-2.5.8
./configure --prefix=/usr/local
make && make install

11.安装PHP

技术分享
cd /soft
tar -zvxf php-5.6.3.tar.gz    
cd  php-5.6.3    
mkdir -p /usr/local/php5  #建立php安装目录    
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr --with-mysqli=/usr/lib64/mysql/mysql_config --with-mysql-sock=/var/lib/mysql/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir --with-jpeg-dir=/usr/local/jpeg 
make  && make install    

PHP系统配置文件设置
cp  php.ini-production   /usr/local/php5/etc/php.ini  #复制php配置文件到安装目录
rm -rf /etc/php.ini   #删除系统自带配置文件    
ln -s /usr/local/php5/etc/php.ini  /etc/php.ini    #添加软链接    
cp  /usr/local/php5/etc/php-fpm.conf.default   /usr/local/php5/etc/php-fpm.conf      #拷贝模板文件为php-fpm配置文件

PHP修改添加Nginx用户
vi  /usr/local/php5/etc/php-fpm.conf  #编辑    
user = www    #设置php-fpm运行账号为www    
group = www   #设置php-fpm运行组为www    
pid = run/php-fpm.pid    #取消前面的分号    
cp /soft/php-5.6.3/sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm  #设置 php-fpm开机启动,拷贝php-fpm到启动目录    
chmod +x /etc/rc.d/init.d/php-fpm  #添加执行权限    
chkconfig php-fpm on    #设置开机启动  

PHP配置文件设置
vi /usr/local/php5/etc/php.ini
找到;disable_functions =修改为
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。找到:;date.timezone =    
修改为:date.timezone = PRC   #设置时区    
找到:expose_php = On    
修改为:expose_php = OFF  #禁止显示php版本的信息

修改PHP参数
post_max_size = 8M             #改为16M
max_execution_time = 30         #改为300
max_input_time = 60               #改为300
View Code

(二) Zabbix安装

Zabbix软件包:

zabbix-2.4.2.tar.gz

zabbix-agent-2.4.2-1.el6.x86_64.rpm

Zabbix 所需依赖包:

yum -y install net-snmp net-snmp-devel OpenIPMI OpenIPMI-devel OpenIPMI-tools OpenIPMI-libs libssh2* unixODBC*

1.数据库初始化

创建并赋予权限

/etc/init.d/mysqld start
mysqladmin -u root password yd_12345678
mysql -uroot -pyd_12345678
> create database zabbix character set utf8;
> use mysql;
> grant all privileges on zabbix.* to zabbix@localhost identified by ‘yd_12345678‘;
> flush privileges;
>quit;

如出现

mysql -u root –p
Enter password: 
ERROR 1045 (28000): Access denied for user root@localhost (using password: YES)

解决办法

>set password for root@localhost =PASSWORD(yd_12345678);

2.安装zabbix

技术分享
cd /soft/
tar zxvf zabbix-2.4.2.tar.gz
cd zabbix-2.4.2
#导入数据库/soft/zabix-2.4.2目录下#注意要按顺序导入,不然会报错
mysql -uzabbix -pyd_12345678 zabbix < database/mysql/schema.sql
mysql -uzabbix -pyd_12345678 zabbix < database/mysql/images.sql
mysql -uzabbix -pyd_12345678 zabbix < database/mysql/data.sql
编译安装:
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/lib64/mysql/mysql_config --with-net-snmp --with-libcurl --enable-proxy --with-openipmi --with-unixodbc --with-ssh2
make install
#注意:
在编译时,如果缺少相应的依赖包,configure过程会给出提示,然后用yum安装相
应的软件。
View Code

3.创建zabbix服务

  vim /etc/services

zabbix-agent    10050/tcp                      # Zabbix Agent
zabbix-agent    10050/udp                      # Zabbix Agent
zabbix-trapper  10051/tcp                      # Zabbix Trapper
zabbix-trapper  10051/udp                      # Zabbix Trapper

4.创建zabbix相关账户,文件,权限

groupadd zabbix
useradd -g zabbix -m zabbix
mkdir -p /etc/zabbix
cp conf/{zabbix_server.conf,zabbix_agentd.conf} /etc/zabbix
chmod 400 /etc/zabbix/zabbix_server.conf
chown zabbix /etc/zabbix/zabbix_server.conf
chown -R zabbix:zabbix /etc/zabbix
chmod 0755 /etc/zabbix/zabbix_server.conf

5.配置zabbix服务端

ln -sf /usr/local/zabbix/etc/zabbix_server.conf /etc/zabbix/zabbix_server.conf

vim /etc/zabbix/zabbix_server.conf

技术分享
ln -sf /usr/local/zabbix/etc/zabbix_server.conf /etc/zabbix/zabbix_server.conf
vim /etc/zabbix/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix                            zabbix所属数据库名称
DBUser=zabbix                            zabbix所属数据库用户
DBPassword=yd_12345678                zabbix数据库密码
DBSocket=/var/lib/mysql/mysql.sock
StartPollers=30                         轮询的初始值(0-1000)
StartIPMIPollers=4                       IPMI轮询的初始值(0-1000)
StartPollersUnreachable=30               轮询不可达的主机数(包括IPMI 0-1000)
StartTrappers=8                         捕获的初始值(0-1000)
StartPingers=4                          ping的初始值(0-1000)
StartDiscoverers=0                      自动发现的初始值(0-250)
CacheSize=384M                          缓存大小
CacheUpdateFrequency=300                缓存更新的频率
StartDBSyncers=8                        数据库同步时间
TrendCacheSize=128M                     总趋势缓存大小
AlertScriptsPath=/usr/bin               脚本的存放位置
LogSlowQueries=1000                     日志慢查询设定
#AlertScriptsPath=/usr/local/zabbix/scripts    #指定告警脚本存放位置
View Code

6.配置zabbix php环境

技术分享
cd frontends/  # /soft/zabbix-2.4.2/frontends 软件包解压路径
cp -rf  php  /usr/local/nginx/html
cd /usr/local/nginx/html
mv php zabbix
chown -R zabbix:zabbix zabbix
vi /usr/local/php5/etc/php.ini
date.timezone = Asia/Shanghai
sed -i "s#;always_populate_raw_post_data = -1#always_populate_raw_post_data = -1#g" /usr/local/php5/etc/php.ini
sed -i "s#;cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" /usr/local/php5/etc/php.ini
View Code

7.配置zabbix启动服务

技术分享
cp /usr/local/zabbix/sbin/zabbix_server /etc/init.d/
cp /usr/local/zabbix/sbin/zabbix_agentd /etc/init.d/
chmod 755 /etc/init.d/zabbix_*
sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g" /etc/init.d/zabbix_server
sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g" /etc/init.d/zabbix_agentd
chkconfig --add zabbix_server
chkconfig --add zabbix_agentd
chkconfig --level 345 zabbix_server on
chkconfig --level 345 zabbix_agentd on
service zabbix_server restart
service zabbix_agentd restart
View Code

8.配置Server端防火墙 #不启用防火墙不用配置

vim /etc/sysconfig/iptables
-A INPUT -s 192.168.0.0/16 -p tcp -m multiport --dports 10050,10051 -j ACCEPT

Zabbix的服务端口为10050和10051

到此,zabbix配置完成.

可以使用web访问http://ip/zabbix/setup.php

默认用户名和密码:admin/zabbix

9.服务初始化

1.启用防火环境设置防火墙开放80,9000,10050,10051端口

2.设置系统Selinux已经关闭

3.设置Mysql、Nginx、php-fpm服务自启动

{chkconfig –level 2345 mysqld on; chkconfig  --level 2345 nginx on; chkconfig  --level 2345 php-fpm on ;chkconfig}

4.设置/etc/init.d/zabbix_server 开机引导,加入/etc/rc.local

10.配置zabbix.conf.php #web setup.php运行后自动生成

  vim /usr/local/nginx/html/zabbix/conf/zabbix.conf.php;

chmod 777 /usr/local/nginx/html/zabbix/conf

技术分享
<?php
// Zabbix GUI configuration file
global $DB;

$DB[TYPE]     = MYSQL;
$DB[SERVER]   = localhost;
$DB[PORT]     = 0;
$DB[DATABASE] = zabbix;
$DB[USER]     = root;
$DB[PASSWORD] = yd_12345678;

// SCHEMA is relevant only for IBM_DB2 database
$DB[SCHEMA] = ‘‘;

$ZBX_SERVER      = localhost;
$ZBX_SERVER_PORT = 10051;
$ZBX_SERVER_NAME = pd;

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
View Code

11.设置中文支持

vim /usr/local/nginx/html/zabbix/include/locales.inc.php

第55行中结尾处false改成true,IE浏览器使用admin登录zabbix主页面右上方Profile中Language 中选择Chinese(zh CN)点击Update。

FQA:故障排除,一步错步步错

一、

  1. 出现connection to database ‘zabbix’ faild .设置了Lnmp和zabbix服务自启动后reboot系统(tail –f /tmp/zabbix.log)
  2. 技术分享
  3. 还是报错参考/usr/local/zabbix/etc/zabiix_server.conf

  4. 技术分享
    LogFile=/tmp/zabbix_server.log
    DBHost=localhost
    DBName=zabbix
    DBUser=zabbix
    DBPassword=yd_12345678
    DBSocket=/var/lib/mysql/mysql.sock
    DBPort=3306
    StartPollers=5
     StartIPMIPollers=10
     StartPollersUnreachable=10
     StartTrappers=10
     StartPingers=10
     StartDiscoverers=10
     SNMPTrapperFile=/tmp/zabbix_snmptt.log
     ListenIP=127.0.0.1
     MaxHousekeeperDelete=500
     CacheSize=384M
     CacheUpdateFrequency=300
     StartDBSyncers=40
     HistoryCacheSize=128M
     TrendCacheSize=128M
     HistoryTextCacheSize=128M
     ValueCacheSize=128M
     Timeout=30
     TrapperTimeout=300
     UnreachablePeriod=45
     UnavailableDelay=60
     UnreachableDelay=15
     AlertScriptsPath=/usr/local/zabbix/scripts
     FpingLocation=/usr/sbin/fping
     LogSlowQueries=10000
     StartProxyPollers=50
     ProxyConfigFrequency=3600
    View Code

     

二、

  1. WEB页面setup.php向导报错(http://IP/zabbix/setup.php)

技术分享

修改php.ini相关的参数:/usr/local/php5/etc/php.ini

三、

比较容易出现问题的配置文件

Nginx配置文件  /usr/local/nginx/conf/nginx.conf

Zabbix配置文件 /usr/local/zabbix/etc/zabbix_server.conf

PHP5配置文件  /usr/local/php5/etc/php.ini

示例配置文件:

技术分享

声明出处:由于本文是根据书本写的博客,如遇已有类似文章博客,请联系我,我会在声明出处。

细化如何安装LNMP + Zabbix 监控安装文档以及故障排除

标签:

原文地址:http://www.cnblogs.com/renfanzi/p/5825485.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!