Building the million PV site architecture

Source: Internet
Author: User
Tags dashed line nginx reverse proxy redis cluster install redis

Case Overview:
    • The implementation of four-layer mode, mainly divided into front-end reverse proxy layer, Web layer, database cache layer and database layer front-end reverse proxy layer adopts the main standby mode, the Web layer adopts cluster mode, the database cache layer adopts the main standby mode, and the database layer adopts master-slave mode.
    • To get closer to the production environment, deploy the environment with two physical machines, deploy the front-end reverse proxy layer, the library cache layer, the database tier on the physical machine, and deploy only the Web tier in the KVM virtual machine. At the same time, each layer has made a high-availability architecture to ensure the stability of the business. Million PV network architecture:

PS: The implementation is normal data flow, the dashed line is abnormal situation of the data flow

Case Environment:
Host name IP Address system Use
Master 192.168.217.128 CentOS 7.3 Reverse proxy, Redis master cache, MySQL master database
Backup 192.168.217.129 CentOS 7.3 Reverse proxy, Redis from cache, MySQL from database
Tomcat-node 1 192.168.217.130 CentOS 7.3 Web
Tomcat-node 2 192.168.217.131 CentOS 7.3 Web
Experiment Mall software: SL Mall Source Package Password: O4QWSL Mall data Password: 5LV2

PS: This shop is incomplete, only for experimental use

Deploy Master: Build Nginx Reverse Proxy: 1. Installation Source:
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm  # 安装带有nginx rpm软件包的源  主从都要做
2. Configure the Nginx reverse proxy:
yum install -y nginx
vi /etc/nginx/nginx.conf   # 在 http 添加http { upstream tomcat_pool {                server 192.168.217.130:8080;   #真实节点 web                 server 192.168.217.131:8080;                ip_hash;           #会话稳固功能,否则无法通过vip地址登陆        }        server {                listen 80;                   server_name 192.168.175.188;  #虚拟出的IP                  location / {                        proxy_pass http://tomcat_pool;                        proxy_set_header X-Real-IP $remote_addr;                }    }   include       /etc/nginx/mime.types;   .......nginx -t -c /etc/nginx/nginx.conf  //测试配置文件语法
Build keepalived:1. Configuration keepalived:
yum install -y keepalived
vim /etc/keepalived/keepalived.conf ! Configuration File for keepalivedglobal_defs {    route_id NGINX_HA}vrrp_script nginx {                 #添加脚本路径    script "/opt/shell/nginx.sh"    interval 2                      #每隔两秒执行一次}vrrp_instance VI_1 {    state MASTER          #活跃服务器    interface ens33       #网卡    virtual_router_id 51     priority 100          #优先级    advert_int 1    authentication {        auth_type PASS        auth_pass 1111}track_script {           #调用脚本    nginx}virtual_ipaddress {    192.168.217.188    #虚拟IP    }}
2. Write the Nginx script:
mkdir /opt/shellvim /opt/shell/nginx.sh#!/bin/bashk=`ps -ef | grep keepalived | grep -v grep | wc -l`if [ $k -gt 0 ];then    /bin/systemctl start nginx.serviceelse/bin/systemctl stop nginx.servicefi# 以上意思为开启 keepalived 会自动开启 Nginxchmod +x /opt/shell/nginx.sh
systemctl start keepalived.service  #开启服务
Configure Backup: And master configuration except keepalived slightly different, the other is the same:
vim /etc/keepalived/keepalived.conf .......vrrp_instance VI_1 {    state BACKUP          #修改备份模式    interface ens33           virtual_router_id 51     priority 90           #确定主从......
systemctl start keepalived.service  #开启服务
Test:
when the keepalived service is turned on, the Nginx test is turned off, and it is found that every 2 seconds Nginx will automatically turn off the main keepalived, test the master-slave drift address switch, and use IP addr to view the VIP binding location
.
Deploying Web Services: 1. Installing the Java Environment:
tar xf jdk-8u144-linux-x64.tar.gz -C /optcp -rv /opt/jdk1.8.0_144/ /usr/local/java  #移动重命名
vim /etc/profile     #添加java环境export JAVA_HOME=/usr/local/javaexport JRE_HOME=/usr/local/java/jreexport PATH=$PATH:/usr/local/java/binexport CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/libsource /etc/profile   #刷新环境
java -version     #证明java环境安装成功java version "1.8.0_144"
2. Install Tomcat:
tar xf apache-tomcat-8.5.23.tar.gz -C /optcp -r /opt/apache-tomcat-8.5.23 /usr/local/tomcat8  #移动重命名
ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup     #开启tomcatln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown  #关闭tomcattomcatup         #开启netstat -anpt | grep 8080    #查看服务是否开启
3. Test:
http://192.168.217.130:8080/    #测试默认测试页是否正常显示http://192.168.217.131:8080/访问 http://192.168.217.188     #修改web不同首页,测试keepalived和反向代理是否成功
vim /usr/local/tomcat8/webapps/ROOT/index.jsp   #首页位置
Deploy the Master and backup databases:
yum install -y mariadb-server mariadbsystemctl start mariadb.service systemctl enable mariadb.servicenetstat -anpt | grep 3306mysql_secure_installation     #常规安全设置,测试可以省略。mysql -uroot -p  < slsaledb-2014-4-10.sql  #导入SL商城数据mysql -uroot -pshow databases;  #查看有没有 slsaledb 数据库GRANT all ON slsaledb.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘abc123‘; #授权flush privileges; # 刷新
Deploy Web server: 1. Add
cd /usr/local/tomcat8/conf/vim server.xml   #跳到148行尾,在Host name下新增 <Context path="" docBase="SLSaleSystem" reloadable="true" debug="0"></Context>#日志调试信息debug为0表示信息越少,docBase指定访问目录# SLSaleSystem 为webapps目录下的源码包
tar xf SLSaleSystem.tar.gz -C /usr/local/tomcat8/webapps/ #解压商城的源码包cd /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes #移动到 webapps下vim jdbc.properties #修改数据库IP地址是VRRP的虚拟IP,以及授权的用户名root和密码abc123。
2. Website test, enter SL Mall:
http://192.168.217.130:8080/     #默认的用户名admin 密码:123456http://192.168.217.131:8080/http://192.168.217.188     #输入虚拟地址测试登录,并且关闭主再测试登录

Deploy Master:1. In the Redis cache host configuration:
yum install -y epel-release  #安装epel源yum install redis -y     # 安装 redis 缓存服务vim /etc/redis.conf      #修改配置文件bind 0.0.0.0systemctl start redis.service    #开启服务netstat -anpt | grep 6379redis-cli -h 192.168.217.128 -p 6379    #本地测试连接192.168.217.128:6379> set name test   #创建name 值是test192.168.217.128:6379> get name        #查看name值
2. Configure the Redis cache slave configuration:
yum install -y epel-release  #安装epel源yum install redis -y     # 安装 redis 缓存服务vim /etc/redis.conf      #修改配置文件bind 0.0.0.0slaveof 192.168.217.128  6379   #主服务器的IP不是虚拟IP  第266行systemctl start redis.service    #开启服务
redis-cli -h 192.168.217.129 -p 6379 //登录从,获取值,成功说明主从同步成功192.168.217.129:6379> get name  #如果能查看到 ,说明同步成功
Deploy Web: Configure the parameters for Redis in the marketplace project:
vim /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes/applicationContext-mybatis.xml  47 行                <constructor-arg value="192.168.217.188"/>  #修改虚拟IP  48                 <constructor-arg value="6379"/>
Deploy master:1. Test Cache Effect:
redis-cli -h 192.168.217.188 -p 6379192.168.175.188:6379> infokeyspace_hits:1  或者 keyspace_misses:0   #关注这个值,命中数和未命中数#登录商城,然后反复点击需要数据库参与的操作页面,再回来使用info 检查keyspace_hits或者keyspace_misses: 值变化。
2. Configure the Redis cluster master-slave switchover (only the primary server is operational):
redis-cli -h  192.168.217.128 info Replication //获取当前服务器的角色vim /etc/redis-sentinel.conf17 protected-mode no       #开启68 sentinel monitor mymaster 192.168.175.128 6379 1   #1表示1台从 注意:修改98 sentinel down-after-milliseconds mymaster 3000     #故障切换时间单位是毫秒systemctl restart redis-sentinel.service  //启动集群netstat -anpt | grep 26379redis-cli -h 192.168.217.128 -p 26379 info Sentinel //查看集群信息
3. Verify master-Slave switching:
systemctl stop redis.service   #关闭主缓存服务redis-cli -h 192.168.175.128 -p 26379 info Sentinel   #发现主变成了129  稍微等下  在master查看
4. Verify the data synchronization situation:
redis-cli -h 192.168.217.129 -p 6379   #进入从缓存服务器192.168.217.129:6379> set name2 test2  #创建OK192.168.217.129:6379> get name2"test2"systemctl start redis    #把主缓存服务启动redis-cli -h 192.168.217.128 -p 6379   #进入主缓存服务器192.168.217.128:6379> get name2    #查看"test2"
Deploy master and backup MySQL master and slave: 1. Edit the configuration file:
vim /etc/my.cnf    #[mysqld]下添加binlog-ignore-db=mysql,information_schemacharacter_set_server=utf8log_bin=mysql_binserver_id=1     #主从id不同log_slave_updates=truesync_binlog=1
systemctl restart mariadb.service  #重启数据库
2. View Authorization in master:
mysql -u root -pshow master status;   #记录日志文件名称和偏移量位置值grant replication slave on *.* to ‘rep‘@‘192.168.175.%‘ identified by ‘123456‘;    #授权flush privileges;   #刷新
3. In the backup authorization:
mysql -u root -pchange master to master_host=‘192.168.217.128‘,master_user=‘rep‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=245;start slave;    #开启show slave status;    #查看    Slave_IO_Running: Yes     #成功    Slave_SQL_Running: Yes
4. Test:

Create the database in the primary database, and view it from the database.

Building the million PV site architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.