高并发集群饿了么后端的登录模块
1.数据库
非交互式python:
非交互式:
2.数据库的负载均衡:阿里巴巴的mycat
修改配置文件
/usr/local/mycat/conf/server.xml :对外的账号 密码 数据库
/usr/local/mycat/conf/schema.xml
如果出现启动异常,8066端口没有打开,可以检查两个日志文件
vim /usr/local/mycat/logs/wrapper.log
vim /usr/local/mycat/logs/mycat.log
3.后端服务器
java|python|php
使用jar包启动服务: java -jar ...
一.配置一主二从mysql57
配置基于gtids事务复制
二.配置mycat读写分离负载均衡
使用mycat为三台数据库设置负载均衡(读写分离)
1.前期环境部署
[root@mycat ~]# ls
anaconda-ks.cfg Mycat-server-1.6.5-release-20180122220033-linux.tar.gz
jdk-8u192-linux-x64.tar.gz
[root@mycat ~]# tar -xf jdk-8u192-linux-x64.tar.gz
[root@mycat ~]# tar -xf Mycat-server-1.6.5-release-20180122220033-linux.tar.gz
[root@mycat ~]# cp -r jdk1.8.0_192/ /usr/local/jdk
[root@mycat ~]# cp -r mycat/ /usr/local/mycat
[root@mycat ~]# sed -i '$aexport JAVA_HOME=/usr/local/jdk' /etc/profile
[root@mycat ~]# source /etc/profile
[root@mycat ~]# sed -i '$aexport PATH=$PATH:$JAVA_HOME/bin' /etc/profile
[root@mycat ~]# source /etc/profile
[root@mycat ~]# javac -version
javac 1.8.0_192
[root@mycat ~]# /usr/local/mycat/bin/mycat console
2.修改server.xml配置文件
[root@mycat ~]# vim /usr/local/mycat/conf/server.xml
93 <user name="haha" defaultAccount="true">
94 <property name="password">haha</property>
95 <property name="schemas">eleme</property>
# 注释
107 <!--
108 <user name="user">
109 <property name="password">user</property>
110 <property name="schemas">TESTDB</property>
111 <property name="readOnly">true</property>
112 </user>
113 -->
3.修改schema.xml配置文件
1.设置schema标签 添加dataNode="xxx" name=eleme
2.修改dataHost标签
[root@mycat ~]# vim /usr/local/mycat/conf/schema.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
3 <mycat:schema xmlns:mycat="http://io.mycat/">
4
5 <schema name="eleme" dataNode="dn1" checkSQLschema="false" sqlMaxLimit="10 0">
6 </schema>
7 <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
8 /> -->
9 <dataNode name="dn1" dataHost="localhost1" database="eleme" />
10 <!-- <dataNode name="dn2" dataHost="localhost1" database="db2" />
11 <dataNode name="dn3" dataHost="localhost1" database="db3" />-->
12 <!--<dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" />
13 <dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" />
14 <dataNode name="jdbc_dn2" dataHost="jdbchost" database="db2" />
15 <dataNode name="jdbc_dn3" dataHost="jdbchost" database="db3" /> -->
16 <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" 17 writeType="0" dbType="mysql" dbDriver="native" switchTyp e="1" slaveThreshold="100">
18 <heartbeat>select user()</heartbeat>
19 <!-- can have multi write hosts -->
20 <writeHost host="hostM1" url="192.168.2.57:3306" user="haha"
21 password="haha">
22 <!-- can have multi read hosts --> 23 <readHost host="hostS2" url="192.168.2.58:3306" user="haha " password="haha" /> 24 <readHost host="hostS3" url="192.168.2.59:3306" user="haha " password="haha" />
25 </writeHost>
26 <!--
27 <writeHost host="hostS1" url="localhost:3316" user="root"
28 password="123456" />
29 --> 30 <!-- <writeHost host="hostM2" url="localhost:3316" user="root" pas sword="123456"/> -->
31 </dataHost>
4.启动服务
三.部署Java17环境
部署两台Java,两台操作一样:
[root@java01 ~]# ls
anaconda-ks.cfg jdk-17_linux-x64_bin.tar.gz
[root@java01 ~]# tar -xf jdk-17_linux-x64_bin.tar.gz
[root@java01 ~]# ls
anaconda-ks.cfg jdk-17.0.12 jdk-17_linux-x64_bin.tar.gz
[root@java01 ~]# cp -r jdk-17.0.12/ /usr/local/jdk
[root@java01 ~]# vim /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=$PATH:$JAVA_HOME/bin
[root@java01 ~]# source /etc/profile
[root@java01 ~]# javac --version
javac 17.0.12
[root@java01 ~]# firewall-cmd --add-port=8080/tcp --permanent
success
[root@java01 ~]# firewall-cmd --reload
success
[root@java01 ~]# ls
anaconda-ks.cfg application_(1).yml eleme_server-0.0.1-SNAPSHOT.jar jdk-17.0.12 jdk-17_linux-x64_bin.tar.gz
[root@java01 ~]# mv application_\(1\).yml application.yml
[root@java01 ~]# ls
anaconda-ks.cfg application.yml eleme_server-0.0.1-SNAPSHOT.jar jdk-17.0.12 jdk-17_linux-x64_bin.tar.gz
[root@java01 ~]# vim application.yml
server:
port: 8080
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.2.19:8066/eleme
username: haha
password: haha
[root@java01 ~]# java -jar eleme_server-0.0.1-SNAPSHOT.jar
浏览器访问:Java的ip:8080,出现登录页面
四.部署LVS-DR模式
lvs负载均衡两台后端服务器Java
lvs:
[root@lvs ~]# ifconfig ens33:0 192.168.2.150 broadcast 192.168.2.121 netmask 255.255.255.255 up
[root@lvs ~]# route add -host 192.168.2.150 dev ens33:0
[root@lvs ~]# yum -y install ipvsadm
[root@lvs ~]# ipvsadm -C
[root@lvs ~]# ipvsadm -A -t 192.168.2.150:8080 -s rr
[root@lvs ~]# ipvsadm -a -t 192.168.2.150:8080 -r 192.168.2.11 -g
[root@lvs ~]# ipvsadm -a -t 192.168.2.150:8080 -r 192.168.2.12 -g
[root@lvs ~]# systemctl stop firewalld
[root@lvs ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@lvs ~]# setenforce 0
[root@lvs ~]# systemctl stop firewalld
[root@lvs ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.2.150:8080 rr
-> 192.168.2.11:8080 Route 1 0 1
-> 192.168.2.12:8080 Route 1 0 1
两台java:
[root@java01 ~]# ifconfig lo:0 192.168.2.150 broadcast 192.168.2.150 netmask 255.255.255.255 up
[root@java01 ~]# route add -host 192.168.2.150 dev lo:0
[root@java01 ~]# vim arp.sh
[root@java01 ~]# source arp.sh
访问:访问lvs的vip地址:8080,出现登录页
五.nginx代理端口
在lvs上下载nginx,代理8080端口
/etc/nginx/nginx.conf
server localhost:8080
server java服务器ip:8080