搭建LNMP環境(CentOS 6)
阿新 • • 發佈:2018-12-30
步驟一:準備編譯環境
本文主要說明手動安裝LNMP平臺的操作步驟
1、系統版本說明
# cat /etc/redhat-release
CentOS release 6.5(Final)
注:這是本文件實施時參考的系統版本。您的實際使用版本可能與此不同,下文中的nginx,mysql,及php版本,您也可以根據實際情況選擇相應版本。
2、關閉SELINUX
修改配置檔案,重啟服務後永久生效。
# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
命令列設定立即生效。
# setenforce 0
3、安全組設定
在ECS安全組放行需訪問的埠和訪問白名單,下面的示例表示允許所有IP訪問伺服器的80埠。您可以根據實際情況放行允許訪問的客戶端IP。
步驟二:安裝nginx
Nginx是一個小巧而高效的Linux下的Web伺服器軟體,是由 Igor Sysoev 為俄羅斯訪問量第二的 Rambler.ru 站點開發的,已經在一些俄羅斯的大型網站上執行多年,目前很多國內外的入口網站、行業網站也都在是使用Nginx,相當穩定。
1、新增執行nginx服務程序的使用者
groupadd -r nginx
useradd -r -g nginx nginx
2、下載原始碼包解壓編譯。
# wget http://nginx.org/download/nginx-1.10.2.tar.gz
# tar xvf nginx-1.10.2.tar.gz -C /usr/local/src
# yum groupinstall "Development tools"
# yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
# cd /usr/local/src/nginx-1.10.2
# ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module
# make && make install
# mkdir -pv /var/tmp/nginx/client
註釋:上面這段沒帶#的,我可是手動一行一行打的,不知道是不是正確的方式;
3、新增SysV啟動指令碼。
# vim /etc/init.d/nginx
註釋:下面這段可以直接複製過去(在PuTTY工具中,在編輯模式下點選滑鼠右鍵就貼上了)
- #!/bin/sh
#
# 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: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/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
killall -9 nginx
}
restart(){
configtest ||return $?
stop
sleep 1
start
}
reload(){
configtest ||return $?
echo -n $"Reloading $prog: "
killproc