很多文档使用的是yum安装mysql、http、php等工具。这里采用源码安装的形式,实现从LNMP-zabbix的全程记录。

一、LNMP平台搭建

  参考:http://www.ttlsa.com/nginx/nginx-install-on-linux/

        http://swht1278.blog.51cto.com/7138082/1623886

  1.nginx的安装

    1.1 依赖环境的部署

       yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel pcre-static gd-*

    1.2 建立nginx用户及用户组

       groupadd -r nginx && useradd -s /sbin/nologin -g nginx -r nginx

    1.3 下载最新nginx安装包

       wget -P /usr/local/src/ http://nginx.org/download/nginx-1.9.1.tar.gz

    1.4 编译安装nginx

        cd /usr/local/src/ && tar xf nginx-1.9.1.tar.gz

       ./configure --prefix=/usr/local/nginx --lock-path=/usr/local/nginx/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/ --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi --with-pcre --with-file-aio --with-http_p_w_picpath_filter_module && make && make install

    1.5 nginx启动脚本

==============================

vim /etc/init.d/nginx   chmod +x /etc/init.d/nginx  

#!/bin/bash

#

# Startup script for Nginx - this script starts and stops the nginx daemon

#

# chkconfig:   - 85 15

# description:  Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server

# processname: nginx

# config:      /usr/local/nginx/conf/nginx.conf

# pidfile:     /usr/local/nginx/logs/nginx.pid 

# 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"

[ -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

    [ $retval -eq 0 ] && touch $lockfile

    return $retval

}

 

stop() {

    echo -n $"Stopping $prog: "

    killproc $prog -QUIT

    retval=$?

    echo

    [ $retval -eq 0 ] && rm -f $lockfile

    return $retval

}

 

restart() {

    configtest || return $?

    stop

    sleep 1

    start

}

 

reload() {

    configtest || return $?

    echo -n $"Reloading $prog: "

    killproc $nginx -HUP

    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

==================================================

   1.6 nginx的启动和关闭

     service nginx start|reload|restart|stop

     chkcofnig nginx on

     或者:

     启动 /usr/local/nginx-1.5.1/sbin/nginx

     关闭 /usr/local/nginx-1.5.1/sbin/nginx -s stop

     重启 /usr/local/nginx-1.5.1/sbin/nginx -s reload

  2.mysql的安装

   参考:二进制源码包安装mysql连接 http://www.ttlsa.com/mysql/install-mysql5_6/

         自定义编译源码包安装mysql连接:http://swht1278.blog.51cto.com/7138082/1658992

   2.1 编译环境安装(适用于最小化安装的Linux系统)

     yum -y install wget gcc* make openssl openssl-devel openssl-clients ncurses-devel -y && yum groupinstall " Development tools" 

   2.2 mysql×××

     wget -P /usr/local/src/ http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz

     #wget -P /usr/local/src/ http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.25.tar.gz

     wget -P /usr/local/src/ http://down1.chinaunix.net/distfiles/cmake-2.8.10.2.tar.gz

   2.3 源码安装cmake编译环境

     cd /usr/local/src/ && tar xf cmake-2.8.10.2.tar.gz

     cd cmake-2.8.10.2 && ./configure --prefix=/usr/local/cmake && make && make install

     vim /etc/profile

      #set cmake

      export PATH==$PATH:/usr/local/cmake/bin

     source /etc/profile

   2.4 源码安装mysql-5.6

     groupadd mysql && useradd -r -g mysql -s /etc/nologin mysql  #(创建mysql用户不需要密码和登录系统)

     mkdir -p /home/mysql/data && mkdir /home/mysql/var 

     cd /usr/local/src/ && tar xf mysql-5.6.20.tar.gz && cd mysql-5.6.20 

     cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/home/mysql/var/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci && make && make install

     

     编译报错解决参考:http://blog.163.com/sz2273_pr/blog/static/41264296201361354426670/

     环境变量配置

     vim /etc/profile

     在末行添加export PATH=$PATH:/usr/sbin/:/usr/local/mysql/bin

     保存退出执行:source /etc/profile 

   2.5 初始化数据库

     /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql --default-storage-engine=MyISAM  

   2.6 修改配置文件my.cnf

============================================

vim /etc/my.cnf


[client]

default-character-set=utf8

#auto-rehash

socket = /home/mysql/var/mysql.sock

[mysqld]

# GENERAL #

user = mysql

slave-skip-errors=1022,1032,1062

basedir = /usr/local/mysql

default-storage-engine = MyISAM

socket = /home/mysql/var/mysql.sock

pid-file = /home/mysql/var/mysql.pid

port = 3306


# MyISAM #

key_buffer_size = 1344M

myisam_recover = FORCE,BACKUP


# SAFETY #

max_allowed_packet = 16M

max_connect_errors = 1000000

skip_name_resolve


# DATA STORAGE #

datadir = /home/mysql/data

long_query_time = 1


# BINARY LOGGING #

log-bin = /home/mysql/data/mysql-bin.log

expire-logs-days = 14

sync-binlog = 1

server-id = 1

max_binlog_size = 500M


# REPLICATION #

relay-log = /home/mysql/data/relay-bin.log

slave-net-timeout = 60


# CACHES AND LIMITS #

tmp_table_size = 32M

max_heap_table_size = 32M

max_connections = 500

thread_cache_size = 50

open_files_limit = 65535

table_definition_cache = 4096

table_open_cache = 4096


# INNODB #

innodb_data_file_path = ibdata1:128M;ibdata2:10M:autoextend

innodb_flush_method = O_DIRECT

innodb_log_files_in_group = 2

innodb_lock_wait_timeout = 50

innodb_log_file_size = 256M

innodb_flush_log_at_trx_commit = 1

innodb_file_per_table = 1

innodb_thread_concurrency = 8

innodb_buffer_pool_size = 8G


# LOGGING #

log-error = /home/mysql/data/mysql-error.log

log-queries-not-using-indexes = 1

slow-query-log = 1

long_query_time = 1

slow-query-log-file = /home/mysql/data/mysql-slow.log


# FOR SLAVE #

#binlog-format = ROW

#log-slave-updates = true

#gtid-mode = on

#enforce-gtid-consistency = true

#master-info-repository = TABLE

#relay-log-info-repository = TABLE

#sync-master-info = 1

#slave-parallel-workers = 2

#binlog-checksum = CRC32

#master-verify-checksum = 1

#slave-sql-verify-checksum = 1

#binlog-rows-query-log_events = 1

#report-port = 3306

#report-host = 10.1.1.10   

============================================

   2.7 mysql的启动与关闭

    cp support-files/mysql.server /etc/init.d/mysql && chmod +x /etc/init.d/mysql

    service mysql start|stop|relaod|restart

    chkconfig mysql on

  3. PHP编译安装

   参考:nginx连接PHP 5.5 http://www.ttlsa.com/nginx/nginx-php-5_5/

   3.1 编译环境安装

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

   3.2 源码包下载

    wget -P /usr/local/src/ http://cn2.php.net/distributions/php-5.6.9.tar.gz

   3.3 编译安装php5.6.9

    cd /usr/local/src/ && tar xf  php-5.6.9.tar.gz && cd php-5.6.9

    ./configure  --prefix=/usr/local/php-5.6.9 --with-config-file-path=/usr/local/php-5.6.9/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath && make && make install

   3.4 配置PHP

    cp php.ini-production /usr/local/php-5.6.9/etc/php.ini

    cp /usr/local/php-5.6.9/etc/php-fpm.conf.default /usr/local/php-5.6.9/etc/php-fpm.conf

=================================    

    打开php.ini配置文件,修改如下参数为如下值,否则zabbix安装不了。

max_execution_time = 300

memory_limit = 128M

post_max_size = 16M

upload_max_filesize = 2M

max_input_time = 300 #这个参数修改是在文档的第383行,相关信息在本文档下面有介绍

date.timezone PRC

==============================

   3.5 启动PHP-fpm

    /usr/local/php-5.6.9/sbin/php-fpm

   3.6 nginx配置

===============================

location /

{

    try_files $uri $uri/ /index.php?$args;

}

 

location ~ .*\.(php)?$

{

    expires -1s;

    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    include fastcgi_params;

    fastcgi_param PATH_INFO $fastcgi_path_info;

    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    #fastcgi_pass 127.0.0.1:9000;

    fastcgi_pass unix:/var/run/phpfpm.sock;

}

=================================


二、编译安装zabbix

  2.1 依赖环境安装

   yum install net-snmp-devel libxml2-devel libcurl-devel -y

  2.2 下载zabbix源码包

   wget -p /usr/local/src/ http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.5/zabbix-2.4.5.tar.gz

  2.3 编译安装zabbix

   cd /usr/local/src/ && tar xf zabbix-2.4.5.tar.gz && cd zabbix-2.4.5

   ./configure --prefix=/usr/local/zabbix-2.4.5/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 && make && make install

  2.4 创建用户

   groupadd -r zabbix && useradd -s /sbin/nologin -g zabbix -r zabbix

  2.5 初始化数据库

    mysql -uroot -pPasswd

    mysql>create database zabbix default charset utf8;

    mysql>quit;

    mysql -uroot -pPasswd zabbix < database/mysql/schema.sql #初始化proxy库

    #初始化server库

    mysql -uroot -p zabbix < database/mysql/p_w_picpaths.sql

    mysql -uroot -p zabbix < database/mysql/data.sql

   mysql设置密码

    $mysql

    mysql>use mysql;

    mysql>update  user set password=password('yzkj2015') where user='root';

    mysql> flush privileges;

  2.6 配置zabbix

   mkdir /etc/zabbix && cp conf/zabbix_server.conf /etc/zabbix/ && vim /etc/zabbix/zabbix_server.conf

==============

DBName=zabbix

DBUser=root

DBPassword=yzkj2015

DBPort=3306

==============

   2.7 zabbix_server启动

    /usr/local/zabbix-2.4.5/sbin/zabbix_server

   2.8 zabbix客户端配置

    创建用户

     groupadd -r zabbix && useradd -s /sbin/nologin -g zabbix -r zabbix

    编译安装

    cd /usr/local/src/ && tar xf zabbix-2.4.5.tar.gz && cd zabbix-2.4.5

    ./configure --prefix=/usr/local/zabbix-2.4.5/ --enable-agent && make && make install

    修改配置文件

    vim /usr/local/zabbix-2.2.2/etc/zabbix_agentd.conf

     Server=127.0.0.1  #被动接受某个IP地址的检查

     ServerActive=127.0.0.1 #主动将数据发送给该IP地址

     Hostname=Zabbix server

    客户端启动

     /usr/local/zabbix-2.4.5/sbin/zabbix_agentd

   2.9 浏览器安装

     网站文件拷贝

     mkdir /home/zabbix && cp -rp /usr/local/src/zabbix-2.4.5/frontends/php/* /home/zabbix && cp /home/zabbix/conf/zabbix.conf.php.example /home/zabbix/conf/zabbix.conf.php

     

      报错PHP option max_input_time 60 300 Fail

      解决:原因是php.ini文件里面有两个参数,第一个max_input_time默认是-1,第二个则是默认为60,需要修改成300

      121 ; max_input_time

      122 ;   Default Value: -1 (Unlimited)

      123 ;   Development Value: 60 (60 seconds)

      124 ;   Production Value: 60 (60 seconds)

      125 max_input_time = 300

      383 max_input_time = 300

      报错:Error connecting to database: No such file or directory

      原因是:Database host写成了localhost

      解决:Database type  MySQL

            Database host  127.0.0.1

            Database port  3306

            Database name  zabbix

            User           root #可以是zabbix,这样安全,但要记得密码要对应

            Password       *****

      备注:这个地方的配置可以在/home/zabbix/conf/zabbix.conf.php中进行修改。路径根据自己的实际情况进行设置查找

    2.10 使用默认账号登录首页

      admin

      zabbix

      

 至此,zabbix的源码安装实验完成,接下来的将是对zabbix的配置进行学习,请参照另外文档。

参考文章:http://www.ttlsa.com/zabbix/install-zabbix-on-linux-5-ttlsa/

声明:该文档仅供学习使用,对于参考文章作者表示衷心感谢,我这篇文档仅仅是对整个搭建过程进行细致的参数调节,以及符合我们自身的生产情况。各位看官只关注学习就好~