HTTPS负载均衡WEB集群架构搭建-wordpress

HTTPS负载均衡WEB集群架构实现


服务器准备
nameOverview
web01-172.16.1.7web服务器
web01-172.16.1.8web服务器
nfs-172.16.1.32nfs服务器
db01-172.16.1.51mariadb数据库服务器
proxy01-172.16.1.5proxy服务器

配置数据库服务器

安装数据库mariadb&mariadb-server

[root@db01 ~]# yum install mariadb mariadb-server

加入开机自启

[root@db01 ~]# systemctl start mariadb
[root@db01 ~]# systemctl enable mariadb

查看端口启动情况

[root@db01 ~]# netstat -lntp |grep 3306

进入mysql数据库

[root@db01 ~]# mysql

添加远程用户&密码并刷新权限

MariaDB [(none)]> grant all privileges on *.* to 'app'@'%' identified by '123456';
MariaDB [(none)]> flush privileges;

创建博客网站数据库

MariaDB [(none)]> create database wordpress;

配置nfs共享存储服务器

安装nfs服务

[root@nfs01 ~]# yum install nfs-utils -y

添加共享配置

[root@nfs01 ~]# vim /etc/exports
/data/blog 172.16.1.0/24(rw,all_squash,anonuid=666,anongid)

创建共享路径

[root@nfs01 ~]# mkdir -p /data/blog

启动nfs服务&加入自启

[root@nfs01 ~]# systemctl start nfs-server
[root@nfs01 ~]# systemctl enable nfs-server

配置web服务器

创建www用户&组

[root@web01 ~]# groupadd -g 666 www
[root@web01 ~]# useradd -g 666 -u www

注释epel源

[root@web01 ~]# gzip /etc/yum.repos.d/epel.repo

配置官方源

[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

下载Nginx

[root@web01 ~]# yum install nginx

下载php

[root@web01 ~]# wget http://cdn.xuliangwei.com/zip

解压php

[root@web01 ~]# unzip php.zip

安装php

[root@web01 ~]# yum install php/*.rpm -y

修改php-fpm运行用户&组为www并检查

[root@web01 ~]# sed -i '/user/c user = www' /etc/php-fpm.d/www.conf
[root@web01 ~]# sed -i '/group/c user = www' /etc/php-fpm.d/www.conf
[root@web01 ~]# cat /etc/php-fpm.d/www.conf |grep www

启动nginx&php-fpm并加入开机自启

[root@web01 ~]# systemctl start nginx php-fpm
[root@web01 ~]# systemctl enable php-fpm nginx

检查端口启动

[root@web01 ~]# netstat -lntp 

配置Nginx

[root@web01 ~]# vim /etc/nginx/conf.d/s.hope202091.com.conf
server {
	listen 80;
	server_name s.hope202091.com;
	root /code/wordpress;
	
	location / {
		index index.php;
	}
	
	location ~ \.php$ {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_param HTTPS on;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
	}
}

创建指定目录

[root@web01 ~]# mkdir /code

下载博客代码包

[root@web01 ~]# wget https://cn.wordpress.org/latest-zh_CN.zip

解压代码包

[root@web01 ~]# unzip latest-zh_CN.zip -d /code

修改目录属主&属主

[root@web01 ~]# chown -R www.www /code

两台web服务器操作一致


解析域名至单台主机测试连通


配置proxy负载均衡

安装Nginx

[root@proxy01 ~]# scp root@172.16.1.7:/etc/yum.repos/nginx.repo /etc/yum.repos
[root@proxy01 ~]# gzip /etc/yum.repos/epel
[root@proxy01 ~]# yum install nginx

配置Nginx

[root@proxy01 ~]# vim /etc/nginx/conf.d/proxy_s.hope202091.com.conf
upstream hope {
	server 172.16.1.7:80;
	server 172.16.1.8:80;
}

server {
	listen 80;
	server_name s.hope202091.com;
	return 302 https://$server_name$request_url;
}

server {
	server 443 ssl http2;
	server_name s.hope202091.com;
	
	ssl_certificate ssl_key/6174879_s.hope202091.com.pem;
	ssl_certificate_key ssl_key/6174879_s.hope202091.com.key;
}

location / {
	proxy_pass http://hope;
	proxy_set_header Host $http_host;
}

启动Nginx&加入自启

[root@proxy01 ~]# systemctl start nginx
[root@proxy01 ~]# systemctl enable nginx

将域名解析至负载均衡测试连通


连接数据库
[root@web01 ~]# vim /code/wordpress/wp-config.php
/MySQL
define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'app' );

/** MySQL database password */
define( 'DB_PASSWORD', '123456' );

/** MySQL hostname */
define( 'DB_HOST', '172.16.1.51' );

重载php-fpm

[root@web01 ~]# systemctl reload php-fpm

两台web服务器操作一致


测试连通&根据安装导向安装 更换主题 新建博客 上传图片 获取图片存储地址


挂载nfs共享路径

查看nfs共享路径

[root@web01 ~]# showmount -e 172.16.1.32

挂载挂载路径&刷新并查看

[root@web01 ~]# mount -t nfs 172.16.1.32:/data/blog /code/wordpress/wp-content/uploads
[root@web01 ~]# mount -aL
[root@web01 ~]# df

配置文件添加挂载

[root@web01 ~]# vim /etc/fstab
172.16.1.32:/data/blog /code/wordpress/wp-content/uploads	nfs	defaults 0 0
172.16.1.32:/data/blog /code/wordpress/wp-content/uploads	nfs defaults 0 0

两台web服务器操作一致


完成!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值