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:支持googlespdy,想了解請百度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)

        stop

        start

        ;;

status)

        status $prog

        RETVAL=$?

        ;;

*)

        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=$?  

    echo  

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

    return $retval  

}  

 

restart() {  

    configtest || return $?  

    stop  

    start  

}  

 

reload() {  

    configtest || return $?  

    echo -n $"Reloading $prog: "  

    killproc ${phpfpm} -HUP  

    RETVAL=$?  

    echo  

}  

 

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  

        $1  

        ;;  

    restart|configtest)  

        $1  

        ;;  

    reload)  

        rh_status_q || exit 7  

        $1  

        ;;  

    status)  

        rh_status  

        ;;  

    *)  

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

        exit 2  

esac

 

 

 

 

 

 

[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密碼,根據提示按回車輸入2次密碼

 

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章