(LNMP) Nginx_PHP_MariaDB

来源:https://www.cnblogs.com/frx9527/archive/2019/12/28/npm.html
-Advertisement-
Play Games

L用的是Centos7.5以上,主要是NMP三組件的安裝記錄。 通常會先安裝一下依賴: yum install -y pcre-devel zlib-devel openssl-devel 使用yum或rpm方式安裝MariaDB # 保留緩存軟體包#sudo vim /etc/yum.conf c ...


L用的是Centos7.5以上,主要是NMP三組件的安裝記錄。

通常會先安裝一下依賴:

yum install -y pcre-devel zlib-devel openssl-devel

 

 

使用yum或rpm方式安裝MariaDB

# 保留緩存軟體包
#sudo vim /etc/yum.conf cachedir=/var/cache/yum/$basearch/$releasever keepcache=1

# 防火牆先關為敬
systemctl stop firewalld.service
systemctl disable firewalld.service


#------------------最簡單的 yum 安裝,預設版本5.5.64 -------------------------
yum install mariadb mariadb-server
systemctl start mariadb
netstat -nltp # 找3306
# vim /etc/my.cnf --[mysqld]下增加一行: 
innodb_file_per_table=1
systemctl restart mariadb

mysql

  use mysql;
  grant all PRIVILEGES on *.* to 'root'@'%' IDENTIFIED BY '123456' with grant option;
  grant all PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY '123456' with grant option;
  FLUSH PRIVILEGES;

 

# ------------離線下載安裝 rpm 的 5.5.64 版本--------------------------------- # https:
//mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-5.5.65/yum/centos74-amd64/rpms/ # https://mariadb.com/kb/en/library/installing-mariadb-with-the-rpm-tool/
# 可能要下載以下rpm包 MariaDB-client-5.5.65-1.el7.centos.x86_64.rpm MariaDB-client-debuginfo-5.5.65-1.el7.centos.x86_64.rpm MariaDB-server-debuginfo-5.5.65-1.el7.centos.x86_64.rpm MariaDB-devel-5.5.65-1.el7.centos.x86_64.rpm MariaDB-server-5.5.65-1.el7.centos.x86_64.rpm MariaDB-shared-5.5.65-1.el7.centos.x86_64.rpm MariaDB-test-5.5.65-1.el7.centos.x86_64.rpm MariaDB-common-5.5.65-1.el7.centos.x86_64.rpm MariaDB-compat-5.5.65-1.el7.centos.x86_64.rpm libzstd-1.3.4-1.el7.x86_64.rpm galera-25.3.26-1.rhel7.el7.centos.x86_64.rpm jemalloc-3.6.0-1.el7.x86_64.rpm jemalloc-devel-3.6.0-1.el7.x86_64.rpm rpm -Uvh --force --nodeps *.rpm #./bin/mysqladmin -u root password '123456' #./bin/mysqladmin -u root -h evxapp01 password '123456' #Alternatively you can run: #./bin/mysql_secure_installation ./bin/mysqld --defaults-file=/etc/my.cnf --user=mysql &
# 後續設置同上.


# ------------- 使用官方推薦的 yum 方式安裝 10.4.8 -----------------------------
# https://mariadb.com/kb/en/library/yum/

# 先得到倉庫

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
# 成功後, 編輯 /etc/yum.repos.d/mariadb.repo 更改一下 url 國內源. 比如清華,其它不改。如果網速夠快,可以不改。
[mariadb-main]
name = MariaDB Server
baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.4.8/yum/rhel/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
gpgcheck = 1
enabled = 1

[mariadb-maxscale]
# To use the latest stable release of MaxScale, use "latest" as the version
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version
name = MariaDB MaxScale
baseurl = https://mirrors.tuna.tsinghua.edu.cn/MaxScale/2.4/centos/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-MaxScale-GPG-KEY
gpgcheck = 1
enabled = 1

[mariadb-tools]
name = MariaDB Tools
baseurl = https://mirrors.tuna.tsinghua.edu.cn/Tools/rhel/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY
gpgcheck = 1
enabled = 1

 # 然後就可以直接 yum 安裝 10.4.8 了。因為上面的文件里寫的是 10.4.8 版本

yum install MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common
# 配置文件同上.
# 啟動 狀態 停止 重啟 開機啟動
systemctl start mariadb
systemctl status mariadb
systemctl stop mariadb
systemctl restart mariadb
systemctl enable mariadb
 

 

二進位程式包 tar 安裝 MariaDB 供參考:
(1) 準備用戶
    groupadd -r -g 306 mysql
    useradd -r -g 306 -u 306 -m -d /data/mysqldb mysql

(2) 準備數據目錄
    以/data/mysqldb為例,建議使用邏輯捲
    chown mysql:mysql /data/mysqldb
    chmod 700 /data/mysqldb

(3) 準備二進位程式
    tar xf mariadb-10.2.15-linux-x86_64.tar.gz -C /usr/local  #/usr/local是程式包指定的目錄,必須解壓在這裡
    cd /usr/local;ln -sv mariadb-10.2.15 mysql
    chown -R mysql:mysql /usr/local/mysql/

(4) 準備配置文件
    mkdir /etc/mysql/
    cp support-files/my-huge.cnf /etc/mysql/my.cnf
    #/usr/local/mysql/support-files下有很多my-*.cnf文件,分別對應不同的記憶體大小,可打開看看,選擇對應自己機器的拷貝就行
    vim /etc/mysql/my.cnf
    [mysqld]中添加三個選項:

        datadir = /data/mysqldb
        innodb_file_per_table = on  # 可不加
        skip_name_resolve = on  # 禁止主機名解析,建議使用,不加也可

(5) 創建資料庫文件
    cd /usr/local/mysql/
    ./scripts/mysql_install_db --datadir=/data/mysqldb --user=mysql

(6) 準備日誌文件
    touch /var/log/mysqld.log
    chown mysql:mysql /var/log/mysqld.log

(7) 準備服務腳本,並啟動服務
    cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
    chkconfig --add mysqld
    service mysqld start

(8) 安全初始化
    /usr/local/mysql/bin/mysql_secure_installation

(9) 添加環境變數
    echo PATH=/usr/local/mysql/bin:$PATH > /etc/profile.d/mysql.sh
    . /etc/profile.d/mysql.sh
    
    
mysql -uroot -p

-- use mysql;
-- grant all PRIVILEGES on *.* to 'root'@'%' IDENTIFIED BY '123456' with grant option;
-- grant all PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY '123456' with grant option;
-- FLUSH PRIVILEGES;

 

解決ibdata1體積太大問題

# 備份全部庫
mysqldump -uroot -p123456 --all-databases --add-drop-table > /opt/all.sql

# vim /etc/my.cnf --[mysqld]下增加一行: 
innodb_file_per_table=1 

# 重啟服務
systemctl restart mariadb

mysql -uroot -p123456 
show variables like '%per_table%';  -- 得到 ON 即開啟成功

# 刪除 ibdata1
cd /var/lib/mysql
rm -rf ib_logfile*
rm -rf ibdata1

# 重啟服務
systemctl restart mariadb

# 導入數據
mysql -uroot -p123456 < /opt/all.sql

 

安裝與配置nginx1.17.4

systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service

tar zxf nginx-1.17.4.tar.gz 
cd nginx-1.17.4/
./configure --prefix=/opt/nginx --with-openssl=/usr/bin/openssl
make & make install

vim /etc/profile

PATH=/opt/nginx/sbin:$PATH
export PATH

. /etc/profile

useradd nginx
passwd nginx 

cd /opt/
chown -R nginx:nginx nginx/

ln -s /opt/nginx/sbin/nginx /usr/bin/nginx
cd /

# 修改conf/nginx.conf 文件,並啟用PHP
user  nginx;
worker_processes  auto;

error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    use epoll;
    worker_connections  16384;
}


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

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

    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  65;
    types_hash_max_size 2048;

    server {
        listen       80;
        server_name  _;

        location / {
            root   html;
            index  index.html index.htm index.php;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}
su nginx
sudo nginx -t

# 啟用PHP解析後,如果瀏覽器出現 File not found . 需要檢查nginx.conf配置文件
# 可能需要將 $document_root 改成絕對路徑。例如下麵的配置就改成了/webapp/www
location ~* \.php$ {
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    /webapp/www$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }    

 

 

 

安裝與配置PHP7.2.22

cd /opt
tar zxf php-7.2.22.tar.gz
cd php-7.2.22

 

安裝依賴

yum install -y autoconf gcc gcc-c++ libxml2 libxml2-devel openssl openssl-devel \
    bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel \
    freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel \
    libxslt libxslt-devel

因為要安裝 MediaWiki, 所以再安裝依賴 APCu, icu, intl

# 下載 https://pecl.php.net/package/APCu
# 下載 https://github.com/unicode-org/icu 或者git 
# icu需要在php編譯之前安裝,成功後就可以在編譯PHP時直接使用。
tar xf icu4c-52_1-src.tgz
cd icu/source
mkdir /usr/local/icu
./configure --prefix=/usr/local/icu
make && make install
# PHP編譯時 --enable-intl --with-icu-dir=/usr/local/icu 
# 直接帶上intl擴展。


# apcu 需要在php安裝之後安裝。安裝完後需要重啟 php-fpm
tar zxf apcu-5.1.17.tgz 
cd apcu
-5.1.17
phpize #
/usr/local/php/bin/phpize
.
/configure --with-php-config=/usr/local/php/bin/php-config
make && make install
# /etc/php.ini中添加引用:
extension=apcu.so
apc.enabled=on
apc.shm_size=128M
apc.enable_cli=on
/etc/init.d/php-fpm restart

# 如果時編譯時沒有intl,事後安裝,則如下執行:
cd /opt/php-7.2.22/ext/intl
make clean
phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-intl --with-icu-dir=/usr/local/icu
make && make install

   

預編譯: 註意紅色的2項,需要在系統中添加對應的組和用戶,用於啟動php-fpm。 參數 with-config-file-path=/etc 則指定php.ini的位置 

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \ --enable-dom \
--enable-exif \ --enable-fileinfo \ --enable-filter \ --with-pcre-dir \ --enable-ftp \ --with-gd \ --with-openssl-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype-dir \ --enable-gd-jis-conv \ --with-gettext \ --with-gmp \ --with-mhash \ --enable-json \ --enable-mbstring \ --enable-mbregex \ --enable-mbregex-backtrack \ --with-libmbfl \ --with-onig \ --enable-pdo \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-zlib-dir \ --with-pdo-sqlite \ --with-readline \ --enable-session \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-wddx \ --with-libxml-dir \ --with-xsl \ --enable-zip \ --enable-mysqlnd-compression-support \ --with-pear \ --enable-opcache \
--enable-intl \
--with-icu-dir=/usr/local/icu

 

編譯如果出錯:

configure: error: off_t undefined; check your library configuration
解決:加入icu/lib路徑 
echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64 /usr/local/icu/lib' >> /etc/ld.so.conf
ldconfig -v

 

 安裝: 

make && make install

  

添加用戶和組,如果事先沒有此用戶的話:

groupadd nginx
useradd -g nginx

 

配置並啟動 php-fpm

vi /etc/profile

PATH=$PATH:/usr/local/php/bin
export PATH

source /etc/profile

cd /opt/php7.2.22   
cp php.ini-production /etc/php.ini
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
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

/etc/init.d/php-fpm start
/etc/init.d/php-fpm restart
/etc/init.d/php-fpm stop

 如果需要 opcache, 操作如下:

yum install -y php-pecl-zendopcache

# 修改配置文件 php.ini zend_extension
=opcache.so [opcache] opcache.enable=1 # 然後重啟php-fpm 和 nginx
/etc/init.d/php-fpm restart
nginx -s reload

# 最後用 phpinfo() 檢查

 

 

一個個安裝嫌煩的話, 開發環境也可以使用xampp包

./xampp-linux-x64-7.2.22-0-installer.run

cd /opt/lampp

./lampp security
# 依次設置安全選項.但是最後要手動啟用mysql的遠程連接 #在
/opt/lampp/etc/my.cnf 中註釋掉: #skip-networking

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

-Advertisement-
Play Games
更多相關文章
  • 大家好我又回來了,前幾天講過一個關於Jwt的身份驗證最簡單的案例,但是功能還是不夠強大,不適用於真正的項目,是的,在真正面對複雜而又苛刻的客戶中,我們會不知所措,就現在需要將認證授權這一塊也變的複雜而又實用起來,那在專業術語中就叫做自定義策略的API認證,本次案例運行在.NET Core 3.0中,... ...
  • 程式寫日誌文件時該不該加鎖 日誌(log) 為了讓自己的思路更加清晰,下麵我都會稱日誌為 log。因為日誌這個詞有兩種含義,詳情見百度百科釋義或者維基百科釋義。 日記的另一種說法。“志”字本身為“記錄”的意思,日誌就為每日的記錄(通常是跟作者有關的)。 伺服器日誌(server log),記錄伺服器 ...
  • 一、休眠概述 休眠,簡而言之就是設備在不需要工作的時候把一些部件、外設關掉(掉電或讓它進入低功耗模式)。 為什麼要休眠呢?一言以蔽之:省電。 休眠分主動休眠和被動休眠。主動休眠:比如我電腦不用了,就通過設置讓系統進入休眠模式;被動休眠:系統檢測到自己閑的慌,為了節約故,自己就休眠去了。 廢話不敘。 ...
  • 配置虛擬主機 vi /usr/local/apache2.4/conf/httpd.conf 搜索httpd-vhost,刪除行首#號 vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf <VirtualHost *:80> ServerAdmi ...
  • 碰到問題解決過程 剛在一個新的機器上裝node環境時,要用一個nrm管理鏡像源時。報了一個錯,如圖1 然後去網上查,說是許可權的問題,執行命令 可以解決問題。 然後我就按照操作做了,又報錯了。這次的錯誤如圖2: 錯誤說是具體策略覆蓋了剛更新的策略,程式仍然保持原有的執行策略。反正最終結果就是未生效唄, ...
  • 以下內容為使用樹莓派搭建伺服器的過程,因為個人還沒有搭建完成,所以僅更新出已完成的部分,至於未完成的部分,以後會持續更新。 具體分為這幾個階段: 1.給樹莓派安裝系統 2.使用電腦連接控並制樹莓派 3.配置網站伺服器環境 4.添加網站源碼 5.配置網站環境設置 【0x01:給樹莓派安裝系統】 我是用 ...
  • 在正式生產資料庫中,因為客戶現場管理不規範產生了一條錯誤數據,由於自身睡眠不佳加上客戶方言表達,將編號記錯,在沒有備份的情況下,直接連遠程資料庫執行了delete操作。 由於備份設置的是每日0點,當天晚上九點鐘的數據尚未進行備份,所以網上大多數基於備份文件的恢復就無法奏效。 上一篇博文(查詢數據... ...
  • 有些資料庫本身,會記錄所有歷史的SQL命令。比如:mysql和pgsql都有專門的log文本文件來存放所有歷史的SQL命令; 也有些資料庫在保存log文本的同時,還保留最近的N條SQL命令在資料庫里,以方便查詢。 SQL Server並沒有這樣的實現,只有sys.dm_exec... ...
一周排行
    -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.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...