Mega-site architecture for millions of PV

Source: Internet
Author: User
Tags import database tomcat server nginx reverse proxy redis cluster install redis

PV (Page view) is the number of pages viewed, usually the main indicator of a network news channel or Web site or even a Web news message. Web page views is one of the most commonly used indicators for evaluating website traffic, referred to as PV.

    • Case overview
      This case design adopts four layer mode to realize, mainly divided into front-end reverse proxy, Web layer, Database cache layer, database layer.
      The front-end reverse proxy layer adopts the main standby mode, the Web layer adopts the cluster mode, the database cache layer adopts the main standby mode, and the database layer adopts the main standby mode.

    • Schema topology diagram: Implementations are normal data flow, and dashed lines are the data flow in exceptional cases.

      ?

    • Limited Computer Configuration This combines the agent layer, the Redis cache data layer, and the MySQL database layer.
Host name IP Use
Master 192.168.200.128 Front-end Nginx Reverse proxy host, Redis cache host, MySQL data main library
Backup 192.168.200.129 Front-end Nginx reverse proxy standby, Redis cache standby, MySQL data backup library
Web1 192.168.200.130 Tomcat server, display Web site
Web2 192.168.200.131 Tomcat server, display Web site
Vip 192.168.200.200

?

  • Configuration on master, backup server
  • Keepalived+nginx installation Configuration
  • Install the source with the Nginx RPM software package
  • Note that the master-slave configuration 3 is different, has been marked

    # rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/#  nginx-release-centos-7-0.el7.ngx.noarch.rpm
  • Use the CentOS default repository to complete the installation below

    # yum install -y keepalived nginx# vi /etc/keepalived/keepalived.conf     //从上修改三个参数! Configuration File for keepalivedglobal_defs {    route_id NGINX_HA              //备份为 NGINX_HB}  //下面删除4行//触发脚本↓↓vrrp_script nginx {    script "/opt/shell/nginx.sh"       interval 2}vrrp_instance VI_1 {    state MASTER               //备份为BACKUP    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.200.200    }}# mkdir /opt/shell# vi /opt/shell/nginx.sh      //编写触发nginx启动的脚本        #!/bin/bash        k=`ps -ef | grep keepalived | grep -v grep | wc -l`        if [ $k -gt 0 ];then            /bin/systemctl start nginx.service        else        /bin/systemctl stop nginx.service        fi# chmod +x /opt/shell/nginx.sh
  • Configure the Nginx front-end scheduling function
  • The same as the primary and standby configuration

    # vi /etc/nginx/nginx.conf //在include 上面一行新增 upstream tomcat_pool {                                server 192.168.200.130:8080;    //web节点服务器                                server 192.168.200.131:8080;                                ip_hash;           #会话稳固功能,否则无法通过vip地址登陆                }                server {                                listen 80;                                server_name 192.168.200.200; #虚拟出的IP                                  location / {                                                proxy_pass http://tomcat_pool;                                                proxy_set_header X-Real-IP $remote_addr;                                }    }

    # nginx -t -c /etc/nginx/nginx.conf  //测试配置文件语法# systemctl stop firewalld.service# setenforce 0# systemctl start keepalived.service    //nginx启动会等待一会
  • Configuration on master, backup server
  • Installation configuration of the database

    # yum install -y mariadb-server mariadb# systemctl start mariadb.service# systemctl enable mariadb.service# netstat -anpt | grep 3306# mysql_secure_installation    //常规安全设置输入( 回车 n n n n y)
  • Import Database

    # mysql -u root -p  
  • Configure on the Web server
  • Install the configuration tomcat (both of the node servers)

    # tar xf apache-tomcat-8.5.23.tar.gz -C /opt# tar xf jdk-8u144-linux-x64.tar.gz -C /opt# cp -rv jdk1.8.0_144/ /usr/local/java# vi /etc/profile   //末尾添加下面4行    export JAVA_HOME=/usr/local/java    export JRE_HOME=/usr/local/java/jre    export PATH=$PATH:/usr/local/java/bin    export CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib# source /etc/profile# java -version    //查看版本# cp -r apache-tomcat-8.5.23 /usr/local/tomcat8# ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup# ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown# tomcatup    //启动tomcat# netstat -anpt | grep 8080  //查看端口是否启动


?
?

    # vi /usr/local/tomcat8/webapps/ROOT/index.jsp //修改默认网页内容            
    • In the browser test page
    • Http://192.168.200.200/the input scheduler address, which is the virtual address, to test the scheduling of the two nodes.


?
?

# cd /usr/local/tomcat8/conf/# vi server.xml   //跳到行尾,在Host name下新增  在149行

<context path= "" docbase= "Slsalesystem" reloadable= "true" debug= "0" ></Context>
Log Debug Information Debug 0 indicates less information, docbase specifies access directory # Tomcatup//start Tomcat

# tomcatdown    //停止tomcat# tomcatup    //启动tomcat

?
?

    • Building the Mall website

      # tar xf SLSaleSystem.tar.gz -C /usr/local/tomcat8/webapps/# cd /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes# vi jdbc.properties   //修改数据库IP地址是VRRP的虚拟IP,以及授权的用户名root和密码abc123。# tomcatdown    //停止tomcat# tomcatup    //启动tomcat

    • Website testing
    • http://192.168.200.130:8080///Default User name Admin password: 123456
    • http://192.168.200.131:8080/
    • HTTP://192.168.200.200//Enter virtual address test login, and turn off master re-test login


?
?

    • Configuration on master, backup server
    • Deploying Redis Master-Slave and cluster

      # yum install -y epel-release# yum install redis -y# cat /etc/redis.conf | grep -v "^#" | grep -v "^$"# vi /etc/redis.conf    bind 0.0.0.0    从服务器上266行多如下一行配置    slaveof 192.168.200.128  6379  //主服务器的IP不是虚拟IP# systemctl start redis.service# netstat -anpt | grep 6379# redis-cli -h 192.168.200.128 -p 6379 //测试连接192.168.200.128:6379> set name test  //设置name 值是test192.168.175.128:6379> get name  //获取name值# redis-cli -h 192.168.200.129 -p 6379 //登录从,获取值,成功说明主从同步成功192.168.200.129:6379> get name"test"

?
?

    • Configure on the Web server
    • Configure parameters for Redis in a marketplace project

      # vi /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes/applicationContext-mybatis.xml    47                 <constructor-arg value="192.168.200.200"/>    48                 <constructor-arg value="6379"/># tomcatdown    //停止tomcat# tomcatup    //启动tomcat

?
?

    • Configuration on master, backup server
    • Test the Redis cache effect
    • Log in to the marketplace, then repeatedly click on the action page that requires the database to participate, and then come back to check keyspace_hits or keyspace_misses: Value change
    • Keyspace_hits: or keyspace_misses://pay attention to this value, the number of hits and misses

      # redis-cli -h 192.168.200.200 -p 6379192.168.200.200:6379> info


?
?

    • Configuring Redis Cluster master-slave switching
    • Only the primary server is operational

      # redis-cli -h  192.168.200.128 info Replication   //获取当前服务器的角色

?

Vi/etc/redis-sentinel.conf (17 rows, 68 rows, 98 rows)
17 protected-mode no68 sentinel monitor mymaster 192.168.200.128 6379 1 //1表示1台从 注意:修改98 sentinel down-after-milliseconds mymaster 3000 //故障切换时间单位是毫秒# service redis-sentinel start //启动集群# netstat -anpt | grep 26379# redis-cli -h 192.168.200.128 -p 26379 info Sentinel  //查看集群信息


    • Verifying master-Slave switching
    • In the Lord

      #  systemctl stop redis.service# redis-cli -h 192.168.200.128 -p 26379 info Sentinel //发现主变成了129

?
?

    • Configuration on master, backup server
    • configuring MySQL master-slave replication
    • MySQL Master server configuration

      # vi /etc/my.cnf      // [mysqld]下    binlog-ignore-db=mysql,information_schema    character_set_server=utf8    log_bin=mysql_bin    server_id=1    log_slave_updates=true    sync_binlog=1

      # systemctl restart mariadb# netstat -anpt | grep 3306# mysql -u root> show master status; //记录日志文件名称和 位置值> grant replication slave on *.* to ‘rep‘@‘192.168.200.%‘ identified by ‘123456‘;> flush privileges;
    • MySQL from server configuration

      # vi /etc/my.cnf / /[mysqld]下    server_id=2# systemctl restart mariadb# netstat -anpt | grep 3306# mysql -u root> change master to master_host=‘192.168.200.128‘,master_user=‘rep‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=245;> start slave;> show slave status\G;    

Mega-site architecture for millions of PV

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.