23uyut 发表于 2016-5-18 08:53:04

LNMP环境搭建(基于zabbix监控软件)

安装依赖包:

yum -y install pcrepcre-developenssl openssl-devel

安装nginx

# tar zxvf nginx-1.6.0.tar.gz

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



# make

# make install

启动:

# /usr/local/nginx-1.6.0/sbin/nginx

关闭:

# /usr/local/nginx-1.6.0/sbin/nginx -s stop

加载配置文件:

# /usr/local/nginx-1.6.0/sbin/nginx -s reload

开机启动:

# 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

# chmod +x /etc/init.d/nginx#执行权限

chkconfig nginx on #设置开机启动

安装依赖包

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



安装php

# tar zxvf php-5.5.14.tar.gz

# ./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



# make&& make install

# cp php.ini-production /usr/local/php-5.5.0/etc/php.ini #复制php配置文件到安装目录

# cp /usr/local/php-5.5.0/etc/php-fpm.conf.default /usr/local/php-5.5.0/etc/php-fpm.conf#拷贝模板文件为php-fpm配置文件



启动:

# /usr/local/php-5.5.0/sbin/php-fpm

开机启动:

# 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













# chmod +x /etc/init.d/php-fpm

# chkconfig php-fpm on





测试篇

修改/usr/local/nginx/conf/nginx.conf 配置文件,需做如下修改

cd /usr/local/nginx/html/ #进入nginx默认网站根目录

   43      location / {

   44             root   html;

   45             indexindex.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         }

# rm -rf /usr/local/nginx1.6.0/html/* #删除默认测试页

# vi index.php #新建index.php文件



<?php

phpinfo();

?>



安装mysql

安装依赖包:

yum install -y autoconf automake imake libxml2-devel expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr bison libtool ncurses5-develncurses-devel





# groupadd mysql #添加mysql组

# useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统

# mkdir -p /data/mysql #创建MySQL数据库存放目录

# chown -R mysql:mysql /data/mysql #设置MySQL数据库存放目录权限

# mkdir -p /usr/local/mysql #创建MySQL安装目录



# tar zxvf mysql-5.6.19.tar.gz

# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc

# make && make install

root@localhost media]#rm -rf /etc/my.cnf #删除系统默认的配置文件(如果默认没有就不用删除)

# cd /usr/local/mysql #进入MySQL安装目录

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系统数据库

# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动

# chmod 755 /etc/init.d/mysqld #增加执行权限

# chkconfig mysqld on #加入开机启动

# 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次密码









wblw0909 发表于 2016-7-11 18:51:32

{:6_430:}
页: [1]
查看完整版本: LNMP环境搭建(基于zabbix监控软件)