日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

php mariadb mysql.sock_(LNMP) Nginx_PHP_MariaDB

發(fā)布時(shí)間:2025/4/5 数据库 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php mariadb mysql.sock_(LNMP) Nginx_PHP_MariaDB 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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

通常會(huì)先安裝一下依賴:

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

# 防火墻先關(guān)為敬

systemctl stop firewalld.service

systemctl disable firewalld.service

#------------------最簡單的 yum 安裝,默認(rèn)版本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;

# 如果修改了 /etc/my.cnf 后,啟動(dòng)mysql 時(shí)出錯(cuò):?ERROR 2002 (HY000): Can't connect to local MySQL server through socket

# 則需要編輯 /etc/my.cnf.d/client.cnf 文件,在[client]下添加:

port=3306

socket=/data/mariadb/mysql.sock

# 指向正確的 sock 和端口

# ------------離線下載安裝 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 后續(xù)設(shè)置同上.

# ------------- 使用官方推薦的 yum 方式安裝 10.4.8 -----------------------------

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

# 成功后, 編輯 /etc/yum.repos.d/mariadb.repo 更改一下 url 國內(nèi)源. 比如清華,其它不改。如果網(wǎng)速夠快,可以不改。

[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= 1enabled= 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= 1enabled= 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= 1enabled= 1

# 然后就可以直接 yum?安裝 10.4.8 了。因?yàn)樯厦娴奈募飳懙氖?10.4.8?版本

yum install MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common

# 配置文件同上.

# 啟動(dòng) 狀態(tài) 停止 重啟 開機(jī)啟動(dòng)

systemctl start mariadb

systemctl status mariadb

systemctl stop mariadb

systemctl restart mariadb

systemctl enable mariadb

二進(jìn)制程序包 tar 安裝 MariaDB 供參考:

(1) 準(zhǔn)備用戶

groupadd-r -g 306mysql

useradd-r -g 306 -u 306 -m -d /data/mysqldb mysql

(2) 準(zhǔn)備數(shù)據(jù)目錄

以/data/mysqldb為例,建議使用邏輯卷chown mysql:mysql /data/mysqldbchmod 700 /data/mysqldb

(3) 準(zhǔn)備二進(jìn)制程序tar xf mariadb-10.2.15-linux-x86_64.tar.gz -C /usr/local #/usr/local是程序包指定的目錄,必須解壓在這里

cd/usr/local;ln -sv mariadb-10.2.15mysqlchown -R mysql:mysql /usr/local/mysql/(4) 準(zhǔn)備配置文件mkdir /etc/mysql/

cp support-files/my-huge.cnf /etc/mysql/my.cnf

#/usr/local/mysql/support-files下有很多my-*.cnf文件,分別對(duì)應(yīng)不同的內(nèi)存大小,可打開看看,選擇對(duì)應(yīng)自己機(jī)器的拷貝就行

vim/etc/mysql/my.cnf

[mysqld]中添加三個(gè)選項(xiàng):

datadir= /data/mysqldb

innodb_file_per_table=on # 可不加

skip_name_resolve=on # 禁止主機(jī)名解析,建議使用,不加也可

(5) 創(chuàng)建數(shù)據(jù)庫文件

cd/usr/local/mysql/./scripts/mysql_install_db --datadir=/data/mysqldb --user=mysql

(6) 準(zhǔn)備日志文件touch /var/log/mysqld.logchown mysql:mysql /var/log/mysqld.log

(7) 準(zhǔn)備服務(wù)腳本,并啟動(dòng)服務(wù)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) 添加環(huán)境變量echo PATH=/usr/local/mysql/bin:$PATH > /etc/profile.d/mysql.sh./etc/profile.d/mysql.shmysql-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# 重啟服務(wù)

systemctl restart mariadb

mysql-uroot -p123456

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

# 刪除 ibdata1

cd/var/lib/mysqlrm -rf ib_logfile*

rm -rf ibdata1

# 重啟服務(wù)

systemctl restart mariadb

# 導(dǎo)入數(shù)據(jù)

mysql-uroot -p123456 < /opt/all.sql

安裝與配置nginx1.17.4

systemctl status firewalld.service

systemctl stop firewalld.service

systemctl disable firewalld.service

systemctl status firewalld.servicetar zxf nginx-1.17.4.tar.gz

cd nginx-1.17.4/./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-openssl=/usr/bin/opensslmake & make installvim/etc/profile

PATH=/opt/nginx/sbin:$PATH

export PATH

./etc/profile

useradd nginxpasswdnginx

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_timeout65; types_hash_max_size 2048;server {

listen80; server_name _;location / {

root html; index index.html index.htm index.php;}

error_page500 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;}

}

}

sunginxsudo nginx -t

# 啟用PHP解析后,如果瀏覽器出現(xiàn) File not found . 需要檢查nginx.conf配置文件

# 可能需要將 $document_root 改成絕對(duì)路徑。例如下面的配置就改成了/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 /opttar 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

因?yàn)橐惭b MediaWiki,?所以再安裝依賴 APCu, icu, intl

# 下載 https://pecl.php.net/package/APCu

# 下載 https://github.com/unicode-org/icu 或者git

# icu需要在php編譯之前安裝,成功后就可以在編譯PHP時(shí)直接使用。

tar xf icu4c-52_1-src.tgz

cd icu/source

mkdir /usr/local/icu

./configure --prefix=/usr/local/icu

make && make install

# PHP編譯時(shí) --enable-intl --with-icu-dir=/usr/local/icu

# 直接帶上intl擴(kuò)展。# apcu 需要在php安裝之后安裝。安裝完后需要重啟 php-fpm

tar zxf apcu-5.1.17.tgz

cd apcu-5.1.17phpize #/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-configmake && 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# 如果時(shí)編譯時(shí)沒有intl,事后安裝,則如下執(zhí)行:

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

預(yù)編譯:?注意紅色的2項(xiàng),需要在系統(tǒng)中添加對(duì)應(yīng)的組和用戶,用于啟動(dòng)php-fpm。?參數(shù)?with-config-file-path=/etc?則指定php.ini的位置

cd php-7.2.22

./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

編譯如果出錯(cuò):

configure: error: off_t undefined; check your library configuration

解決:加入icu/lib路徑 vim /etc/ld.so.conf

/usr/local/lib64

/usr/local/lib

/usr/lib

/usr/lib64

/usr/local/icu/lib

# 保存退出,執(zhí)行:

ldconfig -v

安裝:

make && make install

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

groupadd nginx

useradd-g nginx

配置并啟動(dòng) 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.inicp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confcp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.confcp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod +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() 檢查

選裝 memcached

yum installmemcachedvi /etc/sysconfig/memcached # 調(diào)大一些內(nèi)存用量

systemctl start memcached&&systemctl enable memcached

# 安裝 php 擴(kuò)展yum install libmemcached libmemcached-devel # 依賴wget https://pecl.php.net/get/memcached-3.1.3.tgz

tar zxf memcached-3.1.3.tgz

cd memcached-3.1.3

/usr/local/php/bin/phpize # php7.2的路徑

./configure --with-php-config=/usr/local/php/bin/php-configmake && make install# 留意路徑信息ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/# 是否存在 memcached.sofind / -name php.ini

# 找到 php.ini 在擴(kuò)展中增加一行:

extension=memcached.so

# 重啟所有的php-fpm進(jìn)程后,瀏覽器中查看 phpinfo

一個(gè)個(gè)安裝嫌煩的話,?開發(fā)環(huán)境也可以使用xampp包

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

cd/opt/lampp

./lampp security

# 依次設(shè)置安全選項(xiàng).但是最后要手動(dòng)啟用mysql的遠(yuǎn)程連接

#在/opt/lampp/etc/my.cnf 中注釋掉:

#skip-networking

總結(jié)

以上是生活随笔為你收集整理的php mariadb mysql.sock_(LNMP) Nginx_PHP_MariaDB的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。