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;
# 如果修改了 /etc/my.cnf 后,啟動mysql 時出錯: 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 &
# 后續設定同上.
# ------------- 使用官方推薦的 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 --user=nginx --group=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的位置
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
編譯如果出錯:
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
# 保存退出,執行:
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() 檢查
選裝 memcached
yum install memcached vi /etc/sysconfig/memcached # 調大一些記憶體用量 systemctl start memcached && systemctl enable memcached
# 安裝 php 擴展 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-config make && make install # 留意路徑資訊 ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/ # 是否存在 memcached.so find / -name php.ini # 找到 php.ini 在擴展中增加一行: extension=memcached.so # 重啟所有的php-fpm行程后,瀏覽器中查看 phpinfo
一個個安裝嫌煩的話, 開發環境也可以使用xampp包
./xampp-linux-x64-7.2.22-0-installer.run cd /opt/lampp ./lampp security
# 依次設定安全選項.但是最后要手動啟用mysql的遠程連接 #在/opt/lampp/etc/my.cnf 中注釋掉: #skip-networking
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/90895.html
標籤:MySQL
