項目一服務架構缺點:
1. 網站無法解析動態頁面
2. 數據存儲結構存在單點故障
3. 網站服務每次都是從源站提取數據
項目需求
- 升級網站運行平臺
- 部署緩存服務
- 部署PXC集羣
- 解決數據庫服務的負載問題
- 解決調度器的單點故障問題
拓撲圖
升級網站運行平臺
一 清除當前配置
1 停止服務
systemctl stop httpd
systemctl disable httpd
2 卸載共享存儲
umount /var/www/html
vim /etc/fstab
#192.168.4.30:/sitedir /var/www/html nfs defaults 0 0
二 部署LNMP
1 安裝軟件
- 安裝源碼Nginx軟件
- 安裝php-fpm軟件
- 安裝php及php-mysql軟件
- 安裝mariadb-server及mariadb mariadb-devel軟件
2 掛載共享存儲
vim /etc/fstab
192.168.4.30:/sitedir /usr/local/nginx/html nfs defaults 0 0
mount -a
systemctl enable remote-fs.target
3 啓動服務
vim +65 /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
/usr/local/nginx/sbin/nginx
systemctl start php-fpm
4 測試配置
在NFS服務端編寫php腳本
vim /sitedir/test.php
<?php
$school="tarena";
echo $school
?>
客戶端訪問
curl http://192.168.4.33/test.php
curl http://192.168.4.44/test.php
部署緩存服務
一 環境準備
1 拓撲圖
2 部署redis服務器
- 安裝軟件
- 初始化服務器
- 停止服務
- 修改配置文件,啓用集羣配置
- 啓動服務
- 查看服務信息
3 創建redis集羣
3.1 配置管理主機
部署運行環境
創建管理腳本
yum -y install ruby rubygems
gem install redis-3.2.1.gem
創建命令檢索目錄
mkdir /root/bin
cd redis-4.0.8/src/
創建管理集羣腳本
cp redis-trib.rb /root/bin/
chmod +x /root/bin/redis-trib.rb
3.2 創建集羣
redis-trib.rb create --replicas 1 服務器列表
3.3 查看集羣信息
redis-trib.rb info 服務器ip:端口
redis-trib.rb check 服務器ip:端口
3.4 測試配置
redis-cli -c -h ip地址 -p 端口
set name bob
get name
二 配置網站服務器
1 配置php支持Redis集羣
1.1 安裝軟件
yum -y install php-devel gcc
cd redis-4.3.0/
phpize
./configure --with-php-config=/usr/bin/php-config
make && make install
1.2 修改配置文件
vim /etc/php.ini
728 extension_dir = "/usr/lib64/php/modules/"
730 extension = "redis.so"
systemctl restart php-fpm
php -m | grep -i redis