General Introduction PV (Page view) that is, the number of pages viewed, or the number of clicks, usually measuring a web site of the main indicators of the implementation of four-layer mode, mainly divided into front-end reverse proxy layer, Web layer, database cache layer and 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 master-slave mode.
|
Software |
version |
Introduction |
Keepa |
1.3.5-6.el7 |
The role of keepalived is to detect the state of a server, if a Web server is down, or if the work fails, keepalived will detect and remove the failed server from the system while using a different server to replace the server's work. When the server is working properly, Keepalived automatically joins the server to the server farm, all of which are automatically completed without human intervention and need to be done manually to repair the failed server. |
Nginx |
1:1.14.0-1.el7_4.ngx |
Nginx is a very powerful high-performance Web and reverse proxy server, it has many very advantageous features: In the case of high connection concurrency, Nginx is a good substitute for Apache server |
Jdk |
8u144-linux-x64 |
The JDK is the Java language Software Development Toolkit for Java applications on mobile devices and embedded devices. The JDK is the core of the entire Java development, which contains the Java Runtime Environment (Jvm+java System class Library) and Java tools. |
Tomcat |
apache-tomcat-8.5.23 |
is a free open-source JSP server. The tomcat6.0 features a tomcat management and control platform, secure domain management, and tomcat valves, which itself contains an HTTP server and can be viewed as a separate Web server. The software features stable performance and supervised ease of use, making it the most widely used JSP server. |
MySQLdb |
1:5.5.56-2.el7 |
Because of its small size, fast speed, low total cost of ownership, especially the characteristics of open source |
Redis |
3.2.10-2.el7 |
Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), and Zset (ordered collection). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. |
Host name |
IP |
Installing the Software |
Master |
192.168.100.188 Intranet 192.168.200.188 External network |
Front-end reverse proxy, Redis cache host MySQL data master |
Backup |
192.168.10015 |
Front-end response agent standby, Redis cache standby MySQL Slave library |
Tomcat-nodel |
192.168.100.9 |
Web Services Tomcat JDK |
Toncat-node2 |
192.168.100.10 |
Web Services Tomcat JDK |
- Implement front-end reverse proxy and test first
- Build keepalived Nginx
Nginx反向代理和keepalived-------安装带有nginx rpm软件包的源-----------主从都要做-----rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm------使用centos 默认仓库完成下面的安装----yum install -y keepalived nginx
- modifying Master profile Parameters
vi /etc/keepalived/keepalived.conf //从上修改三个参数 BACKUP 从! 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 #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 { # 虚拟IP 192.168.100.188 192.168.200.188 }}mkdir /opt/shellvi /opt/shell/nginx.sh#!/bin/bashk=`ps -ef | grep keepalived | grep -v grep | wc -l` #当keepalived 服务开启的时候会自动检测nginx 若keepalived 开启则开启nginxif [ $k -gt 0 ];then /bin/systemctl start nginx.serviceelse/bin/systemctl stop nginx.servicefichmod +x /opt/shell/nginx.sh
- Configure the Nginx front-end scheduling function
vi /etc/nginx/nginx.conf //在include 上面一行新增 upstream tomcat_pool { server 192.168.100.9:8080; # 定义web 服务主机 server 192.168.100.10:8080; ip_hash; #hash算法会话稳固功能,否则无法通过vip地址登陆 } server { listen 80; server_name 192.168.100.188; #虚拟出的IP location / { proxy_pass http://tomcat_pool; proxy_set_header X-Real-IP $remote_addr; } }nginx -t -c /etc/nginx/nginx.conf //测试配置文件语法systemctl start keepalived.service //nginx启动会等待一会-----------以上主从都要做--------------------在keepalived服务开启状态下,关闭nginx做测试,发现每隔2秒nginx又会自动启用测试主从漂移地址切换。
- Build the Tomcat JDK on the Web server
---------both---------tar xf Apache-tomcat-8.5.23.tar.gztar XF jdk-8u144-linux-x64.tar.gzcp-rv jdk1.8.0_144//usr/ Local/javavi/etc/profile # Add environment variable 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 # Immediate effect java-version #允许检测版可以看到版本信息java version "1.8.0_144" Cp-r apache-tomcat-8.5.23/usr/local/tomcat8ln-s/usr/local/ Tomcat8/bin/startup.sh/usr/bin/tomcatup #启动脚本添加到被系统识别的命令ln-S/usr/local/tomcat8/bin/shutdown.sh/usr/bin/ Tomcatdown Tomcatup # Open Service NETSTAT-ANPT | grep 8080http://192.168.100.9:8080///tests whether the default test page is displayed properly http://192.168.100.10:8080/cd/use.local/tomcat8/webapps/ROOT/ # to the Tomcat Site Directory MV index.jsp INDEX.JSP.DKVI index.jsp//modify Default Web content
Build MySQL master on the master server
yum install -y mariadb-server mariadb #安装MySQLsystemctl start mariadb.servicesystemctl enable mariadb.servicenetstat -anpt | grep 3306cd /usr/binmysql_secure_installation //常规安全设置mysql -uroot -p----------导入数据库-----------mysql -u root -p < slsaledb-2014-4-10.sqlmysql -uroot -p show databases;GRANT all ON slsaledb.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘abc123‘;flush privileges; #给与权限
----------------以下在两台tomcat节点做----------------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。------------网站测试------http://192.168.100.9:8080/ //默认的用户名admin 密码:123456http://192.168.100.10:8080/http://192.168.175.188 //输入虚拟地址测试登录,并且关闭主再测试登录
Building a Redis Cluster
----------on the primary server and from the server-----use centos7.4 default source install Yum install-y Epel-releaseyum install redis-yvi/etc/redis.conf bind 0.0.0.0 #修改systemctl Start REDIS.SERVICENETSTAT-ANPT | grep 6379redis-cli-h 192.168.175.128-p 6379//test connection 192.168.100.9:6379> set name test//Set name value is test192.168.100.10:63 79> Get name//Gets the name value from the server on more than one line configuration------266 slaveof 192.168.100.188 6379//home server IP is not virtual ipredis-cli-h 192.168.100.188 -P 6379//login from, get the value, successfully explained master-slave synchronization succeeded 192.168.100.188:6379> get name "test"-------------Configure the parameters of Redis in the marketplace project---vi/usr/local/ Tomcat8/webapps/slsalesystem/web-inf/classes/applicationcontext-mybatis.xml38 <!--redis configuration start-up 47 <constructor-arg value= "192.168.100.188"/> #虚拟IP <constructor-arg value= "6379"/>- -----------The following test cache effect-----redis-cli-h 192.168.100.188-p 6379192.168.100.188:6379> infokeyspace_hits:1 or Keyspace_ misses:2//pay attention to this value, hit number and miss number login to the mall, and then repeatedly click on the database to participate in the action page, and then come back to check keyspace_hits or keyspace_misses: value changes. Configure the Redis set---------the followingThe group master-slave Switch---only on the primary server is Operation--------redis-cli-h 192.168.175.128 info Replication//Get the role of the current server vi/etc/redis-sentinel.conf17 Protected-mode no68 Sentinel Monitor MyMaster 192.168.175.128 6379 1//1 represents 1 units from note: Modify 98 Sentinel Down-after-milliseconds MYM Aster 3000//Failover time Unit is millisecond service Redis-sentinel start//start Cluster NETSTAT-ANPT | grep 26379redis-cli-h 192.168.175.128-p 26379 Info Sentinel//View cluster information-----------Verify master-slave switching----in the Lord service Redis STOPREDIS-CL I-h 192.168.100.1-p 26379 Info Sentinel//Discovery Master becomes 1------verifying data Synchronization---redis-cli-h 192.168.175.130-p 6379 192.168.175.130:6 379> set name2 test2ok192.168.175.130:6379> get Name2 "test2" service Redis start//Turn master boot redis-cli-h 192.168.175.128 -P 6379192.168.175.128:6379> Get name2 "Test2"
MySQL Master-slave configuration
--------mysql主服务器配置-------vi /etc/my.cnf //[mysqld]下binlog-ignore-db=mysql,information_schemacharacter_set_server=utf8log_bin=mysql_binserver_id=1log_slave_updates=truesync_binlog=1systemctl restart mariadbnetstat -anpt | grep 3306mysql -u rootshow master status; //记录日志文件名称和 位置值grant replication slave on *.* to ‘rep‘@‘192.168.175.%‘ identified by ‘123456‘;flush privileges;----------mysql从服务器配置-------vi /etc/my.cnf //[mysqld]下server_id=2systemctl restart mariadbnetstat -anpt | grep 3306mysql -u rootchange master to master_host=‘192.168.175.128‘,master_user=‘rep‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=245;start slave;show slave status\G; #检测是否同步 Slave_IO_Running: Yes Slave_SQL_Running: Yes-----------以下可以测试主上操作,从同步情况-------
Mega PV website General architecture