Mega-site architecture of the million PV site architecture case

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

I. Overview of the case

This case is implemented in four-layer mode, which is mainly divided into front-end reverse proxy, Web layer, database cache layer and database layer.

    • Front-end reverse proxy with main standby mode
    • The Web tier uses cluster mode
    • The database cache layer uses the main standby mode
    • Database tier with master-slave mode


Due to the limitations of the experimental conditions, the experiment opened four virtual machines, where the front-end agent layer, the database cache layer, the database layer service is built on the first two virtual servers, the Web layer uses cluster mode, which is used to place two virtual machines separately. Therefore, in order to simulate the actual environment, the service is built according to the following topology.

Second, the experimental environment
Host name Operating System IP Address Use
Server1 Centosx84_64 192.168.144.112 Front-end reverse proxy nginx, Redis cache host, MySQL master database
Server2 Centosx84_64 192.168.144.111 Front-end Reverse proxy preparation Nginx, Redis standby cache host, MySQL standby database
Web1 Centosx84_64 192.168.144.113 Web Services Tomcat
Web2 Centosx84_64 192.168.144.114 Web Services Tomcat
III. Experimental Deployment 3.1, Master and slave settings keepalive and nginx reverse proxy
    • Configuring the Yum Source

RPM-IVH http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

    • Installing KeepAlive software and Nginx

Yum install-y keepalived Nginx

3.1.1 Configuration keepalive
    • Configure the master-slave keepalive, the two configurations are basically the same, the configuration file has been described in different places

Vi/etc/keepalived/keepalived.conf

! Configuration File for keepalivedglobal_defs {    route_id NGINX_HA    //主从不同}vrrp_script nginx {    script "/opt/shell/nginx.sh"    //配置带动Nginx启动脚本    interval 2   //每隔2s响应}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        //调度Nginx启动脚本的函数名}virtual_ipaddress {    192.168.144.188    //设置虚拟IP    }}
3.1.2 Create KeepAlive Drive Nginx startup script

Mkdir-p/opt/shell
vim/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

chmod +x/opt/shell/nginx.sh

3.1.3 Configuring the Nginx front-end scheduling function

Vim/etc/nginx/nginx.conf

    • Add a row above the include
upstream tomcat_pool {                server 192.168.144.113:8080;                server 192.168.144.114:8080;                ip_hash;        //会话稳固功能,否则无法通过vip地址登陆        }        server {                listen 80;                server_name 192.168.144.188;  //虚拟IP                location / {                        proxy_pass http://tomcat_pool;                        proxy_set_header X-Real-IP $remote_addr;                }        }
    • After the configuration is complete, check the Nginx configuration file syntax

Nginx-t-c/etc/nginx/nginx.conf

    • Shut down the firewall and SELinux, ready to start keepalive, then through the configuration file drive script, start Nginx, it is important to note that to stop nginx, you need to shut down keepalive before you can.

    • See if Nginx starts

Netstat-ntap | grep nginx

3.2. Deploy two Web servers 3.2.12 Web server Deployment Tomcat, the deployment steps are identical, in order to test the distinction, need to make a difference in the home page content

Tar XF apache-tomcat-8.5.23.tar.gz
Tar XF jdk-8u144-linux-x64.tar.gz
MV jdk1.8.0_144//usr/local/java
MV Apache-tomcat-8.5.23/tomcat8

    • After the decompression is complete, configure the JDK environment variables to allow the various commands of the JDK to be recognized by the system

Vim/etc/profile

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/lib

Source/etc/profile

    • Configuring the Tomcat startup and shutdown commands for system recognition

      Ln-s/usr/local/tomcat8/bin/startup.sh/usr/bin/tomcatup
      Ln-s/usr/local/tomcat8/bin/shutdown.sh/usr/bin/tomcatdown

    • Start the service, view the port status, and use your own web page test to see if the service is available.

Tomcatup
NETSTAT-ANPT | grep 8080

http://192.168.144.113:8080///test whether the default test page is displayed properly
http://192.168.144.114:8080/

    • In order to divide two Web servers, modify the first page content

vim/usr/local/tomcat8/webapps/root/index.jsp

    • Enter the dispatcher address, which is the virtual address, to test the scheduling of the two nodes.

http://192.168.175.188/

3.2.2 Building Member Shop
    • First add the Support Marketplace module to the Tomcat configuration file

cd/usr/local/tomcat8/conf/
Vim Server.xml

    • Jump to end of line, new in 148 row position under host name

      <Context path="" docBase="SLSaleSystem" reloadable="true" debug="0"></Context>//日志调试信息debug为0表示信息越少,docBase指定访问目录
    • Unzip the Membership store package

Tar zxvf slsalesystem.tar.gz-c/usr/local/tomcat8/webapps/

Cd/usr/local/tomcat8/webapps/slsalesystem/web-inf/classes

Vim jdbc.properties//Modify the database IP address is the VRRP virtual IP, as well as the authorized username root and password abc123.

driverClassName=com.mysql.jdbc.Driverurl=jdbc\:mysql\://192.168.144.188\:3306/slsaledb?useUnicode\=true&characterEncoding\=UTF-8  //该成我们设定的虚拟IPuname=rootpassword=123456minIdle=10maxIdle=50initialSize=5maxActive=100maxWait=100removeAbandonedTimeout=180removeAbandoned=true
    • Client Testing

http://192.168.144.113:8080///Default User name Admin password: 123456
http://192.168.144.114:8080/

http://192.168.175.188//Enter virtual address test login, and turn off master re-test login

3.3. Deploy MySQL and master-slave 3.3.1 Install MySQL
    • In the actual production environment, MySQL service should be built here, but due to the limitations of experimental conditions, this experiment uses MARIADB instead of MySQL.

Yum install-y mariadb-server mariadb

Systemctl Start Mariadb.service
Systemctl Enable Mariadb.service

NETSTAT-ANPT | grep 3306

Mysql_secure_installation//

Set root Password? [y/n] Y//Set the password for the MySQL administrator account, I choose the password for abc123new password:re-enter new Password:password updated successfully! Reloading privilege tables. ... success!  By default, a MariaDB installation had an anonymous user, allowing Anyoneto log into MariaDB without had to had a user  Account created Forthem.  This was intended only for testing, and the Installationgo a bit smoother. You should remove them before moving into aproduction environment. Remove anonymous users? [y/n] N//delete anonymous user? ... skipping.  Normally, Root should only is allowed to connect from ' localhost '. Thisensures that someone cannot guess at the root of password from the network. Disallow Root login remotely? [y/n] n//deny root user remote login? ... skipping.  By default, the MariaDB comes with a database named ' Test ' anyone canaccess. This was also intended only for testing, and should was removedbefore moving into a production environment. Remove test database and access to it? [y/n] N//delete test database? ... skippIng. Reloading the privilege tables would ensure that all changes made so farwill take effect immediately. Reload privilege tables now? [y/n] Y//Reload all tables of the database? ... success! Cleaning up ...  All done! If you've completed all of the above steps, your mariadbinstallation should now is secure. Thanks for using mariadb!

Mysql-uroot-p//Enter the database

3.3.2 Import Database, authorize

Mysql-u Root-p < Slsaledb-2014-4-10.sql
Mysql-uroot-p

show databases;GRANT all ON slsaledb.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘abc123‘;    
3.3.3 MySQL master-slave configuration
    • The MySQL master server.

Vim/etc/my.cnf

[mysqld]下添加binlog-ignore-db=mysql,information_schema       //二进制日志格式character_set_server=utf8log_bin=mysql_bin  //开启二进制日志server_id=1  log_slave_updates=truesync_binlog=1   //同步日志

Systemctl Restart MARIADB

NETSTAT-ANPT | grep 3306

Mysql-u root-p

show master status; //记录日志文件名称和 位置值+------------------+----------+--------------+--------------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         |+------------------+----------+--------------+--------------------------+| mysql_bin.000001 |      626 |              | mysql,information_schema |+------------------+----------+--------------+--------------------------+grant replication slave on *.* to ‘rep‘@‘192.168.144.%‘ identified by ‘123456‘;  //授予主从状态flush privileges;
    • MySQL from the server

Vim/etc/my.cnf

[mysqld]下添加server_id=2

Systemctl Restart MARIADB

NETSTAT-ANPT | grep 3306
Mysql-u root-p

change master to master_host=‘192.168.144.112‘,master_user=‘rep‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=2626;start slave;show slave status;            Slave_IO_Running: Yes            Slave_SQL_Running: Yes
    • The next step is to test whether the master-slave status is feasible.
3.4 Deployment of the Redis Database cache tier 3.4.1 installation Redis
    • Very good for master-slave Redis Database cache, first need to install Redis software

Yum install-y epel-release//install extension source
Yum Install Redis-y

3.4.2 Setting the master-slave relationship
    • Configure Master Redis

Vim/etc/redis.conf

bind 0.0.0.0   //将监听网址修改成任意网段

Systemctl Start Redis.service
NETSTAT-ANPT | grep 6379

    • Whether the test itself is installed to complete use

Redis-cli-h 192.168.144.112-p 6379//test connection

192.168.144.112:6379> set name test//Set name value is test

192.168.144.112:6379> Get name//Get Name Value

    • Configure the Redis

Vim/etc/redis.conf

bind 0.0.0.0   //61行,修改监听地址...slaveof 192.168.114.112  6379 //266行下添加主服务器的IP,不是虚拟IP
    • Two Redis Server service restarts

Systemctl Restart Redis.service

    • Enter Redis from the server and discover that replication is complete

Redis-cli-h 192.168.144.111-p 6379
192.168.144.111:6379> Get Name
"Test"

    • This completes the Redis master-slave configuration.
3.4.3 Configuring Redis parameters in a marketplace project
    • Configure the Marketplace project in the Web node, specify the Redis virtual IP

Vim/usr/local/tomcat8/webapps/slsalesystem/web-inf/classes/applicationcontext-mybatis.xml

      <!--redis 配置 开始-->         <constructor-arg value="192.168.144.188"/>    //47行         <constructor-arg value="6379"/>              //48行
3.4.4 Test Cache effects

Redis-cli-h 192.168.144.188-p 6379

192.168.175.188:6379> Info

keyspace_hits:1  或者 keyspace_misses:2//关注这个值,命中数和未命中数登录商城,然后反复点击需要数据库参与的操作页面,再回来检查keyspace_hits或者keyspace_misses: 值变化。

Mega-site architecture of the million PV site architecture case

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.