lnmp 环境搭建 + zabbix

lnmp 环境搭建 + zabbix

1、安装mysql

tar -zxvf mysql-5.6.13-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.13-linux-glibc2.5-x86_64 /usr/local/mysql
mkdir -pv /data/mysql
cd /usr/local/mysql/script
./mysql_install --user=mysql --basedir=/usr/local/mysql --data-dir=/data/mysql

2、安装nginx

tar -zxvf /root/soft/pcre-8.33.tar.gz
tar -zxvf nginx-1.5.6.tar.gz
cd nginx-1.5.6
 ./configure --prefix=/usr/local/nginx \
 --sbin-path=/usr/local/nginx/sbin/nginx \
 --conf-path=/usr/local/nginx/etc/nginx.conf \
 --error-log-path=/usr/local/nginx/logs/error.log \
 --http-log-path=/usr/local/nginx/logs/access.log \
 --pid-path=/var/run/nginx/nginx.pid  \
 --lock-path=/var/lock/nginx.lock  \
 --user=nginx --group=nginx \
 --with-http_ssl_module \
 --with-http_flv_module \
 --with-http_stub_status_module \
 --with-http_gzip_static_module \
 --http-client-body-temp-path=/usr/local/nginx/client/ \
 --http-proxy-temp-path=/usr/local/nginx/proxy/ \
 --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \
 --with-pcre=/root/soft/pcre-8.33 #指定pcre源码包的路径
make && make install

检查nginx配置文件
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/etc/nginx.conf

启动nginx
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/etc/nginx.conf

3、安装php

yum install libxml2-devel libpng-devel libjpeg-devel gd freetype-devel bzip2-devel libcurl-devel 
tar -jxvf php-5.4.32.tar.bz2
cd php-5.4.32
编译php
./configure  \
 --prefix=/usr/local/php \
 --with-config-file-path=/usr/local/php/etc \
 --with-bz2 \
 --with-curl \
 --with-gettext \
 --with-libxml-dir \
 --with-zlib \
 --with-pdo-mysql=mysqlnd \
 --with-mysqli=mysqlnd \
 --with-mysql=mysqlnd \
 --with-libdir=lib64 \
 --with-openssl \
 --with-gd \
 --with-jpeg-dir \
 --with-png-dir \
 --with-freetype-dir \
 --with-iconv-dir \
 --enable-gd-native-ttf \
 --enable-dom \
 --enable-xml \
 --enable-fpm \
 --enable-ftp \
 --enable-sockets \
 --enable-mbstring \
 --enable-calendar \
 --enable-bcmath \
 --disable-ipv6 
make && make install

4、配置php

cp php.ini-production /usr/local/php/etc/php.ini
 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
 sed -i 's/;pid/pid/g' /usr/local/php/etc/php-fpm.conf
 cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
 chmod 755 /etc/rc.d/init.d/php-fpm
 chkconfig php-fpm on

添加zendGuardLoader支持

ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz
tar -zxvf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz
cd ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64
cp php-5.4.x/ZendGuardLoader.so /usr/local/php/lib/
vim /usr/local/php/php.ini zend_extension = /usr/local/php/lib/ZendGuardLoader.so 
zend_loader.enable = 1 
zend_loader.disable_licensing = 0 
zend_loader.obfuscation_level_support = 3

5、配置nginx支持php

user  nginx;
worker_processes  1;
#error_log  logs/error.log;
 error_log  logs/error.log  notice;
 #error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
 }
http {
   include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        root /usr/local/nginx/html;
        index index.php indext.html;
        location / {
             try_files $uri $uri/ /index.php?$args;
        }
        location ~ .*\.(php)?$ {
             expires -1s;
             try_files $uri = 404;
             include        fastcgi_params;
             #fastcgi_split_path_info ^(.+\.php)(/.+)$;
             #fastcgi_param  PATH_INFO $fastcgi_path_info;
             fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
             fastcgi_index  index.php;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_param QUERY_STRING $query_string;
             fastcgi_param REQUEST_METHOD $request_method;
             fastcgi_param CONTENT_TYPE $content_type;
             fastcgi_param CONTENT_LENGIH $content_length;
        }
    }
}

如果nginx和php安装在同一服务器上,可以使用sock方式进行连接,速度跟快

修改php-fpm配置文件
注释掉listen = 127.0.0.1:9000
改成listen = /tmp/fpm.sock

修改nginx配置文件

#fastcgi_pass  localhost:9000;
fastcgi_pass  unix:/tmp/fpm.sock;

6、安装zabbix

如果没有安装bcmath要补装安装php扩展bcmath
进入php源码包目录

cd php/ext/bcmath
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
vim /usr/local/php/etc/php.ini 添加
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/bcmath.so
tar -zxvf zabbix-2.0.6.tar.gz
cd zabbix-2.0.6
./configure --prefix=/usr/local/zabbix --enable-server --enable-java --enable-agent --with-mysql  --with-libcurl
 make install

创建数据库

mysql -uroot -p
create database zabbix default character set utf8
grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';
grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'zabbix';
use zabbix;
source /zabbix-2.0.6/database/mysql/schema.sql
source /zabbix-2.0.6/database/mysql/data.sql
source /zabbix-2.0.6/database/mysql/images.sql

添加服务端口

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
 zabbix-java     10052/tcp                       #zabbix java
 zabbix-java     10052/udp                       #zabbix java

修改配置文件

vim /usr/local/zabbix/etc/zabbix_server.conf
DBUser=zabbix
DBPassword=zabbxi密码
vim /usr/local/zabbix/etc/zabbix_agentd.conf
Hostname=Zabbix server
cp -arf zabbix/frontends/php  /usr/local/nginx/html/zabbix
chown –R zabbix:zabbix /usr/local/nginx/html/zabbix

 

修改php配置

vim /usr/local/php/etc/php.ini
max_execution_time = 300
date.timezone = Asia/Shanghai
memory_limit = 128M
post_max_size =16M
upload_max_filesize= 2M
max_execution_time = 300
max_input_time = 300

将zabbix的页面程序复制到nginx文档目录下

cp zabbix-2.0.6/front/php /usr/local/nginx/html/zabbix

在浏览器中安装zabbix

创建启动脚本

cp misc/init.d/fedora/core/× /etc/rc.d/init.d/

7、zabbix客户端安装

打包服务端上的客户端程序

cd /
tar -czvf zabbix.tar.gz /usr/local/zabbix/bin* /usr/local/zabbix/sbin/zabbix_agentd /usr/local/zabbix/sbin/zabbix_agent /usr/local/zabbix/etc/zabbix_agentd.conf /etc/rc.d/init.d/zabbix_agentd

在被监控客户端上解压

tar -zxvf zabbix.tar.gz -C /

编辑配置文件

vim /usr/local/zabbix/etc/zabbix_agentd.conf
Server=zabbix服务端ip地址

发表评论