百万用户量的系统架构方案实例

本文详细介绍了构建能支撑百万用户量的系统架构过程,涵盖了从安装redis集群、zookeeper、ActiveMQ、nginx、nfs,到初始化和配置mysql服务器、web服务器及转码服务器等关键步骤。通过具体的机器分配、软件安装、配置和权限设置,展示了完整的系统搭建流程。
摘要由CSDN通过智能技术生成

1.准备工作

先创建zhy用户
命令:

切换到root用户
root账号拥有root权限
密码:De@2016er
su root
sudo adduser zhy
添加密码:
sudo passwd zhy
zhy密码:
mine1058!firemen

2.安装软件

(1)安装redis集群

机器分配

10.162.27.141
10.162.27.142
10.162.27.143

拷贝文件到zhy文件夹

scp -r ./software/ zhy@10.162.27.141:/home/zhy/
scp -r ./software/ zhy@10.162.27.142:/home/zhy/
scp -r ./software/ zhy@10.162.27.143:/home/zhy/

按照文档安装

解压

tar xzvf redis-3.2.11.tar.gz

编译

cd redis-3.2.11
make

安装

cd /home/zhy
mkdir -p apps/redis/bin
mkdir -p apps/redis/data
mkdir -p apps/redis/conf

拷贝程序到相应目录

cp -vf /home/zhy/software/redis-3.2.11/src/redis-server ~/apps/redis/bin
cp -vf /home/zhy/software/redis-3.2.11/src/redis-cli ~/apps/redis/bin

配置master服务器

在141上新建master的配置文件
cd /home/zhy/apps/redis/conf
vi redis.conf
拷贝master的配置,并保存
启动master
/home/zhy/apps/redis/conf/redis.conf

配置slave服务器

在142,143上新建slave的配置文件
cd /home/zhy/apps/redis/conf
vi redis.conf
拷贝slave的配置,并保存

启动

/home/zhy/apps/redis/bin/redis-server /home/zhy/apps/redis/conf/redis.conf

配置开机启动

mkdir ~/bin
zhy 用户执行:
cat >> ~/bin/sys_init_startup.sh << EOF
/home/zhy/apps/redis/bin/redis-server /home/zhy/apps/redis/conf/redis.conf
EOF
chmod 750 ~/bin/sys_init_startup.sh
以 root 用户登录,编辑 /etc/rc.local 文件,添加如下行:
su - zhy -c “/home/zhy/bin/sys_init_startup.sh”

关闭防火墙

sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service

测试集群

登录master机器
/home/zhy/apps/redis/bin/redis-cli -c -p 6380 -a cacheManager1
set name chenpy
get name
登录slave机器
/home/zhy/apps/redis/bin/redis-cli -c -p 6380 -a cacheManager1
get name
发现内容已经同步过来
redis端口改为了6380

(2)安装zookeeper

同样新建用户zhy

机器分配

10.162.27.144
10.162.27.145
10.162.27.146

拷贝安装包

把安装包拷贝到 144的 software文件夹
拷贝完成后用scp 分别拷贝到3台机器的 /home/zhy/software 中
scp -r ./software/ zhy@10.162.27.144:/home/zhy/
scp -r ./software/ zhy@10.162.27.145:/home/zhy/
scp -r ./software/ zhy@10.162.27.146:/home/zhy/

安装zookeeper

创建目录 apps
cd /home/zhy/
mkdir -p apps
cd apps
tar xzvf /home/zhy/software/zookeeper-3.4.11.tar.gz
cd zookeeper-3.4.11

修改 ZooKeeper 配置文件

cp -vf conf/zoo_sample.cfg conf/zoo.cfg
mkdir -p logs
mkdir -p data

替换文本

sed -i ‘s#dataDir=/tmp/zookeeper#dataDir=/home/zhy/apps/zookeeper-3.4.11/data#g’ conf/zoo.cfg

配置文件中添加配置

cat >> conf/zoo.cfg << EOF
dataLogDir=/home/zhy/apps/zookeeper-3.4.11/logs
three servers of this cluster
server.1=10.162.27.144:2888:3888
server.2=10.162.27.145:2888:3888
server.3=10.162.27.146:2888:3888
EOF

添加服务的id

在 10.162.27.144 服务器上执行
touch data/myid
echo 1 > data/myid
在 10.162.27.145 服务器上执行
touch data/myid
echo 2 > data/myid
在 10.162.27.146 服务器上执行
touch data/myid
echo 3 > data/myid

关闭防火墙

sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service

启动服务器

/home/zhy/apps/zookeeper-3.4.11/bin/zkServer.sh start

配置自动启动

cat >> ~/bin/sys_init_startup.sh << EOF
/home/zhy/apps/zookeeper-3.4.11//bin/zkServer.sh start
EOF

添加执行权限

chmod 750 ~/bin/sys_init_startup.sh
以 root 用户登录,编辑 /etc/rc.local 文件,添加如下行:
su - zhy -c “/home/zhy/bin/sys_init_startup.sh”

(3)安装 ActiveMQ

同样新建用户zhy

机器分配:

10.162.27.147
10.162.27.148
10.162.27.149

把安装包拷贝到 147的 software文件夹

拷贝完成后用scp 分别拷贝到3台机器的 /home/zhy/software 中
scp -r ./software/ zhy@10.162.27.147:/home/zhy/
scp -r ./software/ zhy@10.162.27.148:/home/zhy/
scp -r ./software/ zhy@10.162.27.149:/home/zhy/

安装mq

解压安装 ActiveMQ
以zhy用户登录执行:
cd ~/apps
tar xzvf /home/zhy/software/apache-activemq-5.15.2-bin.tar.gz

编辑 ActiveMQ 配置文件

cd ~/apps/apache-activemq-5.15.2
vim conf/activemq.xml




修改为

卸载本身的jdk

因为activemq-5.15需要jdk1.8 所以需要安装jdk1.8
sudo rpm -e –nodeps java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
sudo rpm -e –nodeps java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
sudo rpm -e –nodeps java-1.7.0-openjdk-devel-1.7.0.91-2.6.2.3.el7.x86_64

按照文档安装

tar xzvf jdk-8u131-linux-x64.tar.gz
然后把jdk复制到apps里面
cp -r /home/zhy/software/jdk1.8.0_131/ /home/zhy/apps/
mv /home/zhy/apps/jdk1.8.0_131/ /home/zhy/apps/jdk1.8.0

修改环境变量

cat >> ~/.bash_profile << EOF
export JAVA_HOME=/home/zhy/apps/jdk1.8.0
export PATH=$PATH:$JAVA_HOME/bin
EOF
source ~/.bash_profile

关闭防火墙

sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service

启动

/home/zhy/apps/apache-activemq-5.15.2/bin/activemq start

配置开机启动

cat >> ~/bin/sys_init_startup.sh << EOF
/home/zhy/apps/apache-activemq-5.15.2/bin/activemq start
EOF

添加执行权限

chmod 750 ~/bin/sys_init_startup.sh
以 root 用户登录,编辑 /etc/rc.local 文件,添加如下行:
su - zhy -c “/home/zhy/bin/sys_init_startup.sh”

(4)安装 nginx

使用账号的安装账号是zhy

安装nginx

tar xzvf nginx-1.12.2.tar.gz
tar xzvf openssl-1.1.0g.tar.gz
unzip pcre-8.41.zip
tar xzvf zlib-1.2.11.tar.gz
mkdir -p /home/zhy/apps
cd nginx-1.12.2

配置

./configure –prefix=/home/zhy/apps/nginx \
–user=zhy –group=zhy \
–with-http_stub_status_module \
–with-http_ssl_module \
–with-stream \
–with-http_stub_status_module \
–with-http_flv_module \
–with-http_mp4_module \
–with-http_secure_link_module \
–with-pcre-jit \
–with-http_realip_module \
–with-http_v2_module \
–with-pcre=../pcre-8.41 \
–with-openssl=../openssl-1.1.0g \
–with-zlib=../zlib-1.2.11

安装

make && make install

端口绑定权限修改:

sudo setcap cap_net_bind_service=+ep /home/zhy/apps/nginx/sbin/nginx

配置nginx环境变量

cat >> ~/.bash_profile << EOF
export NGINX_HOME=/home/zhy/apps/nginx
export PATH=$PATH:$NGINX_HOME/sbin
EOF

配置nginx

cat >> ~/bin/sys_init_startup.sh << EOF
/home/zhy/apps/nginx/sbin/nginx
EOF
chmod 750 ~/bin/sys_init_startup.sh

创建项目的nginx文件

修改 nginx 配置文件
zhy 用户登录执行:
cd ~/apps/nginx/conf
mkdir conf.d
vi nginx.conf
将 “#gzip on;” 所在的行改为如下内容:
gzip on;
include conf.d/*.conf;
编辑 conf.d/elearn.zjrb.com.conf 文件。
cd ~/apps/nginx/conf/conf.d
vi wsxy.chinaunicom.cn.conf

配置nginx配置文件

upstream zhy-spark {
hash $cookie_uid consistent;

    server 10.162.27.150:8091;
server 10.162.27.150:8092;
}

server {
    listen 80;
    server_name "uat.campus.chinaunicom.cn";

    userid          on;
    userid_name     uid;
    userid_domain   uat.campus.chinaunicom.cn;
    userid_path     /;

    location / {
            index   index.html;
            root    "/home/zhy/web-root/learner-web";
            try_files $uri $uri/ /index.html =404;
    }

    location /learner {
            index   index.html;
            alias   "/home/zhy/web-root/learner-web";
            try_files $uri $uri/ /index.html =404;
    }

    location /consoleui/showcase {
            index   index.html;
            alias   "/home/zhy/web-root/showcase";
            try_files $uri $uri/ /index.html =404;
    }


    location /lmsapi {
            alias   "/home/zhy/web-root/lmsapi";
    }

    location /console {
            index   index.html;
            alias   "/home/zhy/web-root/console-web";
            try_files $uri $uri/ /index.html =404;
    }

    location /content {
            index   index.html;
            alias   "/nfs_share/content-root";
            try_files $uri $uri/ /index.html =404;
    }

    location /api {
            proxy_pass  http://zhy-spark;

            #Proxy Settings
            proxy_redirect     off;
            #proxy_buffering    off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_next_upstream error timeout invalid_header http_502 http_503 http_504;
            proxy_max_temp_file_size 0;
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;
            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
            client_max_body_size    1000m;
    }
}

nginx自动启动

su - zhy -c “/home/zhy/bin/sys_init_startup.sh”

开启端口

sudo firewall-cmd –zone=public –add-port=80/tcp –permanent

命令含义:

–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效

项目部署

node –max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build -prod -bh /learner/

部署前端工程

unzip -o /home/zhy/web-root/learner-web.zip -d /home/zhy/web-root/learner-web
unzip -o /home/zhy/web-root/console-web.zip -d /home/zhy/web-root/console-web

配置免密

ssh-keygen -t rsa

(5)安装nfs

[服务器端nfs]

安装nfs

sudo yum install rpcbind nfs-utils -y

创建/data/content

mkdir /data
mkdir /data/content
把共享的目录变为 nfsnobody用户和用户组
chown -R nfsnobody:nfsnobody /data
为目录增加权限
chmod 777 /data -R

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值