lnmp(wecenter)集群拆分
昨天搭建了wordpress以及wecenter。两个典型的lnmp环境的论坛。
今天将wecenter拆分成集群。
节点:web-7,web-8,db-5,nfs-31
web-7和wen-8安装wecenter模拟后期负载均衡。
db-51担任数据库服务器
nfs-31担任备份服务器
web-7/8部署
- 安装nginx以及mariadb
yum install -y nginx
yum install mariadb mariadb-server
- php在阿里yum中版本不适配。所以需要配置本地源
将all_rpm.tar 传到yum文件夹下解压
安装配置repo服务
yum install -y createrepo
createrepo /etc/yum.repos.d/local_yum_rpm
编写local.repo文件
[local]
name=local
baseurl=file:///etc/yum.repos.d/local_yum_rpm
gpgcheck=0
enabled=1
安装php服务
yum install --enablerepo=local php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb php71w-json php71w-pecl-apcu php71w-pecl-apcu-devel
#--enablerepo=local 指定仓库安装,防止安装到其他仓库不同版本的php
-
将wecenter.zip发到/var/www/html/wecenter中
-
mkdir /var/www/html/wecenter
-
unzip wecenter.zip -d /var/www/htm/wecenter
> 设置权限 chmod 777 /var/www/html/wecenter
>
> (本机实验无脑777)
-
安装配置数据库服务
-
yum install -y mariadb mariadb.service
```
修改数据库密码
mysqladmin -uroot password 'root'
登入后创建wecenter数据库
create database wecenter
```
- 在nginx中编写wecenter.conf文档
[root@web-8 /var/www/html/wecenter]#cat /etc/nginx/conf.d/php.conf
server{
listen 80;
server_name wecenter.xie.cc;
index index.php;
root /var/www/html/wecenter;
location ~ \.php$ {
root /var/www/html/wecenter;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
-
启动nginx以及php服务
-
本机实验安装后没有启动
-
systemctl start nginx php-fpm.service
-
设置本机(windows)的hosts文件
#192.168.100.7 wecenter.xie.cc wordpress.xie.cc
192.168.100.8 wecenter.xie.cc wordpress.xie.cc
依次使用本机的命令行页面进行测试。
正在 Ping wecenter.xie.cc [192.168.100.8] 具有 32 字节的数据:
来自 192.168.100.8 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.100.8 的回复: 字节=32 时间=1ms TTL=64
正在 Ping wecenter.xie.cc [192.168.100.7] 具有 32 字节的数据:
来自 192.168.100.8 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.100.8 的回复: 字节=32 时间=1ms TTL=64
部署db-51
-
安装服务
yum install -y mariadb mariadb-server.x86_64
-
将web-7或web-8的数据库文件传输一个过来
在web-7执行 mysqldump -uroot -p'root' -A --single-transaction > /opt/alldb.sql scp /opt/alldb.sql root@192.168.100.31://opt/
-
执行数据库文件
mysql -uroot -pwww.yuchaoit.cn < /opt/alldb.sql systemctl restart mariadb
-
设置数据库权限,使其他节点能够远程链接
grant all privileges on *.* to 'linux'@'%' identified by 'root';
-
将web7,web-8读取数据库的文件修改
[root@web-8 /var/www/html/wecenter/system/config]#cat database.php <?php $config['charset'] = 'utf8mb4'; $config['prefix'] = 'aws_'; $config['driver'] = 'MySQLi'; $config['master'] = array ( 'charset' => 'utf8mb4', 'host' => '192.168.100.51', 'username' => 'linux', 'password' => 'root', 'dbname' => 'wecenter', ); $config['slave'] = false;
-
重启服务
-
systemctl restart nginx php-fpm
-
进入两个节点的wecenter创建内容,查看是否同步。
-
配置nfs
-
安装服务
yum install nfs-utils rpcbind -y
-
设置共享目录以及创建目录设置用户组
mkdir /wecenter-data groupadd www -g 666 useradd www -s /sbin/nologin -M -u 666 -g 666 chown -R www.www /wecenter-data/
-
设置exports
vim /etc/exports /wecenter-data 192.168.100.0/24(rw,sync,all_squash,anonuid=666,anongid=666) 编译刷新一下 exportfs -r
-
查看是否正确运行
[root@nfs-31 ~]#showmount -e 192.168.100.31 Export list for 192.168.100.31 /wecenter-data192.168.100.0/24 #(显示以上内容则运行成功)
-
设置web服务器的共享(web-7,web-8)
#安装服务 yum install nfs-utils rpcbind -y #挂载 mount -t nfs 192.18.100.31:/wecenter-data /var/www/html/wecenter/uploads
-
测试
完成
搭建以及拆分时碰到的问题
-
wencenter页面没有正常显示。
-
nginx文件夹中的wecenter.conf文件中需要指引index
index index.php;
-
配置文件后缀错了
写成了wecenter.php
-
数据库没有同步成功
- 查看/var/www/html/wecenter/system/config]#cat database.php 文件有没有配置错误