lnmp(wecenter)集群拆分

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部署

  1. 安装nginx以及mariadb
yum install -y nginx
yum install mariadb mariadb-server

  1. 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
  1. 将wecenter.zip发到/var/www/html/wecenter中

  2. mkdir /var/www/html/wecenter

  3. unzip wecenter.zip -d /var/www/htm/wecenter

> 设置权限 chmod 777 /var/www/html/wecenter
>
> (本机实验无脑777)
  1. 安装配置数据库服务

yum install -y mariadb mariadb.service
```
修改数据库密码
mysqladmin -uroot password 'root' 
登入后创建wecenter数据库
create database wecenter
```
  1. 在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;
    }
}
  1. 启动nginx以及php服务

  2. 本机实验安装后没有启动

  3. systemctl start nginx php-fpm.service

  4. 设置本机(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

  1. 安装服务

    yum install -y mariadb mariadb-server.x86_64 
    
  2. 将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/
    
  3. 执行数据库文件

    mysql -uroot -pwww.yuchaoit.cn  < /opt/alldb.sql 
    systemctl restart mariadb
    
  4. 设置数据库权限,使其他节点能够远程链接

    grant all privileges on *.* to 'linux'@'%' identified by 'root';
    
  5. 将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;
    
  6. 重启服务

    1. systemctl restart nginx php-fpm
      
    2. 进入两个节点的wecenter创建内容,查看是否同步。

配置nfs

  1. 安装服务

    yum install nfs-utils rpcbind -y
    
  2. 设置共享目录以及创建目录设置用户组

    mkdir /wecenter-data
    groupadd www -g 666
    useradd www -s /sbin/nologin -M -u 666 -g 666
    chown -R www.www /wecenter-data/
    
  3. 设置exports

    vim /etc/exports
    /wecenter-data 192.168.100.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
    
    编译刷新一下
    exportfs -r
    
    
  4. 查看是否正确运行

    [root@nfs-31 ~]#showmount -e 192.168.100.31
    Export list for 192.168.100.31
    /wecenter-data192.168.100.0/24
    
    #(显示以上内容则运行成功)
    
  5. 设置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
    
  6. 测试
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

完成

搭建以及拆分时碰到的问题

  1. wencenter页面没有正常显示。

  2. nginx文件夹中的wecenter.conf文件中需要指引index

    index index.php;
    
  3. 配置文件后缀错了

    写成了wecenter.php

  4. 数据库没有同步成功

    1. 查看/var/www/html/wecenter/system/config]#cat database.php 文件有没有配置错误
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值