当前位置: 首页 > news >正文

Centos8 系統Lnmp服務器環境搭建

Centos8 系統Lnmp服務器環境搭建

服務器環境 Centos8

[root@centos8 ~]# uname -a
Linux centos8 4.18.0-348.el8.x86_64 #1 SMP Tue Oct 19 15:14:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

# 更新軟件包列表
root@debian:~# dnf update

安裝信息

  • PHP 版本8.2.27

https://www.php.net/distributions/php-8.2.27.tar.gz

  • Nginx 版本 1.26.0

https://nginx.org/download/nginx-1.26.0.tar.gz

  • Mariadb 版本 10.6.21

https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.6.21/source/mariadb-10.6.21.tar.gz

https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.6.21/bintar-linux-systemd-x86_64/mariadb-10.6.21-linux-systemd-x86_64.tar.gz

操作步驟

  • 下載安裝包
 # Mariadb下載
 wget -c https://mirrors.thzhost.com/mariadb/mariadb-10.6.21/bintar-linux-systemd-x86_64/mariadb-10.6.21-linux-systemd-x86_64.tar.gz
 wget -c https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.6.21/source/mariadb-10.6.21.tar.gz
 # PHP下載
 wget -c  https://www.php.net/distributions/php-8.2.27.tar.gz
 # Nginx下載
 wget -c https://nginx.org/download/nginx-1.26.0.tar.gz

下面是AI列出的各个扩展和库文件的作用解析,通常这些库和开发包是用来编译 PHP 的不同功能模块或扩展的。

  1. gcc 和 gcc-c++
    作用: GCC 是 GNU 编译器集合的缩写,是 Linux 下的主要编译器之一。gcc 用于编译 C 程序,gcc-c++ 用于编译 C++ 程序。在编译 PHP 或其他程序时,这两个工具是必不可少的。
  2. make
    作用: make 是一个自动化构建工具,通常用于编译源代码时,自动根据依赖关系生成目标文件。在 PHP 编译过程中,make 会根据源代码的变化自动选择哪些文件需要重新编译。
  3. autoconf
    作用: autoconf 用于自动生成配置脚本。在编译 PHP 或其他程序时,autoconf 会根据系统环境自动生成配置脚本,以便能够适配不同的系统。
  4. bzip2-devel
    作用: 提供 bzip2 压缩工具的开发库。它允许 PHP 使用 bzip2 格式压缩和解压缩文件。
  5. libxml2-devel
    作用: libxml2 是一个流行的 XML 解析库,libxml2-devel 提供开发所需的头文件和库文件。PHP 中的 XML 扩展依赖于这个库,用于处理 XML 数据。
  6. libpng-devel
    作用: libpng 是一个用于操作 PNG 格式图像的库。libpng-devel 提供了开发用的头文件,PHP 的 GD 扩展和图像处理功能可能依赖此库来处理 PNG 图片。
  7. libjpeg-devel
    作用: libjpeg 是一个处理 JPEG 图像的库,libjpeg-devel 提供了开发用的头文件。PHP 的 GD 扩展会用到这个库来处理 JPEG 格式的图像。
  8. libXpm-devel
    作用: libXpm 是一个 X Pixmap 图像格式库,libXpm-devel 提供了开发用的头文件。PHP 的 GD 扩展也可能使用此库来处理 XPM 图像格式。
  9. libicu-devel
    作用: libicu 是国际化和本地化的库,支持多种语言的字符编码转换和日期时间格式化。libicu-devel 提供开发所需的头文件。PHP 的 intl 扩展使用这个库来处理国际化问题,例如时区转换、数字格式化等。
  10. libmcrypt-devel
    作用: libmcrypt 是一个提供加密算法的库。libmcrypt-devel 提供了开发所需的头文件。它通常被用来加密和解密数据,但需要注意,libmcrypt 已被许多现代库所取代,如 OpenSSL。
  11. libxslt-devel
    作用: libxslt 是 XSLT(可扩展样式表语言转换)处理的库,libxslt-devel 提供开发所需的头文件。PHP 的 XSLT 扩展依赖此库,用于转换 XML 文档。
  12. re2c
    作用: re2c 是一个快速的 C 语言正则表达式引擎,主要用于生成高效的正则表达式匹配代码。它被用于 PHP 的某些模块(如 mbstring)的编译。
  13. libzip-devel
    作用: libzip 是用于处理 ZIP 文件格式的库,libzip-devel 提供了开发用的头文件。PHP 的 zip 扩展依赖此库来压缩和解压 ZIP 格式文件。
  14. curl-devel
    作用: libcurl 是一个支持多种协议(如 HTTP、FTP 等)的数据传输库,curl-devel 提供了开发所需的头文件。PHP 的 curl 扩展依赖此库,允许 PHP 使用各种协议进行数据传输,尤其是 HTTP 请求。
  15. libssl-devel
    作用: libssl 是 OpenSSL 加密库,提供加密算法、SSL/TLS 协议的实现。libssl-devel 提供开发所需的头文件,PHP 使用 OpenSSL 库来支持安全协议(如 HTTPS),以及加密和解密操作。
  16. libpng-devel (重复)
    作用: 已经解释过,这个包提供支持 PNG 图像格式的库。重复出现,应该只是偶然。
    总结
    这些库和开发包都是在编译 PHP 时,启用各种功能或扩展所必须的。例如:

图像处理功能:libpng-devel、libjpeg-devel、libXpm-devel、libgd。
网络和加密功能:libcurl-devel、libssl-devel、libmcrypt-devel。
国际化和字符编码:libicu-devel、re2c。
文件处理功能:libzip-devel、bzip2-devel。
这些库的安装和配置能确保你在 PHP 环境中使用到各种扩展和功能。

# 安裝擴展
dnf groupinstall "Development Tools"   # 安装开发工具集
dnf install -y gcc gcc-c++ make autoconf bzip2-devel libxml2-devel libpng-devel libjpeg-devel libXpm-devel libicu-devel libmcrypt-devel libxslt-devel re2c libzip-devel curl-devel libjpeg-devel libpng-devel libXpm-devel libxml2-devel libicu-devel libssl-devel libpng-devel libmcrypt-devel libcurl-devel libxslt-devel libjpeg-devel libpng-devel libzip-devel

這些安裝包大多數是開發過程中常用的工具和庫,特別是用於構建和編譯 PHP、網絡應用、數據庫、加密、圖像處理等多種功能的應用程序
dnf install epel-releasednf update 以便安装一些不在默认仓库中的包:

  • 编译软件前先用户/用户组和工程目录构建(可以根据自己项目需求创建)
# 創建www用戶組 和www用戶(取消登錄權限)
groupadd www
useradd -s /sbin/nologin -M -g www www
# 創建web工程目錄和設定相關目錄權限
mkdir -p /home/wwwroot/default
chown -R www:www /home/wwwroot
mkdir -p /home/wwwlogs
chown -R www:www /home/wwwlogs
  • 先安裝PHP

# 解壓php安裝包
tar -zxvf php-8.2.18.tar.gz
# 進入php安裝目錄
cd php-8.2.18 
# 構建工程
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear   --with-jpeg --with-freetype --with-zlib --enable-xml --disable-rpath --enable-bcmath --with-curl --enable-mbregex --enable-mbstring  --enable-gd --with-openssl  --with-mhash  --enable-sockets --with-zip   --enable-opcache  --with-webp --disable-fileinfo


# 指定執行編譯,指定操作方式-并發執行,提高執行效率
make -j $(nproc)
# 安裝
make install

這些是用於構建和安裝 PHP 的 ./configure 命令參數。每個參數控制 PHP 的某些特性或擴展功能。以下是這些參數的解釋:

  • 構建php工程參數説明

    1. –prefix=/usr/local/php
      指定 PHP 的安裝目錄。PHP 將被安裝到 /usr/local/php 目錄中。
    2. –with-config-file-path=/usr/local/php/etc
      設定 PHP 配置文件(php.ini)的存放路徑。此處將配置文件存放於 /usr/local/php/etc 目錄。
    3. –with-config-file-scan-dir=/usr/local/php/conf.d
      設定 PHP 用來載入額外配置的目錄。這個參數指定 PHP 在啟動時會從 /usr/local/php/conf.d 目錄載入其他 .ini 配置文件。
    4. –enable-fpm
      啟用 PHP 的 FastCGI Process Manager (FPM)。這使得 PHP 可以作為 FastCGI 進程池來處理 HTTP 請求,通常用於 Web 伺服器,如 Nginx 和 Apache。
    5. –with-fpm-user=www
      設定 FPM 進程運行的用戶。這裡設為 www 用戶,這是常見的 Web 伺服器用戶。
    6. –with-fpm-group=www
      設定 FPM 進程運行的用戶組。這裡設為 www 組。
    7. –enable-mysqlnd
      啟用 MySQL Native Driver (mysqlnd),這是一個 PHP 用來與 MySQL 進行通信的高效擴展,取代了原有的 MySQL 客戶端庫。
    8. –with-mysqli=mysqlnd
      使用 mysqlnd 驅動來支持 MySQL 的 mysqli 擴展。這使得 PHP 可以更高效地與 MySQL 數據庫互動。
    9. –with-pdo-mysql=mysqlnd
      使用 mysqlnd 驅動來支持 MySQL 的 PDO(PHP Data Objects)擴展。PDO 提供了一個統一的方式來訪問不同類型的數據庫。
    10. –with-pear
      啟用 PEAR(PHP Extension and Application Repository),這是一個 PHP 擴展和應用程序庫,允許安裝 PHP 類庫和工具。
    11. –with-jpeg
      啟用 JPEG 圖像處理支持。PHP 將能夠處理 JPEG 格式的圖像,通常與 GD 擴展一起使用。
    12. –with-freetype
      啟用 FreeType 字體支持。這使得 PHP 能夠處理使用 FreeType 字體庫的圖像操作。
    13. –with-zlib
      啟用 zlib 支持,用於處理壓縮文件,像是 .gz 格式的文件。它也是很多 Web 應用程序中常見的壓縮庫。
    14. –enable-xml
      啟用 XML 支持。這使得 PHP 能夠處理 XML 文件和數據,並支持各種 XML 相關的函數和擴展。
    15. –disable-rpath
      禁用 rpath,這通常是與動態鏈接庫相關的一個設置。這可以防止在系統中安裝 PHP 時不必要地設置庫的搜尋路徑。
    16. –enable-bcmath
      啟用 BCMath 擴展,這是一個用於高精度數學計算的庫。它支持大數字運算,對於需要處理非常大數字的應用很有用。
    17. –with-curl
      啟用 cURL 支持。cURL 是一個強大的命令行工具和庫,支持多種協議(如 HTTP、FTP、SMTP 等),使得 PHP 可以發送 HTTP 請求並與遠程伺服器交互。
    18. –enable-mbregex
      啟用多字節字符正則表達式(mbregex)支持,這對於處理包含非 ASCII 字符(如中文、日文等)的字符串非常有用。
    19. –enable-mbstring
      啟用多字節字符串擴展(mbstring),這是處理多字節字符編碼(如 UTF-8、EUC-JP 等)的常用工具。
    20. –enable-gd
      啟用 GD 圖像處理庫。GD 是一個用來處理圖像的庫,支持創建、修改圖像文件,支持多種格式,如 JPEG、PNG、GIF 等。
    21. –with-openssl
      啟用 OpenSSL 擴展,這是支持 SSL 和 TLS 加密的庫,使得 PHP 可以進行加密操作和安全的網絡通信。
    22. –with-mhash
      啟用 MHASH 擴展,這是用於加密和哈希計算的庫,支持多種哈希算法。
    23. –enable-sockets
      啟用 Socket 擴展,這使得 PHP 可以進行低級的網絡通信,並支持 TCP/IP 協議、UDP 等。
    24. –with-zip
      啟用對 ZIP 文件的支持,使 PHP 能夠創建、讀取和修改 .zip 壓縮文件。
    25. –enable-opcache
      啟用 OPCache。OPCache 是 PHP 的一個字節碼緩存機制,能夠提高 PHP 腳本的執行效率,減少解析和編譯的時間。
    26. –with-webp
      啟用 WebP 圖像格式支持。WebP 是一種新型的圖片格式,具有更好的壓縮性能。
    27. –disable-fileinfo
      禁用 Fileinfo 擴展。Fileinfo 擴展通常用於檢測文件類型,禁用此擴展可減少 PHP 的啟動時間和占用的內存。
      總結:
      這些參數的組合設置了 PHP 安裝的各種功能和擴展,包括數據庫支持、圖像處理、加密、網絡通信等功能。根據你的需求,可以選擇啟用或禁用某些擴展來構建一個適合你的環境的 PHP
  • 配置php-fpm.conf

/usr/local/php/etc/php-fpm.conf ,對應目錄中沒有該配置文件的,需要手動創建

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 40
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 40
pm.max_requests = 1024
pm.process_idle_timeout = 10s
request_terminate_timeout = 1000
request_slowlog_timeout = 0
slowlog = var/log/slow.log

  • 配置php服務

nano /etc/systemd/system/php-fpm.service

[Unit]
Description=The PHP FastCGI Process Manager
After=network.target

[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=false

[Install]
WantedBy=multi-user.target
  • 配置環境變量
nano /etc/profile
PATH=$PATH:/usr/local/php/bin:/usr/local/mariadb/bin
export PATH

执行 命令 source /etc/profile 使配置生效
执行完可通过echo $PATH 查看

  • 安裝Nginx
# 解壓php安裝包
tar -zxvf nginx-1.26.0.tar.gz
# 進入php安裝目錄
cd nginx-1.26.0 
# 構建工程
./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--error-log-path=/usr/local/nginx/error.log \
--http-log-path=/usr/local/nginx/access.log \
--pid-path=/usr/local/nginx/nginx.pid \
--lock-path=/usr/local/nginx/nginx.lock \
--http-client-body-temp-path=/usr/local/nginx/client_temp \
--http-proxy-temp-path=/usr/local/nginx/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/scgi_temp \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module

# 指定執行編譯,指定操作方式-并發執行,提高執行效率
make -j $(nproc)

# 安裝
make install
  • 配置nginx服務信息
nano /etc/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=false
  
[Install]
WantedBy=multi-user.target
  • nginx.conf配置文件

注意 修改nginx.conf 前,先備份一下nginx.conf。cp /usr/local/nginx/nginx.conf /usr/local/nginx/nginx.conf.default
注意: 如果nginx.conf 沒有enable-php.conf文件,創建一個enable-php.conf作爲php-fpm的通用配置文件,内容配置如下

enable-php.conf 文件通用配置

 location ~ [^/]\.php(/|$)
        {
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
        }

nginx.conf文件配置

user  www www;

worker_processes auto;
worker_cpu_affinity auto;

#error_log  /home/wwwlogs/nginx_error.log  crit;

#pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept off;
        accept_mutex off;
    }

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

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile on;
        sendfile_max_chunk 512k;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

server
    {
        listen 80 default_server reuseport;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        root  /home/wwwroot/default; # 把網站根目錄放置在/home/wwwroot目錄下面
        #location /hkpma {
        #        auth_basic "HTTP Basic Authentication";
        #        auth_basic_user_file /home/default.htpasswd;
        #}
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf; # 需要在 nginx.conf同級目錄下創建一個enable-php.conf 配置文件

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }
include vhost/*.conf; # 可以創建一個vhost目錄,用來放置多站點的server配置文件
}


  • 安裝Mariadb

安裝前準備相關目錄

# 創建mariadb分組和用戶
groupadd mariadb
useradd -s /sbin/nologin -M -g mariadb mariadb

mkdir -p /home/mariadb
chown -R mariadb:mariadb /home/mariadb
# 加壓 mariadb-10.6.21-linux-systemd-x86_64.tar.gz 並進入加壓后的mariadb 目錄
tar -zxvf mariadb-10.6.21.tar.gz
cd mariadb-10.6.21

執行安裝Mariadb

# 構建工程
cmake .  -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_DATADIR=/home/mariadb \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mariadb.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci

#編譯
make -j $(nproc)

#安裝
make install

#複製附件到指定目錄
cp /usr/local/mariadb/support-files/mysql.server /etc/init.d/mariadb
chmod 755 /etc/init.d/mariadb


  • 初始化數據庫

注意:執行下面命令是,需要確保 /etc/my.cnf的文件存在。本操作教程指定安裝數據庫目錄放置在/home/mariadb目錄下

# 修改/usr/local/mariadb 用戶組為mariadb
# 執行初始化命令
/usr/local/mariadb/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mariadb --datadir=/home/mariadb --user=mariadb

如果缺少/etc/my.cnf,拷貝創建一份my.cnf文件

[client]
#password   = your_password
port        = 3306
socket      = /tmp/mariadb.sock

[mysqld]
character-set-server=utf8mb4
sql-mode=NO_ENGINE_SUBSTITUTIO
port        = 3306
socket      = /tmp/mariadb.sock
user    = mariadb
basedir = /usr/local/mariadb
datadir = /home/mariadb
log_error = /home/mariadb/mariadb.err
pid-file = /home/mariadb/mariadb.pid
skip-external-locking
key_buffer_size = 128M
max_allowed_packet = 256M
table_open_cache = 4096
sort_buffer_size = 16M
net_buffer_length = 8K
read_buffer_size = 32M
read_rnd_buffer_size = 16M
myisam_sort_buffer_size = 128M
thread_cache_size = 64
query_cache_type = 0
tmp_table_size = 64M

explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
expire_logs_days = 10

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_buffer_pool_instances =8
innodb_data_home_dir = /home/mariadb
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /home/mariadb
innodb_buffer_pool_size = 8G
innodb_log_file_size = 2G
innodb_log_buffer_size = 64
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 60
back_log = 128
[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 2M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout


  • 配置Mariadb服務
nano /etc/systemd/system/mariadb.service
[Unit]
Description=MariaDB Server
After=network.target syslog.target

[Service]
Type=forking

ExecStart=/etc/init.d/mariadb start
ExecStop=/etc/init.d/mariadb stop
ExecReload=/etc/init.d/mariadb reload

Restart=no
PrivateTmp=false

[Install]
WantedBy=multi-user.target

安裝完mariadb數據后,需要執行mariadb-secure-installation 刪除mariadb一下默認行爲

注意:先啓動數據庫服務,再執行 mariadb-secure-installation

mariadb-secure-installation是MariaDB的一个脚本,用于执行安全性相关的操作和设置。它会引导用户完成一系列的步骤,以确保MariaDB数据库服务器的安全性。这些步骤通常包括:
设置root密码:您将被要求设置root用户的密码。这是MariaDB的超级用户账户,具有最高权限。
删除匿名用户:这个步骤将删除具有空用户名的匿名用户账户。这些账户通常是安全风险,因为它们允许未经身份验证的用户访问数据库。
禁用远程root登录:禁用root用户通过远程连接登录MariaDB。这样可以减少潜在的安全风险。
删除测试数据库:删除默认情况下安装的测试数据库。这些数据库可能包含一些示例数据,可能会成为潜在的安全漏洞。
重新加载权限表:重新加载权限表,以确保新的权限设置立即生效。
这些步骤可以提高MariaDB服务器的安全性,并减少潜在的安全风险。执行mariadb-secure-installation命令后,按照提示逐步完成这些步骤即可。

以下是執行mariadb-secure-installation過程

root@debian:~/mariadb-10.6.21# mariadb-secure-installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
# 初始化安裝,root密碼爲空,可以直接按回車鍵
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.
# 可以直接按"n"
Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.
# 是否設置root賬號密碼,按Y,輸入自己的密碼 如aa@123456........
Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
# 默認有個匿名用戶賬號,需要刪除
Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
# 是否禁止root賬號遠程登錄,按Y禁止,按n不禁止
Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
# 默認有個test數據庫,需要刪除
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# 確定保存相關配置嗎  確認Y保存
Reload privilege tables now? [Y/n] Y
 ... Success!
# 完成所有配置
Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

-安裝mariadb擴展mroonga

apt install -y libgroonga-dev
apt install -y groonga-normalizer-mysql
https://packages.groonga.org/source/mroonga/mroonga-latest.tar.gz
./configure \
    --with-mysql-source=/root/mariadb-10.6.17 \
    --with-mysql-config=/usr/local/mariadb/bin/mysql_config \
    --with-default-tokenizer=TokenBigramSplitSymbolAlphaDigit

make -j $(nproc)

make install

phpmyadmin 無法登錄數據庫

PHPmyadmin hy000 2002
phpmyadmin提示mysqli_
real_connect(): (HYO00/2
002): No such file or dire
ctory错误的解决办法
phpmyadmin上传到网站目录后提示解决phpmyadmin mysqli_real_connect():
(HYO00/2002): No such file or directory的错误,解决方法把phpmyadmin目录中的配置文件
config.sample.inc.php改成config.inc.php打开编辑config.inc.php
找到:
c f g [ ′ S e r v e r s ′ ] [ cfg['Servers'][ cfg[Servers][i][‘host’] = ‘localhost’;改成:
c f g [ ′ S e r v e r s ′ ] [ cfg['Servers'][ cfg[Servers][i]['host] = ‘127.0.0.1’;
再次刷新页面就不会出现mysqli_real_connect():(HYO00/2002): No such file or directory的错误提示了。

  • 服務器管理
# php 服務
systemctl status php-fpm
systemctl enable php-fpm
systemctl start php-fpm
systemctl reload php-fpm
systemctl stop php-fpm
# nginx 服務
systemctl status nginx
systemctl enable nginx
systemctl start nginx
systemctl reload nginx
systemctl stop nginx
# mariadb 服務
systemctl status mariadb 
systemctl enable mariadb 
systemctl start mariadb 
systemctl reload mariadb 
systemctl stop mariadb 





相关文章:

  • 高效加盖骑缝章:PDF文件处理的实用解决方案
  • 跨境TRS投资操作指南与系统解决方案
  • EspressoSample深度解析:在CircleCI上高效运行Android UI测试
  • 【Linux】kylin桌面进入pe模式,livecd模式
  • DTMF从2833到inband的方案
  • arm64位FFmpeg与X264库
  • 详细解析int GetLength() const;声明中的const是修饰什么的?
  • JDBC FetchSize不生效,批量变全量致OOM问题分析
  • CLion下载安装(Windows11)
  • Sa-Token核心功能解剖二( Session会话、 持久层Redis扩展 、全局侦听器 、全局过滤器、多账号体系认证、单点登录)
  • 【嵌入式学习2】指针数组结构体练习题
  • 对匿名认证的理解
  • Spring Cloud本地调试禁用Nacos自动注册方案解析
  • Compose 实践与探索十七 —— 多指手势与自定义触摸反馈
  • 个人学习编程(3-29) leetcode刷题
  • 四、Shamir Secret Sharing (Shamir 秘密共享)
  • node-red修改标题
  • Ubuntu下载docker、xshell
  • docker 部署 postgresql 切换用户
  • 【计算机操作系统】第八章、磁盘存储器管理:从外存组织到可靠性技术
  • 荣盛发展:新增未支付债务11.05亿元
  • 林诗栋/蒯曼混双取胜,国乒赢得多哈世乒赛开门红
  • 中国进出口银行:1-4月投放制造业中长期贷款超1800亿元
  • 王伟妻子人民日报撰文:81192,一架永不停航的战机
  • 中拉互联网发展与合作论坛在西安开幕
  • 为何选择上海?两家外企提到营商环境、人才资源……