共计 4265 个字符,预计需要花费 11 分钟才能阅读完成。
lvs 实践(lvs+nginx+mariadb+php—fpm+nfs 搭建 wordpress)
lvs 实践(lvs+nginx+mariadb+php—fpm+nfs 搭建 wordpress)
1
|
lvs_dr 模型
|
1
|
nginx
|
1
|
mariadb
|
1
|
php-fpm
|
1
|
wordpress
|
实验拓扑
要求说明:1、lvs——director 调度两台 nginx+php-fpm real server 采用 dr 模型 算法为 rr | |
2、mriadb 为 real server 提供数据库 nfs 挂载至 2 台 real-server 提供文件服务 | |
3、为了方便起见各节点 iptables 和 seLinux 均已关闭。4、windows 本地提供 host 文件做解析 z.com 至 |
step1:网络配置
按照拓扑图要求配置网络环境。
step2:各节点软件安装
lvs——director:
#yum -y install ipvsadm
两台 real server:
# yum -y install nginx nfs-utils rpcbind | |
# yum -y install php-fpm php-mysql php-gd php-mbstring php-mcrypt |
nfs-server:
# yum -y install nfs-utils rpcbind
Mariadb-server
#yum -y install mariadb*
step3: 服务配置
nfs_server 配置
#groupadd www -g 501 | |
#useradd www -u 501 -g www -M -r | |
#mkdir /usr/share/nginx/html/ | |
#chown -R www:www /usr/share/nginx/html/ | |
# echo '/usr/share 192.168.3.0/24(rw,sync,all_squash,anongid=501,anonuid=501)' > /etc/exports | |
#exportfs -rv | |
#systemctl start rpcbind.service | |
#systemctl start nfs.service | |
#cd /usr/share/nginx/html/ | |
#准备好 wordpress | |
#wget https://cn.wordpress.org/wordpress-4.5.2-zh_CN.tar.gz | |
# tar zxvf wordpress-4.5.2-zh_CN.tar.gz | |
# cp -R wordpress/* ./ | |
# cp wp-config-sample.php wp-config-sample.php.bak | |
# mv wp-config-sample.php wp-config.php | |
#修改如下 部分略 | |
#<?php | |
/** | |
* WordPress 基础配置文件。* | |
* 这个文件被安装程序用于自动生成 wp-config.php 配置文件,* 您可以不使用网站,您需要手动复制这个文件,* 并重命名为“wp-config.php”,然后填入相关信息。* | |
* 本文件包含以下配置选项:* | |
* * MySQL 设置 | |
* * 密钥 | |
* * 数据库表名前缀 | |
* * ABSPATH | |
* | |
* @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php | |
* | |
* @package WordPress | |
*/ | |
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** // | |
/** WordPress 数据库的名称 */ | |
define('DB_NAME', 'wordpress'); | |
/** MySQL 数据库用户名 */ | |
define('DB_USER', 'wordpress'); | |
/** MySQL 数据库密码 */ | |
define('DB_PASSWORD', '123456'); | |
/** MySQL 主机 */ | |
define('DB_HOST', '192.168.3.8'); |
lvs—director
#ifconfig eno16777736:0 192.168.2.11/32 broadcast 192.168.2.11 up | |
#route add -host 192.168.2.11 dev eno16777736:0 |
两台 real—server
#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore | |
#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce | |
#echo 1 > /proc/sys/net/ipv4/conf/eno16777736/arp_ignore | |
# echo 2 > /proc/sys/net/ipv4/conf/eno16777736/arp_announce | |
#ifconfig lo:0 192.168.2.11/32 broadcast 192.168.2.11 up | |
#route add -host 192.168.2.11 dev lo:0 | |
#systemctl start rpcbind.service | |
#mount -t nfs 192.168.3.9:/usr/share/ /usr/share/nginx | |
# df -h | |
文件系统 容量 已用 可用 已用 % 挂载点 | |
/dev/mapper/centos-root 18G 1.4G 17G 8% / | |
devtmpfs 105M 0 105M 0% /dev | |
tmpfs 115M 0 115M 0% /dev/shm | |
tmpfs 115M 8.6M 107M 8% /run | |
tmpfs 115M 0 115M 0% /sys/fs/cgroup | |
/dev/sda1 497M 124M 373M 25% /boot | |
tmpfs 23M 0 23M 0% /run/user/0 | |
192.168.3.9:/usr/share/nginx 18G 1.1G 17G 7% /usr/share/nginx | |
# vim /etc/nginx/conf.d/z.com.conf | |
server { | |
listen 80; | |
server_name z.com; | |
root /htdocs/z_com; | |
index index.php; | |
add_header X-via $server_addr; | |
location / { | |
root /htdocs/z_com; | |
index index.php index.html index.html; | |
} | |
location ~* .(jpg|jpeg|png|gif|js|css)$ {root /htdocs/z_com;} | |
location ~ .php$ { | |
root /htdocs/z_com; | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /htdocs/z_com$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
} | |
#systemctl start nginx.service |
Mariadb 数据库配置
#systemctl start mariadb.service | |
#mysql | |
MariaDB [(none)]> create database wordpress; | |
grant all on wordpress.* to 'wordpress'@'%' identified by '123456'; |
step4:lvsdirector 集群配置
#ipvsadm -A -t 192.168.2.11:80 -s rr | |
#ipvsadm -a -t 192.168.2.11:80 -r 192.168.2.117 -g | |
#ipvsadm -a -t 192.168.2.11:80 -r 192.168.2.135 -g | |
# ipvsadm -Ln | |
IP Virtual Server version 1.2.1 (size=4096) | |
Prot LocalAddress:Port Scheduler Flags | |
-> RemoteAddress:Port Forward Weight ActiveConn InActConn | |
TCP 192.168.2.11:80 rr | |
-> 192.168.2.117:80 Route 1 0 0 | |
-> 192.168.2.135:80 Route 1 0 0 |
最后效果如下
正文完
星哥玩云-微信公众号
