<rollingPolicy class="ch.qos.logback.core.rolling.Ti
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
meBasedRollingPolicy">
${LOG_HOME}/server.%d{yyyy-MM-dd}.log
30
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
10MB
3.项目打包
将项目打成一个jar包
部署环境:需要安装 jdk1.8,正确配置环境变量。
注意:需要关闭 linux 的防火墙,或者是开放 8761 端口
1.上传实例
在/usr/local/创建一个 eureka 的目录
将项目的 jar 包拷贝到/usr/local/eureka
2.编写一个启动脚本文件
项目名称:替换为 jar包名称
配置文件变量名称:替换为对应的 eureka1和eureka2
#!/bin/bash
cd dirname $0
CUR_SHELL_DIR=pwd
CUR_SHELL_NAME=basename ${BASH_SOURCE}
JAR_NAME=“项目名称”
JAR_PATH= C U R S H E L L D I R / CUR_SHELL_DIR/ CURSHELLDIR/JAR_NAME
#JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m"
JAVA_MEM_OPTS=""
SPRING_PROFILES_ACTIV="-Dspring.profiles.active=配置文件变量名称"
#SPRING_PROFILES_ACTIV=""
LOG_DIR=$CUR_SHELL_DIR/logs
LOG_PATH= L O G D I R / LOG_DIR/ LOGDIR/{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