1. 程式人生 > >搭建LNMP環境(CentOS 6)

搭建LNMP環境(CentOS 6)

步驟一:準備編譯環境

本文主要說明手動安裝LNMP平臺的操作步驟

1、系統版本說明

  1. # cat /etc/redhat-release
  2. 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。

圖片1

步驟二:安裝nginx

Nginx是一個小巧而高效的Linux下的Web伺服器軟體,是由 Igor Sysoev 為俄羅斯訪問量第二的 Rambler.ru 站點開發的,已經在一些俄羅斯的大型網站上執行多年,目前很多國內外的入口網站、行業網站也都在是使用Nginx,相當穩定。

1、新增執行nginx服務程序的使用者

  1. # groupadd -r nginx
  2. # useradd -r -g nginx nginx

2、下載原始碼包解壓編譯。

  1. # wget http://nginx.org/download/nginx-1.10.2.tar.gz
  2. # tar xvf nginx-1.10.2.tar.gz -C /usr/local/src
  3. # yum groupinstall "Development tools"
  4. # yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
  5. # cd /usr/local/src/nginx-1.10.2
  6. # ./configure \
  7. --prefix=/usr/local/nginx \
  8. --sbin-path=/usr/sbin/nginx \
  9. --conf-path=/etc/nginx/nginx.conf \
  10. --error-log-path=/var/log/nginx/error.log \
  11. --http-log-path=/var/log/nginx/access.log \
  12. --pid-path=/var/run/nginx.pid \
  13. --lock-path=/var/run/nginx.lock \
  14. --http-client-body-temp-path=/var/tmp/nginx/client \
  15. --http-proxy-temp-path=/var/tmp/nginx/proxy \
  16. --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
  17. --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  18. --http-scgi-temp-path=/var/tmp/nginx/scgi \
  19. --user=nginx \
  20. --group=nginx \
  21. --with-pcre \
  22. --with-http_v2_module \
  23. --with-http_ssl_module \
  24. --with-http_realip_module \
  25. --with-http_addition_module \
  26. --with-http_sub_module \
  27. --with-http_dav_module \
  28. --with-http_flv_module \
  29. --with-http_mp4_module \
  30. --with-http_gunzip_module \
  31. --with-http_gzip_static_module \
  32. --with-http_random_index_module \
  33. --with-http_secure_link_module \
  34. --with-http_stub_status_module \
  35. --with-http_auth_request_module \
  36. --with-mail \
  37. --with-mail_ssl_module \
  38. --with-file-aio \
  39. --with-ipv6 \
  40. --with-http_v2_module \
  41. --with-threads \
  42. --with-stream \
  43. --with-stream_ssl_module
  44. # make && make install
  45. # mkdir -pv /var/tmp/nginx/client

註釋:上面這段沒帶#的,我可是手動一行一行打的,不知道是不是正確的方式;

3、新增SysV啟動指令碼。

# vim /etc/init.d/nginx

註釋:下面這段可以直接複製過去(在PuTTY工具中,在編輯模式下點選滑鼠右鍵就貼上了)

  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemon
  4. #
  5. # chkconfig: - 85 15
  6. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
  7. # proxy and IMAP/POP3 proxy server
  8. # processname: nginx
  9. # config: /etc/nginx/nginx.conf
  10. # config: /etc/sysconfig/nginx
  11. # pidfile: /var/run/nginx.pid
  12. # Source function library.
  13. ./etc/rc.d/init.d/functions
  14. # Source networking configuration.
  15. ./etc/sysconfig/network
  16. # Check that networking is up.
  17. ["$NETWORKING"="no"]&& exit 0
  18. nginx="/usr/sbin/nginx"
  19. prog=$(basename $nginx)
  20. NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  21. [-f /etc/sysconfig/nginx ]&&./etc/sysconfig/nginx
  22. lockfile=/var/lock/subsys/nginx
  23. start(){
  24. [-x $nginx ]|| exit 5
  25. [-f $NGINX_CONF_FILE ]|| exit 6
  26. echo -n $"Starting $prog: "
  27. daemon $nginx -c $NGINX_CONF_FILE
  28. retval=$?
  29. echo
  30. [ $retval -eq 0]&& touch $lockfile
  31. return $retval
  32. }
  33. stop(){
  34. echo -n $"Stopping $prog: "
  35. killproc $prog -QUIT
  36. retval=$?
  37. echo
  38. [ $retval -eq 0]&& rm -f $lockfile
  39. return $retval
  40. killall -9 nginx
  41. }
  42. restart(){
  43. configtest ||return $?
  44. stop
  45. sleep 1
  46. start
  47. }
  48. reload(){
  49. configtest ||return $?
  50. echo -n $"Reloading $prog: "
  51. killproc