VM build a service consumer cluster.
① draw SpringCloud XI virtual machine build eureka cluster, install jdk1.8 in Linux, bash: /usr/java/jdk1.8.0_11/bin/java: CAN not the Execute BiNa . Set up a virtual machine, installed jdk1.8.
② draw electricity supplier sixty-one, Nginx installation and startup . Nginx consumer01,02,03 are mounted on the machine node. Later discovered, do not install nginx.
③ draw electricity supplier sixty-two, Nginx load balancing availability, keepalived + nginx Nginx achieve cluster, and two main distributor equipment distributor (may be more than one backup distributor) . Keepalived consumer01,02,03 are mounted on the machine node. Linux create a file with touch, create a folder with mkdir.
④consumer subproject pom files need to add the following:
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.125</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-autoscaling</artifactId>
<version>1.11.125</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-bom -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.125</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ec2</artifactId>
<version>1.11.125</version>
</dependency>
<!-- <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-pom</artifactId>
<version>1.11.125</version> </dependency> -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<version>1.11.125</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jdom/jdom2 -->
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.vafer</groupId>
<artifactId>jdependency</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>7.0-beta</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-analysis</artifactId>
<version>7.0-beta</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
<version>7.0-beta</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>7.0-beta</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>7.0-beta</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-loader-tools</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>1.0.2.v20150114</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
</dependencies>
<!-- <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target>
</configuration> </plugin> <plugin> <artifactId> maven-assembly-plugin </artifactId>
<configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs> <archive> <manifest> <mainClass>com.lss.springcloud.EurekaServer7001_App</mainClass>
</manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id>
<phase>package</phase> <goals> <goal>single</goal> </goals> </execution>
</executions> </plugin> </plugins> </build> -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Then maven clean, install.
⑤ do not install nginx. Keepalived.conf configuration file directly. The first node configuration service consumers.
cd / etc / keepalived /
vi keepalived.conf
keepalived.cnf content is:
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/etc/keepalived/microservicejar.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
unicast_src_ip 192.168.10.115
unicast_peer {
192.168.10.116
192.168.10.117
}
virtual_ipaddress {
192.168.100.188
}
}
cd /etc/keepalived
touch microservicejar.sh
we /etc/keepalived/microservicejar.sh
microservicejar.sh contents are:
#!/bin/sh
ps -fe | grep microservicecloud.jar | grep -v grep
if [ $? -ne 0 ]
then
service keepalived stop
fi
If it is found not bind the virtual IP, you might have forgotten to perform the following steps:
chmod +x /etc/keepalived/microservicejar.sh
To give permission to the script.
ip a
You can see be bound.
⑥ configure the second node serving consumers.
vim /etc/keepalived/keepalived.conf
keepalived.conf 的内容是:
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/etc/keepalived/microservicejar.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
unicast_src_ip 192.168.10.116
unicast_peer {
192.168.10.115
192.168.10.117
}
virtual_ipaddress {
192.168.100.188
}
}
vim /etc/keepalived/microservicejar.sh
microservicejar.sh 的内容是:
#!/bin/sh
ps -fe | grep microservicecloud.jar | grep -v grep
if [ $? -ne 0 ]
then
service keepalived stop
fi
如果发现不能绑定虚拟IP,则可能是忘记执行以下步骤:
chmod +x /etc/keepalived/microservicejar.sh
给脚本赋予权限。
⑦配置第三台服务消费者节点。
vim /etc/keepalived/keepalived.conf
keepalived.conf 的内容是:
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/etc/keepalived/microservicejar.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth2
virtual_router_id 51
# nopreempt
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
unicast_src_ip 192.168.10.117
unicast_peer {
192.168.10.115
192.168.10.116
}
virtual_ipaddress {
192.168.100.188
}
}
vi /etc/keepalived/microservicejar.sh
microservicejar.sh 的内容是:
#!/bin/sh
ps -fe | grep microservicecloud.jar | grep -v grep
if [ $? -ne 0 ]
then
service keepalived stop
fi
如果发现不能绑定虚拟IP,则可能是忘记执行以下步骤:
chmod +x /etc/keepalived/microservicejar.sh
给脚本赋予权限。
至此可以达到ribbon的负载均衡高可用。