主頁 > 軟體設計 > LNMP專案部署

LNMP專案部署

2021-10-05 07:55:31 軟體設計

LNMP專案部署

介紹

專案的生命周期

  • 策劃:老板+產品+UI設計
  • 實施:前端開發(客戶端頁面)+后端開發(ava php python等)+測驗
  • 上線:運維
  • 維護:運維
  • 結束

運維作業內容

  • 專案策劃,實施之初,進行準備作業,學習對應架構和方案
  • 服務器上搭建代碼版本控制器
  • 為測驗人員搭建測驗環境
  • 部署專案上線
  • 專案后期維護

分布式集群

  • 集群:多臺服務器在一起作同樣的事

  • 分布式 :多臺服務器在一起作不同的事

  • 常用架構

    • 負債均衡LB
    • 高可用HA
    • 資料庫主從復制M-S
    • 讀寫分離R-W
    • 快取中間件:memcached、Redis
    • 非關系型資料庫:mongodb

在這里插入圖片描述

專案背景

  • 年份:2021
  • 發布產品型別:互聯網動態站點 社區論壇 商城 社交類站點
  • 用戶數量:100-500
  • PV:頁面訪問數量,點擊量,1000-3000(24小時訪問次數總和)
  • QPS:并發量,吞吐量,5-10(每秒訪問查詢次數)
    • 計算:pv/時間 = qps
    • 壓測:使用ab等并發測驗軟體,在規定時間發送一定的請求數量
  • TPS:每秒事務次數,5-10
  • RPS:每秒請求次數,5-10
  • DAU:每榷訓躍用戶數,榷訓數,10-50

軟體架構

  • C/S client/server
  • B/S browser/server

不管是C還是B,都是屬于前端客戶端

運維人員主要負責和管理的是server端,也統稱為服務器端

  • LAMP:Linux+Apache+MySQL+PHP
  • LNMP:Linux+Nginx+MySQL+PHP
  • LNMPA:Linux+Nginx+MySQL+PHP+Apache
  • LNMT:Linux+Nginx+MySQL+Tomcat

在這里插入圖片描述

環境準備

最小化安裝centOs6.9

安裝vim
[root@server02 ~]# yum install -y vim
已加載插件:fastestmirror
設定安裝行程
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
錯誤:Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again

報錯:Cannot retrieve repository metadata (repomd.xml) for repository: base.

原因:CentOS6已經在2020年11月30日停止維護了,centos官方停止了對centos6的所有更新,并且下架了包括官方所有的centos6源,目前阿里、163、清華等centos6源已無法使用

解決:如下

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
vi /etc/yum.repos.d/CentOS-Base.repo
#撰寫
[centos-office]
name=centos-office
failovermethod=priority
baseurl=https://vault.centos.org/6.10/os/x86_64/
gpgcheck=1
gpgkey=https://vault.centos.org/6.10/os/x86_64/RPM-GPG-KEY-CentOS-6

yum list
yum install -y vim

配置vim
echo "set nu" >> /root/.vimrc
echo "set ts=4" >> /root/.vimrc

sed -i "8calias grep='grep --color'" /root/.bashrc
source /root/.bashrc

關閉防火墻
service iptables stop
chkconfig iptables off

setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config

修改主機名
vim /etc/sysconfig/network
#修改為
HOSTNAME=server01
su

域名決議
vim /etc/hosts
#追加
192.168.139.128 server01.lnmp.com server01

時間同步
yum -y install ntp
service ntpd start
chkconfig ntpd on
ntpdate cn.ntp.org.cn

LNMP部署

MySQL安裝

編譯引數的說明

編譯引數說明
-DCMAKE_INSTALL_PREFIX安裝到的軟體目錄
-DMYSQL_DATADIR資料檔案存盤的路徑
-DSYSCONFDIR組態檔路徑 (my.cnf)
-DENABLED_LOCAL_INFILE=1使用localmysql客戶端的配置
-DWITH_PARTITION_STORAGE_ENGINE使mysql支持分表
-DEXTRA_CHARSETS安裝支持的字符集
-DDEFAULT_CHARSET默認字符集使用 這里配置為utf8mb4
-DDEFAULT_COLLATION連接字符集
-DWITH_SSL開啟mysql的ssl使用

初始化引數說明

初始化引數說明
–basedir安裝到的軟體目錄
–datadir資料檔案存盤路徑
–usermysql使用的用戶

腳本安裝及其初始化

[root@server01 ~]# yum install -y lrzsz
[root@server01 ~]# mkdir /root/soft
[root@server01 ~]# cd /root/soft
[root@server01 soft]# rz
#傳入mysql-5.6.33.tar.gz軟體包

[root@server01 ~]# vim mysql_install.sh

#!/bin/bash
#原始碼編譯安裝MySQL
mysql_install() {
	#1、創建用戶
`id mysql` &>/dev/null
[ $? -ne 0 ] && useradd -s /sbin/nologin -M mysql
#2、解決依賴
yum install -y cmake ncurses-devel
#3、編譯安裝
cd /root/soft
tar zxvf mysql-5.6.33.tar.gz
cd mysql-5.6.33
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_SSL=bundled
make && make install
#組態檔
rm -rf /etc/my.cnf
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
#授權并初始化資料庫
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#配置服務、自啟動和環境變數
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld start
chkconfig --add mysqld
echo 'PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
#洗掉匿名用戶
#設定root域名的密碼
rpm -qa|grep expect
if [ $? -ne 0 ];then
   yum -y install expect
fi
#匯入環境變數PATH
export PATH=/usr/local/mysql/bin:$PATH
#初始化root密碼 洗掉匿名用戶
echo '#!/usr/bin/expect
set timeout 60
spawn mysql_secure_installation
expect {
"enter for none" { send "\r"; exp_continue}
"Y/n" { send "Y\r" ; exp_continue}
"password" { send "123456\r"; exp_continue}
"Cleaning up" { send "\r"}
}
interact ' > mysql_secure_installation.exp
chmod +x mysql_secure_installation.exp
./mysql_secure_installation.exp
}
#腳本開始時間
start_time=`date +%s`
#執行的腳本代碼
mysql_install
#腳本結束時間
end_time=`date +%s`
#腳本執行花費時間
const_time=$((end_time-start_time))
echo 'Take time is: '$const_time's'

[root@server01 ~]# sh mysql_install.sh 

Nginx安裝

介紹

官網

http://nginx.org/

在這里插入圖片描述

功能
  • web服務器 httpd http協議

同類的web服務器軟體:apache,nginx(俄羅斯),IIS(微軟 fastcgi),lighttpd(德國)

  • 代理服務器 反向代理
  • 郵箱代理服務器 IMAP POP3 SMTP
  • 負載均衡功能 LB loadblance
特點(優點)
  • 高可靠:穩定性高,一個master多個worker,master行程用于管理調度請求分發到哪一個worker行程,worker行程用于回應請求,當其中一個worker行程出現問題,master會調度其他worker行程
  • 熱部署 :(1)平滑升級 ;(2)可以快速多載配置
  • 高并發:可以同時回應更多的請求 ,達到幾萬的并發量,基于事件epoll模型
  • 回應快:尤其在處理靜態檔案上,回應速度很快 ,內核基于sendfile機制
  • 低消耗:cpu和記憶體占用低,建立開銷1w個請求 ,記憶體只消耗2-3MB
  • 分布式支持 :反向代理,七層負載均衡

安裝

  • 編譯引數說明
引數作用
–prefix編譯安裝到的軟體目錄
–userworker行程運行用戶
–groupworker行程運行用戶組
–with-http_ssl_module支持https,需要pcel-devel依賴
–with-http_stub_status_module基本狀態資訊顯示,查看請求數、連接數等
–with-http_realip_module定義客戶端地址和埠為header頭資訊
用于反向代理后的真實IP獲取
[root@server01 ~]# cd /root/soft/
[root@server01 soft]# rz
#傳入下載好的 nginx-1.14.2軟體包
[root@server01 soft]# tar -xzf nginx-1.14.2.tar.gz 
[root@server01 soft]# ls
mysql-5.6.33         mysql_secure_installation.exp  nginx-1.14.2.tar.gz
mysql-5.6.33.tar.gz  nginx-1.14.2
[root@server01 nginx-1.14.2]# useradd -s /sbin/nologin -M www
[root@server01 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module

報錯:./configure: error: the HTTP rewrite module requires the PCRE library.

原因:缺少pcre-devel依賴庫

解決:yum install -y pcre-devel

[root@server01 nginx-1.14.2]# yum install -y pcre-devel
[root@server01 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module

報錯:./configure: error: SSL modules require the OpenSSL library.

原因:缺少openssl-devel依賴庫

解決:yum install -y openssl-devel

[root@server01 nginx-1.14.2]# yum install -y openssl-devel
[root@server01 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

[root@server01 nginx-1.14.2]# make && make install
[root@server01 nginx-1.14.2]# cd /usr/local/nginx/
[root@server01 nginx]# pwd
/usr/local/nginx

腳本安裝(提前將軟體包下載到/root/soft):

#!/bin/bash
#編譯安裝Nginx
nginx_install(){
#創建軟體運行用戶
`id www` &>>/dev/null
if [ $? -ne 0 ];then
   useradd -s/sbin/nologin -M www
fi
#安裝依賴
yum -y install pcre-devel zlib-devel openssl-devel
#編譯安裝
cd /root/soft
tar xvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module && make && make install
}
#腳本開始時間
start_time=`date +%s`
#執行的腳本代碼
nginx_install
#腳本結束時間
end_time=`date +%s`
#腳本執行花費時間
const_time=$((end_time-start_time))
echo 'Take time is: '$const_time's'

初始化

[root@server01 nginx-1.14.2]# cd /usr/local/nginx/
[root@server01 nginx]# ls
conf  html  logs  sbin
[root@server01 nginx]# cd sbin/
[root@server01 sbin]# ls
nginx
目錄作用
conf組態檔
html網站根目錄
logs日志
sbin可執行檔案 [軟體的啟動,停止,重啟等]
啟動nginx
[root@server01 sbin]# ./nginx 
[root@server01 sbin]# ss -tnalp|grep nginx
LISTEN     0      128                       *:80                       *:*      users:(("nginx",34295,6),("nginx",34296,6))
[root@server01 sbin]# ps -ef |grep nginx
root   34295     1 0 17:57 ?  00:00:00 nginx: master process ./nginx
www    34296 34295 0 17:57 ?  00:00:00 nginx: worker process
root   34304  3419 0 17:57 pts/0 00:00:00 grep --color nginx

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-pvRlavDz-1633274276799)(…/%E5%9B%BE%E7%89%87%E6%94%BE%E7%BD%AE%E7%82%B9/image-20211002180101979.png)]

引數介紹(#后面的了解即可,不常用)
[root@server01 sbin]# ./nginx -h
nginx version: nginx/1.14.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help 幫助
  -v            : show version and exit #版本查看
  -V            : show version and configure options then exit查看版本和配置選項
  -t            : test configuration and exit 檢測組態檔語法
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing #在配置測驗期間禁止顯示非錯誤資訊
  -s signal     : send signal to a master process: stop, quit, reopen, reload  stop強制退出  quit優雅的退出  reopen重開日志   reload多載配置
  -p prefix     : set prefix path (default: /usr/local/nginx/) #設定nginx目錄
  -c filename   : set configuration file (default: conf/nginx.conf) #指定啟動使用的組態檔
  -g directives : set global directives out of configuration file
  • nginx編譯包里默認沒有服務啟動腳本模板,可以通過官方社區獲得https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/
服務配置
[root@server01 ~]# cd /etc/init.d/
[root@server01 init.d]# rz
#傳入已經下載的nginx腳本
[root@server01 init.d]# chmod +x nginx 

開啟
[root@server01 init.d]# service nginx start
[root@server01 init.d]# chkconfig --add nginx
[root@server01 init.d]# chkconfig nginx on

PHP安裝

介紹

  • PHP: Hypertext Preprocessor,超文本前處理器

    • HTML:超文本標記語言
    • HTTP:超文本傳輸協議
  • 頁面分類:

    • 靜態頁面 一般普通訪問到的頁面

    • 動態頁面 用戶可以和服務器進行互動頁面

    • 執行動態頁面,需要和服務器進行互動,使用后端語言進行開發,php可實作該功能

在這里插入圖片描述

  • PHP是一種通用開源腳本語言,混合了C、Java、Perl以及PHP自創的語法,主要適用于Web開發

  • PHP是將程式嵌入到HTML(標準通用標記語言下的一個應用)檔案中去執行,執行效率比完全生成HTML標記的CGI要高許多

  • PHP還可以執行編譯后代碼,編譯可以達到加密和優化代碼運行,使代碼運行更快

  • PHP-FPM(FastCGI Process Manager:FastCGI行程管理器),PHP-FPM提供了更好的PHP行程管理方式,可以有效控制記憶體和行程、可以平滑多載PHP配置,在./configure的時候帶 –enable-fpm引數即可開啟PHP-FPM

安裝

[root@server01 init.d]# cd /root/soft/
[root@server01 soft]# rz
[root@server01 soft]# ls
mysql-5.6.33  mysql-5.6.33.tar.gz  mysql_secure_installation.exp  nginx-1.14.2  nginx-1.14.2.tar.gz  php-7.2.12.tar.gz
[root@server01 soft]# tar -xzf php-7.2.12.tar.gz 
[root@server01 soft]# cd php-7.2.12

解決依賴(可忽略下文因依賴報錯的部分)
[root@server01 php-7.2.12]# yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel

配置
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

報錯:configure: error: libxml2 not found. Please check your libxml2 installation.

原因:缺少依賴庫libxml2

解決:yum install -y libxml2-devel

[root@server01 php-7.2.12]# yum install -y libxml2-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

報錯:configure: error: cURL version 7.10.5 or later is required to compile php with cURL support

原因:缺少curl依賴庫

解決:yum install -y curl-devel

[root@server01 php-7.2.12]# yum install -y curl-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

報錯:configure: error: jpeglib.h not found.

原因:缺少libjpeg依賴庫

解決:yum install -y libjpeg-devel

[root@server01 php-7.2.12]# yum install -y libjpeg-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

報錯:configure: error: png.h not found.

原因:缺少libpng依賴庫

解決:yum install -y libpng-devel

[root@server01 php-7.2.12]# yum install -y libpng-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

報錯:configure: error: freetype-config not found.

原因:缺少freetype依賴庫

解決:yum install -y freetype-devel

[root@server01 php-7.2.12]# yum install -y freetype-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

編譯安裝
[root@server01 php-7.2.12]# make && make install

[root@server01 php-7.2.12]# cd /usr/local/php/
[root@server01 php]# ls
bin  etc  include  lib  php  sbin  var
目錄名稱作用
binphp相關命令目錄,php 、phpize、php-config在原始碼編譯擴展時用
etc組態檔
includephp默認類別庫
libphp第三方擴展類別庫
phpman檔案檔案
sbinphp-fpm執行檔案
varlog日志目錄 ;run運行目錄 ;保存pid檔案

初始化

使組態檔生效
[root@server01 php]# cd etc
[root@server01 etc]# ls
php-fpm.conf.default  php-fpm.d
[root@server01 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server01 etc]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
[root@server01 etc]# ls
php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@server01 etc]# cp /root/soft/php-7.2.12/php.ini-development /usr/local/php/etc/php.ini
#組態檔說明
php.ini			默認php組態檔
php-fpm.conf	php-fpm相關的配置 

啟動php
[root@server01 etc]# cd ../sbin/
[root@server01 sbin]# ./php-fpm

選項說明
[root@server01 sbin]# ./php-fpm -h
Usage: php-fpm [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>] [-D] [-F [-O]]
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -h               This help
  -i               PHP information
  -m               Show compiled in modules
  -v               Version number
  -p, --prefix <dir>
                   Specify alternative prefix path to FastCGI process manager (default: /usr/local/php).
  -g, --pid <file>
                   Specify the PID file location.
  -y, --fpm-config <file>
                   Specify alternative path to FastCGI process manager config file.
  -t, --test       Test FPM configuration and exit
  -D, --daemonize  force to run in background, and ignore daemonize option from config file
  -F, --nodaemonize
                   force to stay in foreground, and ignore daemonize option from config file
  -O, --force-stderr
                   force output to stderr in nodaemonize even if stderr is not a TTY
  -R, --allow-to-run-as-root
                   Allow pool to run as root (disabled by default)

添加到啟動服務中
[root@server01 php-7.2.12]# cp /root/soft/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@server01 php-7.2.12]# chmod +x /etc/init.d/php-fpm
[root@server01 php-7.2.12]# chkconfig --add php-fpm
[root@server01 php-7.2.12]# chkconfig --list

添加環境變數
[root@server01 php-7.2.12]# echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile
[root@server01 php-7.2.12]# source /etc/profile

上述步驟均可使用腳本代替

#!/bin/bash
php_install(){
#php編譯安裝
#和nginx使用相同的用戶,如果沒有就創建
`id www` &> /dev/null
[ $? -ne 0 ] && useradd -s /sbin/nologin -M www
#解決依賴
yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel
#解壓
tar xvf php-7.2.12.tar.gz
cd php-7.2.12
#編譯安裝php
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts && make && make install
#組態檔初始化
cp php.ini-development /usr/local/php/etc/php.ini
#php-fpm服務組態檔
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#php-fpm服務子組態檔
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
#配置服務及其環境變數
cp /root/soft/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
service php-fpm start
chkconfig --add php-fpm
echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile
}
#腳本開始時間
start_time=`date +%s`
#執行的腳本代碼
php_install
#腳本結束時間
end_time=`date +%s`
#腳本執行花費時間
const_time=$((end_time-start_time))
echo 'Take time is: '$const_time's'

Nginx+php-fpm配置

撰寫測驗檔案
[root@server01 php-7.2.12]#  vim /usr/local/nginx/html/index.php
<?php
	phpinfo();

修改組態檔
[root@server01 php-7.2.12]# vim /usr/local/nginx/conf/nginx.conf

 41         #access_log  logs/host.access.log  main;
 42 root html; 第一步:把root變數提升上層
 43         location / {
 44             #root   html; 這里的root需要被注釋掉
 45             index  index.html index.htm;
 46         }
 47 
 48         #error_page  404              /404.html;
 49 
 50         # redirect server error pages to the static page /50x.html
 51         #
 52         error_page   500 502 503 504  /50x.html;
 53         location = /50x.html {
 54             root   html;
 55         }
 56 
 57         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 58         #
 59         #location ~ \.php$ {
 60         #    proxy_pass   http://127.0.0.1;
 61         #}
 62 
 63         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 64         #
 65         location ~ \.php$ { 第二步:該段解注釋
 66         #    root           html; 默認使用上層的root變數,這里也要注釋掉
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 第三步:把script修改為$document_root 
 70             include        fastcgi_params;
 71         } 注意,不要忘記最后這個括號
 72 
root@server01 php-7.2.12]# service nginx configtest
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server01 php-7.2.12]# service nginx reload
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
重新載入 nginx:                                           [確定]

測驗

在這里插入圖片描述

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/305407.html

標籤:其他

上一篇:計算機網路概述(1)基本概念、因特網組成與三種交換方式、計算機網路的分類

下一篇:Linux之無人值守安裝系統

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 面試突擊第一季,第二季,第三季

    第一季必考 https://www.bilibili.com/video/BV1FE411y79Y?from=search&seid=15921726601957489746 第二季分布式 https://www.bilibili.com/video/BV13f4y127ee/?spm_id_fro ......

    uj5u.com 2020-09-10 05:35:24 more
  • 第三單元作業總結

    1.前言 這應該是本學期最后一次寫作業總結了吧。總體來說,對作業的節奏也差不多掌握了,作業做起來的效率也更高了。雖然和之前的作業一樣,作業中都要用到新的知識,但是相比之前,更加懂得了如何利用工具以及資料。雖然之間卡過殼,但總體而言,這幾次作業還算完成的比較好。 2.作業程序總結 相比前兩個單元,此單 ......

    uj5u.com 2020-09-10 05:35:41 more
  • 北航OO(2020)第四單元博客作業暨課程總結博客

    北航OO(2020)第四單元博客作業暨課程總結博客 本單元作業的架構設計 在本單元中,由于UML圖具有比較清晰的樹形結構,因此我對其中需要進行查詢操作的元素進行了包裝,在樹的父節點中存盤所有孩子的參考。考慮到性能問題,我采用了快取機制,一次查詢后盡可能快取已經遍歷過的資訊,以減少遍歷次數。 本單元我 ......

    uj5u.com 2020-09-10 05:35:48 more
  • BUAA_OO_第四單元

    一、UML決議器設計 ? 先看下題目:第四單元實作一個基于JDK 8帶有效性檢查的UML(Unified Modeling Language)類圖,順序圖,狀態圖分析器 MyUmlInteraction,實際上我們要建立一個有向圖模型,UML中的物件(元素)可能與同級元素連接,也可與低級元素相連形成 ......

    uj5u.com 2020-09-10 05:35:54 more
  • 6.1邏輯運算子

    邏輯運算子 1. && 短路與 運算式1 && 運算式2 01.運算式1為true并且運算式2也為true 整體回傳為true 02.運算式1為false,將不會執行運算式2 整體回傳為false 03.只要有一個運算式為false 整體回傳為false 2. || 短路或 運算式1 || 運算式2 ......

    uj5u.com 2020-09-10 05:35:56 more
  • BUAAOO 第四單元 & 課程總結

    1. 第四單元:StarUml檔案決議 本單元采用了圖模型決議UML。 UML檔案可以抽象為圖、子圖、邊的邏輯結構。 在實作中,圖的節點包括類、介面、屬性,子圖包括狀態圖、順序圖等。 采用了三次遍歷UML元素的方法建圖,第一遍遍歷建點,第二、三次遍歷設定屬性、連邊,實作圖物件的初始化。這里借鑒了一些 ......

    uj5u.com 2020-09-10 05:36:06 more
  • 談談我對C# 多型的理解

    面向物件三要素:封裝、繼承、多型。 封裝和繼承,這兩個比較好理解,但要理解多型的話,可就稍微有點難度了。今天,我們就來講講多型的理解。 我們應該經常會看到面試題目:請談談對多型的理解。 其實呢,多型非常簡單,就一句話:呼叫同一種方法產生了不同的結果。 具體實作方式有三種。 一、多載 多載很簡單。 p ......

    uj5u.com 2020-09-10 05:36:09 more
  • Python 資料驅動工具:DDT

    背景 python 的unittest 沒有自帶資料驅動功能。 所以如果使用unittest,同時又想使用資料驅動,那么就可以使用DDT來完成。 DDT是 “Data-Driven Tests”的縮寫。 資料:http://ddt.readthedocs.io/en/latest/ 使用方法 dd. ......

    uj5u.com 2020-09-10 05:36:13 more
  • Python里面的xlrd模塊詳解

    那我就一下面積個問題對xlrd模塊進行學習一下: 1.什么是xlrd模塊? 2.為什么使用xlrd模塊? 3.怎樣使用xlrd模塊? 1.什么是xlrd模塊? ?python操作excel主要用到xlrd和xlwt這兩個庫,即xlrd是讀excel,xlwt是寫excel的庫。 今天就先來說一下xl ......

    uj5u.com 2020-09-10 05:36:28 more
  • 當我們創建HashMap時,底層到底做了什么?

    jdk1.7中的底層實作程序(底層基于陣列+鏈表) 在我們new HashMap()時,底層創建了默認長度為16的一維陣列Entry[ ] table。當我們呼叫map.put(key1,value1)方法向HashMap里添加資料的時候: 首先,呼叫key1所在類的hashCode()計算key1 ......

    uj5u.com 2020-09-10 05:36:38 more
最新发布
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:20:47 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:20:25 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:20:17 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:20:10 more
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:19:44 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:19:07 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:18:57 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:18:49 more
  • 05單件模式

    #經典的單件模式 public class Singleton { private static Singleton uniqueInstance; //一個靜態變數持有Singleton類的唯一實體。 // 其他有用的實體變數寫在這里 //構造器宣告為私有,只有Singleton可以實體化這個類! ......

    uj5u.com 2023-04-19 08:42:51 more
  • 【架構與設計】常見微服務分層架構的區別和落地實踐

    軟體工程的方方面面都遵循一個最基本的道理:沒有銀彈,架構分層模型更是如此,每一種都有各自優缺點,所以請根據不同的業務場景,并遵循簡單、可演進這兩個重要的架構原則選擇合適的架構分層模型即可。 ......

    uj5u.com 2023-04-19 08:42:41 more