天天看點

LNMP環境搭建(基于zabbix監控軟體)

LNMP環境搭建(基于zabbix監控軟體)

安裝依賴包:

yum -y install pcre  pcre-devel  openssl openssl-devel

安裝nginx

[root@localhost media]# tar zxvf nginx-1.6.0.tar.gz

[root@localhost media]# cd nginx-1.6.0

[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx-1.6.0 --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre

--with-http_stub_status_module:支援nginx狀态查詢

--with-http_ssl_module:支援https

--with-http_spdy_module:支援google的spdy,想了解請百度spdy,這個必須有ssl的支援

--with-pcre:為了支援rewrite重寫功能,必須制定pcre

[root@localhost nginx-1.6.0]# make

[root@localhost nginx-1.6.0]# make install

啟動:

[root@localhost nginx-1.6.0]# /usr/local/nginx-1.6.0/sbin/nginx 

關閉:

[root@localhost nginx-1.6.0]# /usr/local/nginx-1.6.0/sbin/nginx -s stop

加載配置檔案:

[root@localhost nginx-1.6.0]# /usr/local/nginx-1.6.0/sbin/nginx -s reload

開機啟動:

[root@localhost ~]# vim /etc/init.d/nginx

#!/bin/bash

# nginx Startup script for the Nginx HTTP Server

# chkconfig: - 85 15

# description: Nginx is a high-performance web and proxy server.

#              It has a lot of features, but it's not for everyone.

# processname: nginx

# pidfile: /var/run/nginx.pid

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

nginxd=/usr/local/nginx-1.6.0/sbin/nginx

nginx_config=/usr/local/nginx-1.6.0/conf/nginx.conf

nginx_pid=/var/run/nginx.pid

RETVAL=0

prog="nginx"

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = "no" ] && exit 0

[ -x $nginxd ] || exit 0

# Start nginx daemons functions.

start() {

if [ -e $nginx_pid ];then

   echo "nginx already running...."

   exit 1

fi

   echo -n $"Starting $prog: "

   daemon $nginxd -c ${nginx_config}

   RETVAL=$?

   echo

   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx

   return $RETVAL

}

# Stop nginx daemons functions.

stop() {

        echo -n $"Stopping $prog: "

        killproc $nginxd

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid

# reload nginx service functions.

reload() {

    echo -n $"Reloading $prog: "

    #kill -HUP `cat ${nginx_pid}`

    killproc $nginxd -HUP

    RETVAL=$?

    echo

# See how we were called.

case "$1" in

start)

        start

        ;;

stop)

        stop

reload)

        reload

restart)

status)

        status $prog

*)

        echo $"Usage: $prog {start|stop|restart|reload|status|help}"

        exit 1

esac

exit $RETVAL

[root@localhost ~]# chmod +x /etc/init.d/nginx  #執行權限

[root@localhost ~]chkconfig nginx on #設定開機啟動

安裝依賴包

[root@localhost php-5.5.14]# yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y

安裝php

[root@localhost media]# tar zxvf php-5.5.14.tar.gz

[root@localhost php-5.5.14]# ./configure --prefix=/usr/local/php-5.5.0 --with-config-file-path=/usr/local/php-5.5.0/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

[root@localhost php-5.5.14]# make  && make install

[root@localhost php-5.5.14]# cp php.ini-production /usr/local/php-5.5.0/etc/php.ini #複制php配置檔案到安裝目錄

[root@localhost php-5.5.14]# cp /usr/local/php-5.5.0/etc/php-fpm.conf.default /usr/local/php-5.5.0/etc/php-fpm.conf  #拷貝模闆檔案為php-fpm配置檔案

[root@localhost php-5.5.14]# /usr/local/php-5.5.0/sbin/php-fpm 

[root@localhost ~]# vi /etc/init.d/php-fpm

#!/bin/sh  

# chkconfig:   - 84 16   

# Source function library.  

. /etc/rc.d/init.d/functions  

# Source networking configuration.  

. /etc/sysconfig/network  

# Check that networking is up.  

[ "$NETWORKING" = "no" ] && exit 0  

phpfpm="/usr/local/php-5.5.0/sbin/php-fpm"  

prog=$(basename ${phpfpm})  

lockfile=/var/lock/subsys/phpfpm

start() {  

    [ -x ${phpfpm} ] || exit 5  

    echo -n $"Starting $prog: "  

    daemon ${phpfpm}

    retval=$?  

    echo  

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

    return $retval  

}  

stop() {  

    echo -n $"Stopping $prog: "  

    killproc $prog -QUIT  

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

restart() {  

    configtest || return $?  

    stop  

    start  

reload() {  

    echo -n $"Reloading $prog: "  

    killproc ${phpfpm} -HUP  

    RETVAL=$?  

force_reload() {  

    restart  

configtest() {  

  ${phpfpm} -t

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  

    restart|configtest)  

    reload)  

        rh_status_q || exit 7  

    status)  

        rh_status  

    *)  

        echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"  

        exit 2  

[root@localhost ~]# chmod +x /etc/init.d/php-fpm 

[root@localhost ~]# chkconfig php-fpm on

測試篇

修改/usr/local/nginx/conf/nginx.conf 配置檔案,需做如下修改

cd /usr/local/nginx/html/ #進入nginx預設網站根目錄

     43        location / {

     44             root   html;

     45             index  index.html index.htm ;

     46             fastcgi_pass 127.0.0.1:9000;

     47             fastcgi_index index.php;

     48             fastcgi_param SCRIPT_FILENAME     $document_root$fastcgi_script_name;

     49             include fastcgi_params;

     50 

     51         }

[root@localhost ~]# rm -rf /usr/local/nginx1.6.0/html/* #删除預設測試頁

[root@localhost ~]# vi index.php #建立index.php檔案

<?php

phpinfo();

?>

安裝mysql

[root@localhost media]yum install -y autoconf automake imake libxml2-devel expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr bison libtool ncurses5-devel  ncurses-devel

[root@localhost ~]# groupadd mysql #添加mysql組

[root@localhost ~]# useradd -g mysql mysql -s /bin/false #建立使用者mysql并加入到mysql組,不允許mysql使用者直接登入系統

[root@localhost ~]# mkdir -p /data/mysql #建立MySQL資料庫存放目錄

[root@localhost ~]# chown -R mysql:mysql /data/mysql #設定MySQL資料庫存放目錄權限

[root@localhost ~]# mkdir -p /usr/local/mysql #建立MySQL安裝目錄

[root@localhost media]# tar zxvf mysql-5.6.19.tar.gz 

[root@localhost mysql-5.6.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc 

[root@localhost media]# make && make install

root@localhost media]#rm -rf /etc/my.cnf #删除系統預設的配置檔案(如果預設沒有就不用删除)

[root@localhost ~]# cd /usr/local/mysql #進入MySQL安裝目錄

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系統資料庫

[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系統啟動

[root@localhost ~]# chmod 755 /etc/init.d/mysqld #增加執行權限

[root@localhost ~]# chkconfig mysqld on #加入開機啟動

[root@localhost ~]# vi /etc/rc.d/init.d/mysqld #編輯

46basedir=/usr/local/mysql #MySQL程式安裝路徑

47datadir=/data/mysql #MySQl資料庫存放目錄

 ps

ln -s /usr/local/mysql/bin/mysql /usr/bin

mysql_secure_installation  #設定Mysql密碼,根據提示按Y 回車輸入2次密碼

繼續閱讀