博客搭建:
- a 實(shí)現(xiàn)數(shù)據(jù)庫(kù)遷移
- b 實(shí)現(xiàn)數(shù)據(jù)共享存儲(chǔ)
補(bǔ)充ssh遠(yuǎn)程的方法:
正常方法:xshell新建標(biāo)簽頁(yè)訪問(wèn)
ssh IP地址(172.16.1.7)52113
在linux系統(tǒng)上ssh 172.16.1.7 -p52113(修改過(guò)的端口)
使用負(fù)載均衡訪問(wèn)三臺(tái)博客
現(xiàn)象:
使用負(fù)載均衡訪問(wèn)博客崭倘,當(dāng)使用登陸界面時(shí)候碟嘴,每進(jìn)行一次登陸負(fù)載均衡就會(huì)跳轉(zhuǎn)到下一臺(tái)博客服務(wù)器上,導(dǎo)致無(wú)法登陸嗜傅。
原因:三臺(tái)服務(wù)器的數(shù)據(jù)庫(kù)在本地茅诱,導(dǎo)致訪問(wèn)每臺(tái)web的時(shí)候會(huì)分別加載各自的數(shù)據(jù)庫(kù)逗物。
解決方法:
1.臨時(shí)解決方法:使用ip_hash 根據(jù)用戶的源ip去固定的加載一臺(tái)服務(wù)器。
2.使用共享數(shù)據(jù)庫(kù)解決負(fù)載均衡顯示頁(yè)面異常問(wèn)題
實(shí)現(xiàn)數(shù)據(jù)庫(kù)數(shù)據(jù)統(tǒng)一存儲(chǔ)
第一個(gè)歷程: 部署數(shù)據(jù)庫(kù)服務(wù)器
yum install -y mariadb mariadb-server
第二個(gè)歷程: 數(shù)據(jù)庫(kù)數(shù)據(jù)備份
mysqldump -uroot -poldboy123 -A > /tmp/backup.sql
第三個(gè)歷程: 數(shù)據(jù)遷移過(guò)程
scp -P52113 -rp /tmp/backup.sql 172.16.1.51:/tmp
第四個(gè)歷程: 恢復(fù)數(shù)據(jù)信息
mysqladmin -uroot password "oldboy123"
mysql -uroot -poldboy123 </tmp/backup.sql
grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by 'oldboy123';
允許172.16.1.0的網(wǎng)段去連接數(shù)據(jù)庫(kù)
mysqladmin -uroot password "oldboy123"
MariaDB [(none)]> select user,host from mysql.user;
+-----------+------------+
| user | host |
+-----------+------------+
| root | 127.0.0.1 |
| wordpress | 172.16.1.% |
| root | ::1 |
| | localhost |
| root | localhost |
| wordpress | localhost |
| | nfs001 |
| root | nfs001 |
+-----------+------------+
8 rows in set (0.00 sec)
最好將數(shù)據(jù)庫(kù)沒(méi)用的用戶刪除
第五個(gè)歷程: 關(guān)閉web服務(wù)器數(shù)據(jù)庫(kù)服務(wù)
systemctl stop mariadb.service
第六個(gè)歷程: 如何配置網(wǎng)站代碼連接數(shù)據(jù)庫(kù)服務(wù)器
vim /html/blog/wp-config.php
define('DB_HOST', '172.16.1.51');
實(shí)現(xiàn)數(shù)據(jù)信息統(tǒng)一共享存儲(chǔ)
第一個(gè)歷程: 部署存儲(chǔ)服務(wù)器
第二個(gè)歷程: 將web服務(wù)器本地已有數(shù)據(jù)進(jìn)行備份存儲(chǔ)
mkdir /tmp/blog_bak -p
mv /html/blog/wp-content/uploads/* /tmp/blog_bak
如何獲取本地存儲(chǔ)數(shù)據(jù)目錄:
方法一: 在網(wǎng)頁(yè)上獲取圖片數(shù)據(jù)存儲(chǔ)目錄
http://blog.oldboy.com/wp-content/uploads/2019/08/oldgirl-300x200.jpg
方法二: 利用inotify監(jiān)控網(wǎng)站站點(diǎn)目錄
方法三: 利用find查找新增數(shù)據(jù)信息
find /html/blog -type f -mmin -2--->查找最近兩分鐘產(chǎn)生的數(shù)據(jù)
第三個(gè)歷程: 實(shí)現(xiàn)共享存儲(chǔ)掛載操作
/data/blog/ 172.16.1.0/24(rw,sync,anonuid=1016,anongid=1016)
#盡量將不同的網(wǎng)站分別存在不同的目錄中
[root@nfs01 blog]# id www
uid=1016(www) gid=1016(www) groups=1016(www)
[root@nfs01 blog]# chown -R www.www /data/
mount -t nfs 172.16.1.31:/data/blog /html/blog/wp-content/uploads/
#web客戶端寫(xiě)入數(shù)據(jù)的用戶為www,需要將掛載目錄的權(quán)限變?yōu)閣ww,注意需要和uid和gid和客戶端相同瑟俭。
PS: 別忘實(shí)現(xiàn)開(kāi)機(jī)自動(dòng)掛載
查看掛載情況 cat /proc/mounts
cat /var/lib/nfs/etab
第四個(gè)歷程: 將備份數(shù)據(jù)進(jìn)行恢復(fù)
mv /tmp/blog_bak/* /html/blog/wp-content/uploads/
第五個(gè)歷程: 測(cè)試數(shù)據(jù)是否可以查看/可以存儲(chǔ)
實(shí)現(xiàn)數(shù)據(jù)庫(kù)共享和存儲(chǔ)共享流程圖
域名更改訪問(wèn)異常問(wèn)題
第一個(gè)歷程: 修改網(wǎng)站后臺(tái)域名信息
配置--常規(guī)--域名信息需要更改
將域名重新注入到數(shù)據(jù)庫(kù)中
第二個(gè)歷程: 修改nginx配置文件域名信息
server_name blog.oldgirl.com
重啟服務(wù)
第三個(gè)歷程: 修改hosts解析信息