41.部署LNMP平臺原始碼

技術小牛人發表於2017-11-21

原始碼部署LNMP

環境需求:關閉防火牆,設定靜態IP地址,部署YUM

# systemctl stop firewalld                  #關閉firewalld防火牆

# systemctl disable firewalld.service           #禁止firewalld服務自啟

# sed -i -e `s|SELINUX=enforcing|SELINUX=disabled|` /etc/selinux/config  #關閉SELINUX

# sed -i -e `s|SELINUXTYPE=targeted|#SELINUXTYPE=targeted|` /etc/selinux/config

#echo [a]     

name=a

baseurl=file:///run/media/root/CentOS 7 x86_64

gpgcheck=0   > /etc/yum.repos.d/a.repo       #部署YUM                         

# yum clean all                              #清除YUM快取

# yum makecache                            #重新生成YUM快取

# echo ‘TYPE=Ethernet                       

BOOTPROTO=static

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

IPV4_FAILURE_FATAL=no

NAME=eth0

DEVICE=eth0

ONBOOT=yes

IPADDR=1.1.1.1

NETMASK=255.255.255.0

GATEWAY=1.1.1.254

DNS1=202.96.134.133   > /etc/sysconfig/network-scripts/ifcfg-eth0 #修改靜態IP

 

部署MYSQL資料庫

# yum -y remove mariadb-server          #移除YUM版的MYSQL資料庫

# yum -y install bison gcc gcc-c++ cmake ncurses-devel  #安裝相關元件

# tar xzvf mysql-5.5.22.tar.gz                #解壓MYSQL壓縮包

# cd mysql-5.5.22/

# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all            #使用CMAKE檢查MYSQL

#make && make install                   #編譯安裝MYSQL資料庫

註釋:

-DCMAKE_INSTALL_PREFIX:指定安裝路徑

-DSYSCONFDIR:指定配置檔案路徑

-DDEFAULT_CHARSET:指定使用的語言編碼

-DDEFAULT_COLLATION:指定預設使用的語言編碼校驗

-DWITH_EXTRA_CHARSETS:指定可以使用其他的語言編碼

# useradd mysql                       #建立執行使用者

# chown -R mysql.mysql  /usr/local/mysql/  #授權安裝目錄

# unalias cp                             #開啟CP命令的強制

# cp  -f /usr/local/mysql/support-files/my-medium.cnf  /etc/my.cnf  #拷貝配置

# /usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data         #初始化MYSQL資料庫

# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld  #命令放入自啟目錄

# chkconfig –add mysqld            #新增自啟服務到chkconfig工具

# chkconfig mysqld on               #設定為開機自啟

# service mysqld start                #重啟MYSQL資料庫服務

# mysqladmin -u root password  123    設定ROOT使用者密碼

 

部署Nginx伺服器

# yum -y install pcre-devel zlib-devel      #安裝相關元件

# useradd -M -s /sbin/nologin nginx       #建立執行使用者

# tar xzvf nginx-1.6.0.tar.gz               #解壓Nginx壓縮包

# cd nginx-1.6.0                     

#./configure –prefix=/usr/local/nginx –user=nginx –group=nginx –with-http_stub_status_module            #檢查Nginx包完整性

# make && make install                    #編譯並安裝Nginx

 

部署PHP伺服器

# yum -y install gd libxml2-devel libjpeg-devel libpng-devel bzip2 #安裝相關元件

# tar xjvf php-7.1.0.tar.bz2                                #解壓PHP壓縮包

# cd php-7.1.0

# ./configure –prefix=/usr/local/php –with-gd –with-zlib –with-mysql=/usr/local/mysql –with-config-file-path=/usr/local/php –enable-mbstring –enable-fpm –with-jpeg-dir=/usr/lib

#make && make install                                #編譯安裝PHP

# cp php.ini-production  /usr/local/php/php.ini            #拷貝PHP配置檔案

# cp /usr/local/php/etc/php-fpm.conf.default   /usr/local/php/etc/php-fpm.conf

# cp /usr/local/php/etc/php-fpm.d/www.conf.default   /usr/local/php/etc/php-fpm.d/www.conf                  #拷貝PHP測試頁面配置檔案     

# useradd -M -s /sbin/nologin php                        #建立執行使用者

 

PHP加速模組安裝方法,下面版本只適用於PHP5.3,想要支援PHP7請下載高版本。

# tar xzvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz

# cp ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so  /usr/local/php/lib/php/                               #拷貝加速模組到PHP指定目錄

# echo `zend_extension=/usr/local/php/lib/php/ZendGuardLoader.so` >>  /usr/local/php/php.ini

# echo `zend_loader.enable=1` >> /usr/local/php/php.ini     #新增加速PHP模組

 

配置LNMP環境變數

# echo “PATH=$PATH:/usr/local/mysql/bin” >> /etc/profile  #設定環境變數

# echo “PATH=$PATH:/usr/local/nginx/sbin” >> /etc/profile

# echo “PATH=$PATH:/usr/local/php/sbin” >> /etc/profile

#source /etc/profile

 

配置Nginx支援PHP解析

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

 location / {

            root   html;

            index index.php index.html index.htm;    #新增index.php首先解析

        }

  

location ~ .php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;          #呼叫本機的php-fpm程式

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;

            include        fastcgi_params;

        }

#vim /usr/local/nginx/html/index.php

新增內容:

<?php

phpinfo ();                              #PHP測試頁面

?>

啟動PHPNginx服務

# php-fpm

# nginx

# netstat -lnupt |grep 3306

# netstat -lnupt |grep 80

# netstat -lnupt |grep php-fpm

 

故障排查:解決PHP頁面解析出現找不到檔案故障

# sed -i -e `s|;cgi.fix_pathinfo=1|cgi.fix_pathinfo=1`  /usr/local/php/php.ini 

本文轉自   觸動的風   51CTO部落格,原文連結:http://blog.51cto.com/10978134/1945763




相關文章