細化如何安裝LNMP + Zabbix 監控安裝文檔以及故障排除

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/javascript

vim install.repophp

[LOCALYUMSOURCE]html

name=PD307java

baseurl=http://192.168.100.254/1 #本地ISO掛載目錄寫法爲:file:///mnt mnt是掛載目錄mysql

        http://192.168.100.254/2linux

gpgcheck=0nginx

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.htmlc++

yum install mysql*web

安裝目錄:/var/lib/mysql/sql

拷貝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、

  1. 出現connection to database ‘zabbix’ faild .設置了Lnmp和zabbix服務自啓動後reboot系統(tail –f /tmp/zabbix.log)
  2. 仍是報錯參考/usr/local/zabbix/etc/zabiix_server.conf

  3. 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

     

2、

  1. WEB頁面setup.php嚮導報錯(http://IP/zabbix/setup.php)

修改php.ini相關的參數:/usr/local/php5/etc/php.ini

3、

比較容易出現問題的配置文件

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

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

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

示例配置文件:

聲明出處:因爲本文是根據書本寫的博客,如遇已有相似文章博客,請聯繫我,我會在聲明出處。

相關文章
相關標籤/搜索