Each node in the cluster registry Eureka Server are equal, each node can act as a service, to vote between the service node by sending a heartbeat.
The project relies eurekaServer modify the stand-alone version of the content.
1. Create a new file application-eurekaserver1.properties
spring.application.name=eureka-server
server.port=8761
# Define named Eureka Server instances in the registration center. We recommend using the suffix defined in the configuration file.
eureka.instance.hostname=eurekaserver1
# Cluster configuration information other Eureka Server nodes. To configure a plurality of nodes, using a comma ',' a plurality of split node information.
# Node information format is: http: // address: port / eureka /. You can use the address IP, domain name, host name is defined.
# Using HTTP Basic syntax, provide a user name and password authentication security required for use.
# Syntax is: http: // username: password @ address: port / eureka /
eureka.client.serviceUrl.defaultZone=http://eurekaserver2:8761/eureka/
application-eurekaserver2.properties
spring.application.name=eureka-server
server.port=8761
# Define named Eureka Server instances in the registration center. We recommend using the suffix defined in the configuration file.
eureka.instance.hostname=eurekaserver1
# Cluster configuration information other Eureka Server nodes. To configure a plurality of nodes, using a comma ',' a plurality of split node information.
# Node information format is: http: // address: port / eureka /. You can use the address IP, domain name, host name is defined.
# Using HTTP Basic syntax, provide a user name and password authentication security required for use.
# Syntax is: http: // username: password @ address: port / eureka /
eureka.client.serviceUrl.defaultZone=http://eurekaserver2:8761/eureka/
2. Modify the host name, vi / etc / hosts
192.168.186.115 eurekaserver1 192.168.186.116 eurekaserver2
3. Use Maven install packaged jar, the target directory project, the two are uploaded to the server
4. In the same directory jar package upload new file, vi eurekaserver.sh, modifying the corresponding parameter
#!/bin/bash cd `dirname $0` CUR_SHELL_DIR = ` pwd ` CUR_SHELL_NAME=`basename ${BASH_SOURCE}` Jar_name = " Project jar package name " JAR_PATH = $ CUR_SHELL_DIR / $ jar_name #JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m" JAVA_MEM_OPTS="" SPRING_PROFILES_ACTIV = " -Dspring.profiles.active configuration file variable name = " #SPRING_PROFILES_ACTIV = "" LOG_DIR = $ CUR_SHELL_DIR / logs LOG_PATH=$LOG_DIR/${JAR_NAME%..log echo_help() { echo -e "syntax: sh $CUR_SHELL_NAME start|stop" } if [ -z $1 ];then echo_help exit 1 fi if [ ! -d "$LOG_DIR" ];then mkdir "$LOG_DIR" fi if [ ! -f "$LOG_PATH" ];then touch "$LOG_DIR" fi if [ "$1" == "start" ];then # check server PIDS=`ps --no-heading -C java -f --width 1000 | grep $JAR_NAME | awk '{print $2}'` if [ -n "$PIDS" ]; then echo -e "ERROR: The $JAR_NAME already started and the PID is ${PIDS}." exit 1 fi echo "Starting the $JAR_NAME..." # start nohup java $JAVA_MEM_OPTS -jar $SPRING_PROFILES_ACTIV $JAR_PATH >> $LOG_PATH 2>&1 & COUNT=0 while [ $COUNT -lt 1 ]; do sleep 1 COUNT=`ps --no-heading -C java -f --width 1000 | grep "$JAR_NAME" | awk '{print $2}' | wc -l` if [ $COUNT -gt 0 ]; then break fi done PIDS=`ps --no-heading -C java -f --width 1000 | grep "$JAR_NAME" | awk '{print $2}'` echo "${JAR_NAME} Started and the PID is ${PIDS}." echo "You can check the log file in ${LOG_PATH} for details." elif [ "$1" == "stop" ];then PIDS=`ps --no-heading -C java -f --width 1000 | grep $JAR_NAME | awk '{print $2}'` if [ -z "$PIDS" ]; then echo "ERROR:The $JAR_NAME does not started!" exit 1 fi echo -e "Stopping the $JAR_NAME..." for PID in $PIDS; do kill $PID > /dev/null 2>&1 done COUNT=0 while [ $COUNT -lt 1 ]; do sleep 1 COUNT=1 for PID in $PIDS ; do PID_EXIST=`ps --no-heading -p $PID` if [ -n "$PID_EXIST" ]; then COUNT=0 break fi done done echo -e "${JAR_NAME} Stopped and the PID is ${PIDS}." else echo_help exit 1 fi
Modify executable permission
chmod 755 eurekaserver.sh
Start Server Eureka -. ./Eurekaserver SH Start Close Server Eureka -. ./Eurekaserver SH STOP