分離部署LNMP架構

来源:https://www.cnblogs.com/Their-own/archive/2022/10/11/16779758.html
-Advertisement-
Play Games

分離部署LNMP 環境說明: | 系統 | 主機名 | IP | 服務 | | | | | | | centos8 | nginx | 192.168.111.141 | nginx | | centos8 | mysql | 192.168.111.142 | mysql | | centos8 ...


分離部署LNMP

目錄

環境說明:

系統 主機名 IP 服務
centos8 nginx 192.168.111.141 nginx
centos8 mysql 192.168.111.142 mysql
centos8 php 192.168.111.143 php

部署nginx

//修改名字
[root@localhost ~]# hostnamectl set-hostname nginx
[root@localhost ~]# bash
[root@nginx ~]# 

//關閉防火牆和selinux
[root@nginx ~]# setenforce 0
[root@nginx ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@nginx ~]# systemctl disable --now firewalld
[root@nginx ~]# reboot

//配置yum源
[root@nginx ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@nginx ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//創建用戶
[root@nginx ~]# useradd -rMs /sbin/nologin nginx

//安裝依賴包
[root@nginx ~]# dnf -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget vim

//創建日誌存放目錄
[root@nginx ~]# mkdir -p /var/log/nginx
[root@nginx ~]# chown -R nginx.nginx /var/log/nginx

//下載nginx包並解壓
[root@nginx ~]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@nginx ~]# tar xf nginx-1.20.2.tar.gz 

//進行編譯安裝
[root@nginx ~]# cd nginx-1.20.2
[root@nginx nginx-1.20.2]# ./configure \
 --prefix=/usr/local/nginx \
 --user=nginx \
 --group=nginx \
 --with-debug \
 --with-http_ssl_module \
 --with-http_realip_module \
 --with-http_gunzip_module \
 --with-http_gzip_static_module \
 --with-http_stub_status_module
[root@nginx nginx-1.20.2]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

//配置環境變數
[root@nginx ~]# echo "export PATH=$PATH:/usr/local/nginx/sbin" > /etc/profile.d/nginx.sh
[root@nginx ~]# source /etc/profile.d/nginx.sh
                
//配置system啟動服務
[root@nginx ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx server daemon
After=network.target 
 
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/bin/kill -HUP \$MAINPID
 
[Install]
WantedBy=multi-user.target

//啟動nginx
[root@nginx ~]# systemctl enable --now nginx
[root@nginx ~]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@nginx ~]# ss -anlt
State        Recv-Q       Send-Q               Local Address:Port               Peer Address:Port       Process       
LISTEN       0            128                        0.0.0.0:80                      0.0.0.0:*                        
LISTEN       0            128                        0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0            128                           [::]:22                         [::]:*                        

image

部署mysql

//修改名字
[root@localhost ~]# hostnamectl set-hostname mysql
[root@localhost ~]# bash
[root@mysql ~]# 

//關閉防火牆
[root@mysql ~]# setenforce 0
[root@mysql ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@mysql ~]# systemctl disable --now firewalld

//配置yum源
[root@mysql ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@mysql ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//創建用戶
[root@mysql ~]# useradd -rMs /sbin/nologin mysql

//下載依賴包
[root@mysql ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs

//下載mysql包並解壓
[root@mysql ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@mysql ~]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

//修改包名,更改屬主屬組
[root@mysql ~]# cd /usr/local/
[root@mysql local]# mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
[root@mysql local]# chown -R mysql.mysql mysql*
[root@mysql local]# ll -d mysql/
drwxr-xr-x. 9 mysql mysql 129 Oct 11 13:42 mysql/

//配置環境變數
[root@mysql local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@mysql local]# source /etc/profile.d/mysql.sh

//創建頭文件
[root@mysql local]# ln -s /usr/local/mysql/include /usr/include/mysql

//添加幫助文檔
[root@mysql local]# vim /etc/man_db.conf 
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/mysql/man

//創建庫文件
[root@mysql ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib/
[root@mysql ~]# ldconfig 

//創建數據存放路勁
[root@mysql ~]# mkdir -p /opt/data
[root@mysql ~]# chown -R mysql.mysql /opt/data/
[root@mysql ~]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 Oct 11 13:48 /opt/data/

//初始化資料庫
[root@mysql ~]# mysqld --initialize --user mysql --datadir /opt/data/
2022-10-11T05:49:31.198902Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-10-11T05:49:31.347232Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-10-11T05:49:31.366252Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-10-11T05:49:31.427201Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7a1816e2-4928-11ed-a649-000c29074265.
2022-10-11T05:49:31.428093Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-10-11T05:49:31.649647Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-10-11T05:49:31.649663Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-10-11T05:49:31.649960Z 0 [Warning] CA certificate ca.pem is self signed.
2022-10-11T05:49:31.695538Z 1 [Note] A temporary password is generated for root@localhost: h.#agi;KB7%t		//臨時密碼
[root@mysql ~]# echo 'h.#agi;KB7%t' > pass

//編寫配置文件
[root@mysql ~]# dnf -y remove mariadb*
[root@mysql ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve

//編寫system控制腳本
[root@mysql ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
After=network.target 

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@mysql ~]# systemctl daemon-reload

//設置開機自啟
[root@mysql ~]# systemctl enable --now mysqld
[root@mysql ~]# ss -anlt
State        Recv-Q       Send-Q               Local Address:Port               Peer Address:Port       Process       
LISTEN       0            128                        0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0            80                               *:3306                          *:*                        
LISTEN       0            128                           [::]:22                         [::]:*                       
//設置mysql密碼
[root@mysql ~]# cat pass 
h.#agi;KB7%t
[root@mysql ~]# mysql -uroot -p'h.#agi;KB7%t'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye

//修改後驗證
[root@mysql ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

部署php

//修改名字
[root@localhost ~]# hostnamectl set-hostname php
[root@localhost ~]# bash
[root@php ~]# 

//關閉防火牆和selinux
[root@php ~]# setenforce 0
[root@php ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@php ~]# systemctl disable --now firewalld

//配置yum源
[root@php ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@php ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//安裝依賴包
[root@php ~]# yum -y install gcc gcc-c++ glibc automake autoconf libtool make
[root@php ~]# yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel 
[root@php ~]# yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel 
[root@php ~]# yum -y install glibc glibc-devel glib2 bzip2-devel ncurses ncurses-devel 
[root@php ~]# yum -y install curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel 
[root@php ~]# yum -y install openssl openssl-devel sqlite-devel libcurl-devel libpng-devel libjpeg-devel 
[root@php ~]# yum -y install freetype-devel libicu-devel libxslt-devel
[root@php ~]# yum -y install systemd-devel
[root@php ~]# yum -y install oniguruma oniguruma-devel
[root@php ~]# yum -y install gmp-devel
[root@php ~]# yum -y install net-snmp-devel
[root@php ~]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@php ~]# yum -y install libsqlite3x-devel libzip-devel

//下載PHP包並解壓
[root@php ~]# wget https://www.php.net/distributions/php-8.1.11.tar.gz
[root@php ~]# tar xf php-8.1.11.tar.gz

//編譯安裝
[root@php ~]# cd php-8.1.11
[root@php php-8.1.11]# ./configure --prefix=/usr/local/php8 \
--with-config-file-path=/usr/local/php8/etc \
--enable-fpm \
--enable-mysqlnd \
--with-mysqli \
--with-pdo-mysql \
--enable-opcache \
--with-pcre-jit \
--enable-gd \
--with-jpeg \
--with-freetype \
--with-gettext \
--with-curl \
--with-openssl \
--enable-sockets \
--enable-mbstring \
--enable-xml \
--with-zip \
--with-zlib \
--with-snmp \
--with-mhash \
--enable-ftp \
--enable-bcmath \
--enable-soap \
--enable-shmop \
--enable-sysvsem \
--enable-pcntl \
--with-gmp

//顯示這個表示沒問題了
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

[root@php php-8.1.11]# make && make install

//配置環境變數
[root@php ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php8.sh
[root@php ~]# source /etc/profile.d/php8.sh

//配置php-fpm
[root@php ~]# cd php-8.1.11
[root@php php-8.1.11]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@php php-8.1.11]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@php php-8.1.11]# chmod +x /etc/rc.d/init.d/php-fpm
[root@php php-8.1.11]# cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@php php-8.1.11]# cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf

//啟動php-fpm
[root@php ~]# service php-fpm start
Starting php-fpm  done
[root@php ~]# ss -anlt
State        Recv-Q       Send-Q               Local Address:Port               Peer Address:Port       Process       
LISTEN       0            128                        0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0            128                      127.0.0.1:9000                    0.0.0.0:*                        
LISTEN       0            128                           [::]:22                         [::]:*                      

安裝後配置

php端配置

//修改配置文件
[root@php ~]# vim /usr/local/php8/etc/php-fpm.d/www.conf
listen = 192.168.111.143:9000		//修改為php本機IP

listen.allowed_clients = 192.168.111.141	//允許指定ip訪問

//在php端上配置網站
[root@php ~]# mkdir -p /var/www/html
[root@php ~]# vim /var/www/html/index.php
<?php
    phpinfo();
?>

//重啟php-fpm服務
[root@php ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@php ~]# ss -anlt
State        Recv-Q       Send-Q               Local Address:Port               Peer Address:Port       Process       
LISTEN       0            128                        0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0            128                192.168.111.143:9000                    0.0.0.0:*                        
LISTEN       0            128                           [::]:22                         [::]:*                        

nginx伺服器端

//修改配置文件
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
#查找index
        location / {
            root   html;
            index  index.php index.html index.htm;		//添加index.php
        }
        
#大概65-71行,取消註釋
 location ~ \.php$ {
            root           /var/www/html;			//指向php端index.php文件位置
            fastcgi_pass   192.168.111.143:9000;	//ip地址為php伺服器地址
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;		//將/scripts更改為$document_root
            include        fastcgi_params;
        }


//重啟服務
[root@nginx ~]# systemctl restart nginx

瀏覽器訪問

image


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 文章的添加 博客園打開需要拷貝的文章,右鍵檢查--》選擇cnblogs_post_body這一個div,然後複製outer HTML到admin後臺文章表裡面 最後需要在文章詳情頁的文章內容那一行添加一個|safe 點贊點踩製作 前端樣式: 不會寫,直接拷貝博客園的點贊點踩html和css樣式 {# ...
  • 泛型除了KTV,還有一個讓人比較疑惑的玩意,而且它就是用來表達疑惑的:? 雖然通過泛型已經達到我們想要的效果了,例如: List<String> list = new ArrayList<String>(); 這樣就可以放心地存取String類型的數據。 但是(抱歉,凡事總有個但是),應用的場景總是 ...
  • 現在的關係型資料庫例如PostgreSQL/MySQL, 都已經對 JSON 類型提供相當豐富的功能, 項目中對於不需要檢索但是又需要結構化的存儲, 會在資料庫中產生很多 JSON 類型的欄位, 與 Jackson 做對象的序列化和反序列化配合非常方便. 如果 JSON 在 Java 代碼中是定義為... ...
  • 目錄 什麼是應用服務雪崩 雪崩效應產生的幾種場景 緩存雪崩的解決方案 雪崩的整體解決方案 熔斷設計 隔離設計 超時機制設計 如何提前發現雪崩 什麼是應用服務雪崩 雪崩問題 分散式系統都存在這樣一個問題,由於網路的不穩定性,決定了任何一個服務的可用性都不是 100% 的。當網路不穩定的時候,作為服務的 ...
  • 一、前言 MyBatis 創建時的一個思想是:資料庫不可能永遠是你所想或所需的那個樣子。 我們希望每個資料庫都具備良好的第三範式或 BCNF 範式,可惜它們並不都是那樣。 如果能有一種資料庫映射模式,完美適配所有的應用程式,那就太好了,但可惜也沒有。 而 ResultMap 就是 MyBatis 對 ...
  • > cat /etc/kylin-build Kylin-Desktop V10-SP1 Build 20220316 > cat /etc/.kyinfo [dist] name=Kylin milestone=Desktop-V10-SP1-General-RC6-Build21-2203 ar ...
  • 一:背景 1.講故事 最近分享了好幾篇關於 非托管記憶體泄漏 的文章,有時候就是這麼神奇,來求助的都是這類型的dump,一飲一啄,莫非前定。讓我被迫加深對 NT堆, 頁堆 的理解,這一篇就給大家再帶來一篇記憶體泄漏。 前段時間有位朋友找到我,說他的程式出現了非托管泄漏,某一塊的操作會導致非托管記憶體上漲的 ...
  • 三台虛擬主機搭建lnmp 環境說明: |主機說明| ip| 安裝服務| | : | : : | : | |nginx |192.168.222.137 |nginx| |mysql| 192.168.222.138 |mysql| |php |192.168.222.139 |php| 阿裡雲官網 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...