diff --git a/codes/linux/build/spring-boot-run.sh b/codes/linux/build/spring-boot-run.sh new file mode 100644 index 0000000..d41a048 --- /dev/null +++ b/codes/linux/build/spring-boot-run.sh @@ -0,0 +1,152 @@ +#!/usr/bin/env bash + +############################################################################## +# console color +BLACK="\033[1;30m" +RED="\033[1;31m" +GREEN="\033[1;32m" +YELLOW="\033[1;33m" +BLUE="\033[1;34m" +PURPLE="\033[1;35m" +CYAN="\033[1;36m" +RESET="$(tput sgr0)" +############################################################################## + +JAVA_OPTS="" +APP_OPTS="" +packageJavaOpts() { + + # GC OPTS + JAVA_OPTS="${JAVA_OPTS} -server -Xms8g -Xmx16g -Xss512k" + JAVA_OPTS="${JAVA_OPTS} -XX:+UseParallelOldGC -XX:+UseAdaptiveSizePolicy -XX:MaxGCPauseMillis=150" + JAVA_OPTS="${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom" + + # DEBUG OPTS + if [[ ${debug} == "on" ]]; then + + # Remote Debug + JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xnoagent -Djava.compiler=NONE" + JAVA_OPTS="${JAVA_OPTS} -Xrunjdwp:transport=dt_socket,address=28889,server=y,suspend=n" + + # GC LOG + JAVA_OPTS="${JAVA_OPTS} -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps" + JAVA_OPTS="${JAVA_OPTS} -verbose:gc -Xloggc:${LOG_PATH}/${APP_NAME}.gc.log" + JAVA_OPTS="${JAVA_OPTS} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M" + + # Heap Dump + JAVA_OPTS="${JAVA_OPTS} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError" + JAVA_OPTS="${JAVA_OPTS} -XX:HeapDumpPath=${LOG_PATH}/${APP_NAME}.heapdump.hprof" + + # JMX OPTS + IP=`ip addr|grep "inet "|grep -v 127.0.0.1|awk '{print $2}'|cut -d/ -f1` + JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote=true" + JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" + JAVA_OPTS="${JAVA_OPTS} -Djava.rmi.server.hostname=${IP} -Dcom.sun.management.jmxremote.port=18889" + fi + + # APP OPTS + JAVA_OPTS="${JAVA_OPTS} -Dsun.net.inetaddr.ttl=60 -Djava.net.preferIPv4Stack=true" + JAVA_OPTS="${JAVA_OPTS} -Dspring.profiles.active=${profile} -Dfile.encoding=UTF-8" + + # CLASSPATH + APP_OPTS=" -classpath lib/* -Dlogging.config=file:./config/logback.dev.xml --spring.config.location=classpath:/,classpath:/config/,file:./,file:./config/" +} + +# 检查服务是否已经启动 +pid="" +checkStarted() { + pid=`ps -ef | grep java | grep ${APP_NAME} | awk '{print $2}'` + if [[ -n "${pid}" ]]; then + return 0 + else + return 1 + fi +} + +main() { + case "${oper}" in + start ) + startServer + ;; + stop ) + stopServer + ;; + restart ) + stopServer + sleep 5 + startServer + ;; + * ) + echo "Invalid oper: ${oper}." + exit 1 + esac + + exit 0 +} + +stopServer() { + echo -n "stopping server: " + if checkStarted ;then + kill -9 ${pid} + printf "${GREEN}\n${APP_NAME} is stopped.${RESET}\n" + else + printf "${RED}\n${APP_NAME} fail to stop.${RESET}\n" + fi +} + +startServer() { + printf "${BLUE}starting ${APP_NAME}...${RESET}\n" + if checkStarted ;then + printf "${YELLOW}[WARN] ${APP_NAME} already started!${RESET}\n" + printf "PID: ${pid}\n" + exit 1 + fi + + packageJavaOpts + printf "${CYAN}JVM OPTS:\n ${JAVA_OPTS}${RESET}\n" + if [[ ! -f "${LOG_PATH}/start.out" ]]; then + touch "${LOG_PATH}/start.out" + fi + nohup java ${JAVA_OPTS} -jar ${ROOT_DIR}/../spring-boot-app.jar ${APP_OPTS} >> ${LOG_PATH}/start.out 2>&1 & + printf "${GREEN}\n${APP_NAME} is started.${RESET}\n" +} + +######################################## MAIN ######################################## +# 设置环境变量 +export LANG="zh_CN.UTF-8" +ROOT_DIR=$(pwd) + +APP_NAME=spring-boot-app +LOG_PATH=${ROOT_DIR}/../logs +mkdir -p ${LOG_PATH} + +declare -a serial +serial=(start stop restart) +echo -n "请选择操作(可选值:start|stop|restart):" +read oper +if ! echo "${serial[@]}" | grep -q ${oper}; then + echo "请选择正确操作(可选值:start|stop|restart)" + exit 1 +fi + +if [[ ${oper} == "start" ]] || [[ "${oper}" == "restart" ]]; then + declare -a serial2 + serial2=(prod dev test) + echo -n "选择 profile(可选值:prod|dev|test):" + read profile + if ! echo "${serial2[@]}" | grep -q ${profile}; then + echo "请选择正确 profile(可选值:prod|dev|test)" + exit 1 + fi + + declare -a serial3 + serial3=(on off) + echo -n "是否启动 debug 模式(可选值:on|off):" + read debug + if ! echo "${serial3[@]}" | grep -q ${debug}; then + echo "是否启动 debug 模式(可选值:on|off)" + exit 1 + fi +fi + +main diff --git a/codes/linux/dunwu-ops.sh b/codes/linux/dunwu-ops.sh index 0422d6d..80f9204 100644 --- a/codes/linux/dunwu-ops.sh +++ b/codes/linux/dunwu-ops.sh @@ -63,7 +63,7 @@ checkOsVersion() { menus=( "配置系统" "安装软件" "退出" ) main() { PS3="请输入命令编号:" - select item in ${menus[@]} + select item in "${menus[@]}" do case ${item} in "配置系统") diff --git a/codes/linux/dunwu-sys.sh b/codes/linux/dunwu-sys.sh index e493bde..0002424 100644 --- a/codes/linux/dunwu-sys.sh +++ b/codes/linux/dunwu-sys.sh @@ -12,7 +12,7 @@ EOF menus=( "替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出" ) main() { PS3="请输入命令编号:" - select item in ${menus[@]} + select item in "${menus[@]}" do case ${item} in "替换yum镜像") diff --git a/codes/linux/soft/arthas-install.sh b/codes/linux/soft/arthas-install.sh new file mode 100644 index 0000000..3266f88 --- /dev/null +++ b/codes/linux/soft/arthas-install.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# ---------------------------------------------------------------------------------- +# 控制台颜色 +BLACK="\033[1;30m" +RED="\033[1;31m" +GREEN="\033[1;32m" +YELLOW="\033[1;33m" +BLUE="\033[1;34m" +PURPLE="\033[1;35m" +CYAN="\033[1;36m" +RESET="$(tput sgr0)" +# ---------------------------------------------------------------------------------- + +printf "${PURPLE}" +cat << EOF +# ---------------------------------------------------------------------------------- +# Arthas 安装脚本 +# @author: Zhang Peng +# ---------------------------------------------------------------------------------- +EOF +printf "${RESET}" + +printf "${BLUE}>>>>>>>> begin.\n${RESET}" + +root=/opt/arthas +if [[ -n $1 ]]; then + root=$1 +fi + +mkdir -p ${root} +curl -o ${root}/arthas-boot.jar https://alibaba.github.io/arthas/arthas-boot.jar + +printf "${GREEN}[OK]\n${RESET}" +printf "${BLUE}<<<<<<<< end.\n${RESET}" diff --git a/codes/linux/soft/config/settings-aliyun.xml b/codes/linux/soft/config/settings-aliyun.xml index a996086..a71a89c 100644 --- a/codes/linux/soft/config/settings-aliyun.xml +++ b/codes/linux/soft/config/settings-aliyun.xml @@ -1,7 +1,8 @@ - + @@ -18,4 +19,4 @@ central - \ No newline at end of file + diff --git a/codes/linux/soft/elk/config/filebeat.yml b/codes/linux/soft/elk/config/filebeat.yml index c11956c..d51ef33 100644 --- a/codes/linux/soft/elk/config/filebeat.yml +++ b/codes/linux/soft/elk/config/filebeat.yml @@ -14,54 +14,54 @@ filebeat.prospectors: -# Each - is a prospector. Most options can be set at the prospector level, so -# you can use different prospectors for various configurations. -# Below are the prospector specific configurations. + # Each - is a prospector. Most options can be set at the prospector level, so + # you can use different prospectors for various configurations. + # Below are the prospector specific configurations. -- type: log + - type: log - # Change to true to enable this prospector configuration. - enabled: true + # Change to true to enable this prospector configuration. + enabled: true - # Paths that should be crawled and fetched. Glob based paths. - paths: - #- /var/log/*.log - #- c:\programdata\elasticsearch\logs\* - - /home/zp/log/*.log + # Paths that should be crawled and fetched. Glob based paths. + paths: + #- /var/log/*.log + #- c:\programdata\elasticsearch\logs\* + - /home/zp/log/*.log - # Exclude lines. A list of regular expressions to match. It drops the lines that are - # matching any regular expression from the list. - #exclude_lines: ['^DBG'] + # Exclude lines. A list of regular expressions to match. It drops the lines that are + # matching any regular expression from the list. + #exclude_lines: ['^DBG'] - # Include lines. A list of regular expressions to match. It exports the lines that are - # matching any regular expression from the list. - #include_lines: ['^ERR', '^WARN'] + # Include lines. A list of regular expressions to match. It exports the lines that are + # matching any regular expression from the list. + #include_lines: ['^ERR', '^WARN'] - # Exclude files. A list of regular expressions to match. Filebeat drops the files that - # are matching any regular expression from the list. By default, no files are dropped. - #exclude_files: ['.gz$'] + # Exclude files. A list of regular expressions to match. Filebeat drops the files that + # are matching any regular expression from the list. By default, no files are dropped. + #exclude_files: ['.gz$'] - # Optional additional fields. These fields can be freely picked - # to add additional information to the crawled log files for filtering - #fields: - # level: debug - # review: 1 + # Optional additional fields. These fields can be freely picked + # to add additional information to the crawled log files for filtering + #fields: + # level: debug + # review: 1 - ### Multiline options + ### Multiline options - # Mutiline can be used for log messages spanning multiple lines. This is common - # for Java Stack Traces or C-Line Continuation + # Mutiline can be used for log messages spanning multiple lines. This is common + # for Java Stack Traces or C-Line Continuation - # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [ - #multiline.pattern: ^\[ + # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [ + #multiline.pattern: ^\[ - # Defines if the pattern set under pattern should be negated or not. Default is false. - #multiline.negate: false + # Defines if the pattern set under pattern should be negated or not. Default is false. + #multiline.negate: false - # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern - # that was (not) matched before or after or as long as a pattern is not matched based on negate. - # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash - #multiline.match: after + # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern + # that was (not) matched before or after or as long as a pattern is not matched based on negate. + # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash + #multiline.match: after #============================= Filebeat modules =============================== @@ -123,25 +123,25 @@ setup.kibana: # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601 host: "192.168.28.11:5601" -#============================= Elastic Cloud ================================== + #============================= Elastic Cloud ================================== -# These settings simplify using filebeat with the Elastic Cloud (https://cloud.elastic.co/). + # These settings simplify using filebeat with the Elastic Cloud (https://cloud.elastic.co/). -# The cloud.id setting overwrites the `output.elasticsearch.hosts` and -# `setup.kibana.host` options. -# You can find the `cloud.id` in the Elastic Cloud web UI. -#cloud.id: + # The cloud.id setting overwrites the `output.elasticsearch.hosts` and + # `setup.kibana.host` options. + # You can find the `cloud.id` in the Elastic Cloud web UI. + #cloud.id: -# The cloud.auth setting overwrites the `output.elasticsearch.username` and -# `output.elasticsearch.password` settings. The format is `:`. -#cloud.auth: + # The cloud.auth setting overwrites the `output.elasticsearch.username` and + # `output.elasticsearch.password` settings. The format is `:`. + #cloud.auth: -#================================ Outputs ===================================== + #================================ Outputs ===================================== -# Configure what output to use when sending the data collected by the beat. + # Configure what output to use when sending the data collected by the beat. -#-------------------------- Elasticsearch output ------------------------------ -#output.elasticsearch: + #-------------------------- Elasticsearch output ------------------------------ + #output.elasticsearch: # Array of hosts to connect to. #hosts: ["192.168.28.11:9200"] diff --git a/codes/linux/soft/elk/config/logback.xml b/codes/linux/soft/elk/config/logback.xml index c86d34a..a174cf9 100644 --- a/codes/linux/soft/elk/config/logback.xml +++ b/codes/linux/soft/elk/config/logback.xml @@ -3,7 +3,7 @@ - + @@ -45,12 +45,12 @@ - - + + - +