Linux LNMP架構搭建

一.搭建LNMP基本架構php

1.L(http) N(nginx) M(mysql) P(php)html

2.安裝順序 Mysql-->PHP-->Nginxmysql

3.安裝包linux

Discuz_3.2.0_SC_GBK
nginx
-1.4.4 httpd-2.4.27 php-5.3.22
mysql-5.6.38-linux-glibc2.12-i686

4.安裝mysql數據庫nginx

(1)解壓mysql壓縮包sql

  tar zxvf mysql.tar.gz                             數據庫

 

(2)將mysql目錄移動/usr/下。vim

  mv mysql目錄 /usr/local/mysql             api

 

(3)在mysql目錄下,建立目錄,做爲datadir(數據目錄)架構

  mkdir /data/mysql                                 

 

(4)建立mysql用戶,不容許登錄,不建立家目錄。

  useradd -s /sbin/nologin -M mysql         

 

(5)將/data/mysql/目錄所屬組所屬主給mysql用戶。

  chown -R mysql:mysql /data/mysql/         

 

(6)將配置文件存放到/etc/my.conf覆蓋。

  cp /mysql目錄/support-files/my-large.cnf /etc/my.cnf

    

(7)修改配置文件

  vim進入/etc/my.conf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld] port = 3306
socket          = /usr/local/mysql/mysql.sock
datadir      = /data/mysql
pid-file = /data/mysql/mysql.pid
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
------------------------------------------
經常使用參數:

Port                               #監聽端口

Socket                             #通訊方式

Key_buffer_size                   #mysql內存使用大小

Log-bin=mysql-bin               #記錄二進制日誌,註釋掉。

Binlog_format=mixed            #日誌相關參數,註釋掉。

Server_id=1                 #主從複製參數,註釋掉。

(8)將服務的啓動腳本放入/etc/init.d/下。

  cp /mysql目錄/support-files/mysql.server /etc/init.d/mysqld

  

(9)修改啓動文件。

  vi /etc/init.d/mysqld    

# The following variables are only set for letting mysql.server find things.

# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
 basedir=/usr/local/mysql    
  bindir=/usr/local/mysql/bin
mysqld_pid_file_path=/data/mysql/master.pid
------------------------------------------ basedir  #定義程序所在路徑 bindir    #定義數據庫啓動路徑

 

(10)在mysql目錄下初始化mysql服務,看到兩個ok就沒問題。

  mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

報錯1:Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
    解決:yum install –y libai*

報錯2:Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
    解決:yum install –y numactl-*
(10)報錯

 

(11)查看是否生成mysql,test。

  mysql]# ls /data/mysql       

 

(12)啓動mysql。

  mysql]# /etc/init.d/mysqld start 

報錯1:Starting MySQL.... ERROR! The server quit without updating PID file (/data/mysql/localhost.localdomain.pid).
    解決:[root@localhost ~]# cd /usr/local/mysql 
             [root@localhost mysql]# chown -R mysql.mysql . 
(12)報錯

 

(13)查看mysql進程。

  ps aux|grep mysql 

 

(14)開啓mysql命令終端Mysql>。

  /usr/local/mysql/bin/mysql  

報錯1:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
    解決:ln -s  /usr/local/mysql/mysql.sock           /tmp/mysql.sock
(14)報錯
報錯1:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
    解決:ln -s  /usr/local/mysql/mysql.sock           /tmp/mysql.

 

(15)設置開機自啓動

  chkconfig --list | grep mysql         #查看是否存在mysql服務。

  chkconfig --add mysqld      #添加mysqld服務

  chkconfig mysqld on      #打開開機自啓動

  /usr/local/mysql/bin/mysql

  注:測試啓動mysql

 

(16)添加環境變量賦值。可以使用mysql命令直接啓動。在當前終端生效。

PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

  [root]# mysql        #測試登錄

 

(17)設置全部終端均可訪問。

  vim /etc/profile

#文件最下面輸入
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

  source /etc/profile  #即時生效

  

(18)設置mysql管理員密碼。

  mysqladmin -uroot password ’123456‘

  mysql -u root -p  #登錄 

  注:再次登錄應輸入管理員,與密碼。

 

(19)mysql下添加普通用戶賦予管理權限,對應主機,與密碼。

  mysql> grant all on *.* to 'user1'@'localhost' identified by 'discuz';

 

5.安裝PHP

(1)解壓php壓縮包。

  tar xvzf php-5.3.22.tar.gz

 

(2)建立PHP禁止登錄用戶。

  useradd -s /sbin/nologin php-fpm

 

(3)進入php目錄下。

  cd php-5.3.22

(4)編譯安裝PHP。

  php-5.3.22]#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multbyte --disable-ipv6 --with-pear --with-curl

yum -y install gcc
yum -y install  libxml2-devel*
yum -y install  bzip2-devel*
yum -y install  curl curl-devel
yum -y install  libjpeg-devel
yum -y install  openssl-devel*
yum -y install  freetype-devel*
yum -y install libpng-devel
yum -y install  libmcrypt-devel* 
#沒有安裝包須要下載源碼包
#安裝編譯包
注:若是報錯可同過 yum list | grep 報錯名 :來查找須要安裝的包

  php-5.3.22]#make      #編譯

  php-5.3.22]#make install   #編譯安裝

 

(5)拷貝php配置文件。

  php-5.3.22]#cp php.ini-production /usr/local/php/etc/php.ini

 

(6)修改PHP配置文件,將off改成on。

  vim /usr/local/php/etc/php.ini

short_open_tag = on

 



(6)拷貝啓動腳本。

  php-5.3.22]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

 

(7)賦予php-fpm文件權限。

  chmod 755 /etc/init.d/php-fpm

(8)啓動php服務。

  /etc/init.d/php-fpm start

報錯1:ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
    解決:進入/usr/local/php/etc/
            cp php-fpm.conf.default php-fpm.conf
(8)報錯

 

(9)查看PHP進程。

  ps aux | grep php

注:Ss是主進程  S是子進程

   

(10)查看PHP監聽端口。

注:查看監聽端口9000

 

6.安裝nginx 

(1)解壓Nginx壓縮包。

  tar xvzf nginx-1.4.4.tar.gz

 

(2)進入Nginx目錄。

  cd nginx-1.4.4

 

(3)Nginx編譯安裝

  nginx-1.4.4]#./configure --prefix=/usr/local/nginx --with-pcre

報錯1:error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
        解決:yum install -y pcre-devel
(3)報錯

  make       #編譯

  make install    #編譯安裝

 

(4)啓動Nginx程序

  nginx-1.4.4]# /usr/local/nginx/sbin/nginx

(5)查看Nginx進程

   ps aux | grep nginx 

 

 (6)關閉防火牆,SELINUX

  service iptables stop

  getenforce 0

 

(7)測試Nginx

 

 

 二.論壇安裝

1.Nginx配置文件調試

(1)調試Nginx主配置文件

  vim /usr/local/nginx/conf/nginx.conf

#user nobody;
worker_processes  1;

#error_log logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  4096;  #處理的鏈接數
}


http {
    include       mime.types;
    default_type  application/octet-stream;

 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

  #access_log logs/access.log main;

    sendfile        on;
   #tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout  65;

    #gzip on;
  
    server {             #虛擬主機   
        listen       80;  
        server_name  localhost;

       #charset koi8-r;

        #access_log  logs/host.access.log main;
    

        location / {              #配置網站所在的路徑
            root   /usr/local/url;      #網站根目錄
            index  index.html index.htm index.php;   #首頁索引類型
        }

       #error_page 404              /404.html;

        # redirect server error pages to the static page /50x.html #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 #

    keepalive_timeout  65;

    #gzip on;

    server {
        listen       80;
        server_name  localhost;

       #charset koi8-r;

        #access_log  logs/host.access.log  main;
        location / {
            root   /usr/local/url;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
     #解開註釋調用php
        location ~ \.php$ {
            root           /usr/local/url;        #網站路徑(修改)
            fastcgi_pass   127.0.0.1:9000;  #指定通訊代理(可改成soket)
            fastcgi_index  index.php;     #
指定主頁索引頁
            fastcgi_param  SCRIPT_FILENAME  /usr/local/usl$fastcgi_script_name; #腳本所在路徑 (修改)
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #

 

 

 

(2)測試Nginx配置文件

  /usr/local/nginx/sbin/nginx -t

  注:yntax is ok 沒問題!

 

(3)加載配置文件

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

 

2.安裝論壇網站

(1)解壓論壇文件包。

  unzip Discuz_X3.2_SC_GBK.zip

 

(2)建立網站根目錄。

  mkdir /usr/local/url

 

(3)將網站程序移動到網站目錄下。

  mv uplocad/*  /usr/local/url

 

(4)刪除多餘文件。

  rm -rf upload/ utility/ readme/

 

(5)權限修改。

  ps aux | grep nginx

  注:nginx執行用戶位nobody用戶,而網站文件是root用戶,則沒有權限執行

   chown -R nobody config/ data uc_client/data uc_server/data

  注:修改網站文件目錄的執行用戶,-R遞歸目錄下的子目錄。

 

(6)安裝論壇

相關文章
相關標籤/搜索