update scripts

pull/11/head
Zhang Peng 2019-10-24 22:00:00 +08:00
parent 90908bb378
commit 2b73cbc127
15 changed files with 471 additions and 381 deletions

View File

@ -1,4 +1,4 @@
# Linux 傻瓜式运维脚本 # Dunwu Shell 运维脚本
> **本项目脚本代码用于在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。** > **本项目脚本代码用于在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。**

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
################################################################################### # ---------------------------------------------------------------------------------
# 控制台颜色 # 控制台颜色
BLACK="\033[1;30m" BLACK="\033[1;30m"
RED="\033[1;31m" RED="\033[1;31m"
@ -10,11 +10,10 @@ BLUE="\033[1;34m"
PURPLE="\033[1;35m" PURPLE="\033[1;35m"
CYAN="\033[1;36m" CYAN="\033[1;36m"
RESET="$(tput sgr0)" RESET="$(tput sgr0)"
################################################################################### # ---------------------------------------------------------------------------------
printf "${BLUE}" printf "${BLUE}\n"
cat << EOF cat << EOF
################################################################################### ###################################################################################
# linux-tutorial 运维脚本工具集下载脚本 # linux-tutorial 运维脚本工具集下载脚本
# 下载 https://github.com/dunwu/linux-tutorial 中的所有脚本到当前服务器的 # 下载 https://github.com/dunwu/linux-tutorial 中的所有脚本到当前服务器的
@ -23,23 +22,27 @@ cat << EOF
# @author: Zhang Peng # @author: Zhang Peng
# See: https://github.com/dunwu/linux-tutorial # See: https://github.com/dunwu/linux-tutorial
################################################################################### ###################################################################################
EOF EOF
printf "${RESET}" printf "${RESET}\n"
path=/home/scripts/linux-tutorial root=/home/scripts/linux-tutorial
printf "\n${GREEN}>>>>>>>> Download linux-tutorial to ${path} begin.${RESET}\n" printf "\n${GREEN}>>>>>>>> Download linux-tutorial to ${root} begin.${RESET}\n"
command -v yum > /dev/null 2>&1 || { printf "${RED}Not detected yum.${RESET}"; command -v yum > /dev/null 2>&1 || {
exit 1; } printf "\n${RED}Not detected yum.${RESET}";
command -v git > /dev/null 2>&1 || { printf "${YELLOW}Not detected git. Install git.${RESET}\n"; exit 1;
yum -y install git; } }
if [[ -d ${path} ]]; then command -v git > /dev/null 2>&1 || {
cd ${path} printf "\n${YELLOW}Not detected git. Install git.${RESET}\n";
yum install -y git;
}
if [[ -d ${root} ]]; then
cd ${root}
git pull git pull
else else
mkdir -p ${path} mkdir -p ${root}
git clone https://gitee.com/turnon/linux-tutorial.git ${path} git clone https://gitee.com/turnon/linux-tutorial.git ${root}
fi fi
chmod +x -R ${path} chmod +x -R ${root}
printf "\n${GREEN}<<<<<<<< Download linux-tutorial to ${path} end.${RESET}\n" printf "\n${GREEN}<<<<<<<< Download linux-tutorial to ${root} end.${RESET}\n"

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
################################################################################### # ---------------------------------------------------------------------------------
# 控制台颜色 # 控制台颜色
BLACK="\033[1;30m" BLACK="\033[1;30m"
RED="\033[1;31m" RED="\033[1;31m"
@ -10,82 +10,74 @@ BLUE="\033[1;34m"
PURPLE="\033[1;35m" PURPLE="\033[1;35m"
CYAN="\033[1;36m" CYAN="\033[1;36m"
RESET="$(tput sgr0)" RESET="$(tput sgr0)"
################################################################################### # ---------------------------------------------------------------------------------
# 打印头部信息 # 打印头部信息
printHeadInfo() { printHeadInfo() {
printf "${BLUE}" printf "${BLUE}\n"
cat << EOF cat << EOF
###################################################################################
*********************************************************************************** # 欢迎使用 Dunwu Shell 运维脚本
* 欢迎使用 Linux CentOS 环境运维脚本 # 适用于 Linux CentOS 环境
* @author: Zhang Peng # @author: Zhang Peng
*********************************************************************************** ###################################################################################
EOF EOF
printf "${RESET}" printf "${RESET}\n"
} }
# 打印尾部信息 # 打印尾部信息
printFootInfo() { printFootInfo() {
printf "${BLUE}" printf "${BLUE}\n"
cat << EOF cat << EOF
###################################################################################
*********************************************************************************** # 脚本执行结束,感谢使用!
* 脚本执行结束,感谢使用! ###################################################################################
***********************************************************************************
EOF EOF
printf "${RESET}" printf "${RESET}\n"
} }
# 检查操作系统环境 # 检查操作系统环境
checkOsVersion() { checkOsVersion() {
if (($1 == 1)); then if (($1 == 1)); then
echo -e "检查操作系统环境是否兼容本套脚本"
platform=`uname -i` platform=`uname -i`
if [[ ${platform} != "x86_64" ]]; then if [[ ${platform} != "x86_64" ]]; then
echo "脚本仅支持 64 位操作系统!" printf "\n${RED}脚本仅支持 64 位操作系统!${RESET}\n"
exit 1 exit 1
fi fi
version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'` version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'`
if [[ ${version} != 7 ]]; then if [[ ${version} != 7 ]]; then
echo "脚本仅支持 CentOS 7" printf "\n${RED}脚本仅支持 CentOS 7${RESET}\n"
exit 1 exit 1
fi fi
echo -e "脚本可以在本环境运行!"
fi fi
} }
menus=( "配置系统" "安装软件" "退出" ) menus=( "配置系统" "安装软件" "退出" )
main() { selectAndExecTask() {
printHeadInfo
PS3="请输入命令编号:" PS3="请输入命令编号:"
select item in "${menus[@]}" select item in "${menus[@]}"
do do
case ${item} in case ${item} in
"配置系统") "配置系统")
./dunwu-sys.sh ./dunwu-sys.sh
main ;; selectAndExecTask ;;
"安装软件") "安装软件")
./dunwu-soft.sh ./dunwu-soft.sh
main ;; selectAndExecTask ;;
"退出") "退出")
exit 0 ;; printFootInfo
*) exit 0 ;;
printf "输入项不支持!\n" *)
main ;; printf "\n${RED}输入项不支持!${RESET}\n"
selectAndExecTask ;;
esac esac
break break
done done
} }
######################################## MAIN ######################################## ######################################## MAIN ########################################
path=$(cd "$(dirname "$0")"; checkOsVersion 1
pwd) selectAndExecTask
printHeadInfo
checkOsVersion 0
main
printFootInfo

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
################################################################################### # ---------------------------------------------------------------------------------
# 控制台颜色 # 控制台颜色
BLACK="\033[1;30m" BLACK="\033[1;30m"
RED="\033[1;31m" RED="\033[1;31m"
@ -10,52 +10,57 @@ BLUE="\033[1;34m"
PURPLE="\033[1;35m" PURPLE="\033[1;35m"
CYAN="\033[1;36m" CYAN="\033[1;36m"
RESET="$(tput sgr0)" RESET="$(tput sgr0)"
################################################################################### # ---------------------------------------------------------------------------------
printf "${BLUE}\n" printf "${BLUE}\n"
cat << EOF cat << EOF
###################################################################################
*********************************************************************************** # 欢迎使用 Dunwu Shell 软件安装脚本
* 欢迎使用 Linux CentOS 软件安装配置脚本 # 适用于 Linux CentOS 环境
* @author: Zhang Peng # @author: Zhang Peng
*********************************************************************************** ###################################################################################
EOF EOF
printf "${RESET}\n"
# print menu # print menu
printf "${PURPLE}" printMenu() {
menus=( docker fastdfs gitlab jdk8 jenkins kafka maven mongodb mysql nacos nexus nginx nodejs redis rocketmq tomcat8 printf "${PURPLE}"
zookeeper zsh exit ) menus=( docker fastdfs gitlab jdk8 jenkins kafka maven mongodb mysql nacos nexus nginx nodejs redis rocketmq tomcat8 zookeeper zsh exit )
for i in "${!menus[@]}"; do for i in "${!menus[@]}"; do
index=`expr ${i} + 1` index=`expr ${i} + 1`
val=`expr ${index} % 2` val=`expr ${index} % 2`
printf "[%02d] %-20s" "${index}" "${menus[$i]}" printf "[%02d] %-20s" "${index}" "${menus[$i]}"
if [[ ${val} -eq 0 ]]; then if [[ ${val} -eq 0 ]]; then
printf "\n" printf "\n"
fi fi
done done
printf "\n${RESET}请输入需要安装的软件编号:\n"
printf "\n\n${BLUE}请选择需要安装的软件:${RESET}"
}
# exec shell to install soft # exec shell to install soft
doInstall() { main() {
printMenu
read -t 30 index read -t 30 index
if [[ -n ${index} ]]; then if [[ -n ${index} ]]; then
no=`expr ${index} - 1` no=`expr ${index} - 1`
len=${#menus[*]} len=${#menus[*]}
if [[ ${index} -gt ${len} ]]; then if [[ ${index} -gt ${len} ]]; then
echo "输入项不支持!" printf "${RED}输入项不支持!\n${RESET}"
exit -1 exit -1
fi fi
key=${menus[$no]} key=${menus[$no]}
if [[ key == 'exit' ]]; then if [[ ${key} == 'exit' ]]; then
printf "${GREEN}退出 Dunwu 软件安装脚本。\n${RESET}"
exit 0 exit 0
fi fi
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/${key}-install.sh | bash sh soft/${key}-install.sh
doInstall printf "\n"
main
else else
echo "输入项不支持!" printf "${RED}输入项不支持!\n${RESET}"
exit -1 exit -1
fi fi
} }
doInstall main

View File

@ -1,13 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cat << EOF # ---------------------------------------------------------------------------------
# 控制台颜色
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 "${BLUE}\n"
cat << EOF
################################################################################### ###################################################################################
# Linux CentOS 环境初始化脚本(设置环境配置、安装基本的命令工具) # 欢迎使用 Dunwu Shell 环境初始化脚本(设置环境配置、安装基本的命令工具)
# 适用于 Linux CentOS 环境
# @author: Zhang Peng # @author: Zhang Peng
################################################################################### ###################################################################################
EOF EOF
printf "${RESET}\n"
menus=( "替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出" ) menus=( "替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出" )
main() { main() {
@ -15,33 +28,34 @@ main() {
select item in "${menus[@]}" select item in "${menus[@]}"
do do
case ${item} in case ${item} in
"替换yum镜像") "替换yum镜像")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/change-yum-repo.sh | bash sh ${root}/sys/change-yum-repo.sh
main ;; main ;;
"安装基本的命令工具") "安装基本的命令工具")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-tools.sh | bash sh ${root}/sys/install-tools.sh
main ;; main ;;
"安装常用libs") "安装常用libs")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-libs.sh | bash sh ${root}/sys/install-libs.sh
main ;; main ;;
"系统配置") "系统配置")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/sys-settings.sh | bash sh ${root}/sys/sys-settings.sh ${root}/sys
main ;; main ;;
"全部执行") "全部执行")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/change-yum-repo.sh | bash sh ${root}/sys/change-yum-repo.sh
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-tools | bash sh ${root}/sys/install-tools.sh
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-libs.sh | bash sh ${root}/sys/install-libs.sh
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/sys-settings.sh | bash sh ${root}/sys/sys-settings.sh ${root}/sys
printf "执行完毕,退出。\n" ;; printf "${GREEN}执行完毕,退出。${RESET}\n" ;;
"退出") "退出")
exit 0 ;; exit 0 ;;
*) *)
printf "输入项不支持!\n" printf "${RED}输入项不支持!${RESET}\n"
main ;; main ;;
esac esac
break break
done done
} }
######################################## MAIN ######################################## ######################################## MAIN ########################################
root=$(pwd)
main main

View File

@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- 使用 aliyun maven 仓库加速下载 --> <!-- 使用 aliyun maven 仓库加速下载 -->
<mirrors> <mirrors>
<mirror> <mirror>
<id>aliyun</id> <id>aliyun</id>
<name>Aliyun</name> <name>Aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url> <url>http://maven.aliyun.com/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf> <mirrorOf>central</mirrorOf>
</mirror> </mirror>
<mirror> <mirror>
<id>repo2</id> <id>repo2</id>
<name>Mirror from Maven Repo2</name> <name>Mirror from Maven Repo2</name>
<url>http://repo2.maven.org/maven2/</url> <url>http://repo2.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf> <mirrorOf>central</mirrorOf>
</mirror> </mirror>
</mirrors> </mirrors>
</settings> </settings>

View File

@ -14,74 +14,74 @@
filebeat.prospectors: filebeat.prospectors:
# Each - is a prospector. Most options can be set at the prospector level, so # Each - is a prospector. Most options can be set at the prospector level, so
# you can use different prospectors for various configurations. # you can use different prospectors for various configurations.
# Below are the prospector specific configurations. # Below are the prospector specific configurations.
- type: log - type: log
# Change to true to enable this prospector configuration. # Change to true to enable this prospector configuration.
enabled: true enabled: true
# Paths that should be crawled and fetched. Glob based paths. # Paths that should be crawled and fetched. Glob based paths.
paths: paths:
#- /var/log/*.log #- /var/log/*.log
#- c:\programdata\elasticsearch\logs\* #- c:\programdata\elasticsearch\logs\*
- /home/zp/log/*.log - /home/zp/log/*.log
# Exclude lines. A list of regular expressions to match. It drops the lines that are # Exclude lines. A list of regular expressions to match. It drops the lines that are
# matching any regular expression from the list. # matching any regular expression from the list.
#exclude_lines: ['^DBG'] #exclude_lines: ['^DBG']
# Include lines. A list of regular expressions to match. It exports the lines that are # Include lines. A list of regular expressions to match. It exports the lines that are
# matching any regular expression from the list. # matching any regular expression from the list.
#include_lines: ['^ERR', '^WARN'] #include_lines: ['^ERR', '^WARN']
# Exclude files. A list of regular expressions to match. Filebeat drops the files that # 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. # are matching any regular expression from the list. By default, no files are dropped.
#exclude_files: ['.gz$'] #exclude_files: ['.gz$']
# Optional additional fields. These fields can be freely picked # Optional additional fields. These fields can be freely picked
# to add additional information to the crawled log files for filtering # to add additional information to the crawled log files for filtering
#fields: #fields:
# level: debug # level: debug
# review: 1 # review: 1
### Multiline options ### Multiline options
# Mutiline can be used for log messages spanning multiple lines. This is common # Mutiline can be used for log messages spanning multiple lines. This is common
# for Java Stack Traces or C-Line Continuation # for Java Stack Traces or C-Line Continuation
# The regexp Pattern that has to be matched. The example pattern matches all lines starting with [ # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [
#multiline.pattern: ^\[ #multiline.pattern: ^\[
# Defines if the pattern set under pattern should be negated or not. Default is false. # Defines if the pattern set under pattern should be negated or not. Default is false.
#multiline.negate: 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 # 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. # 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 # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash
#multiline.match: after #multiline.match: after
#============================= Filebeat modules =============================== #============================= Filebeat modules ===============================
filebeat.config.modules: filebeat.config.modules:
# Glob pattern for configuration loading # Glob pattern for configuration loading
path: ${path.config}/modules.d/*.yml path: ${path.config}/modules.d/*.yml
# Set to true to enable config reloading # Set to true to enable config reloading
reload.enabled: true reload.enabled: true
# Period on which files under path should be checked for changes # Period on which files under path should be checked for changes
#reload.period: 10s #reload.period: 10s
#==================== Elasticsearch template setting ========================== #==================== Elasticsearch template setting ==========================
setup.template.settings: setup.template.settings:
index.number_of_shards: 3 index.number_of_shards: 3
#index.codec: best_compression #index.codec: best_compression
#_source.enabled: false #_source.enabled: false
#================================ General ===================================== #================================ General =====================================
@ -96,7 +96,7 @@ name: 127.0.0.1
# Optional fields that you can specify to add additional information to the # Optional fields that you can specify to add additional information to the
# output. # output.
fields: fields:
profile: development profile: development
#============================== Dashboards ===================================== #============================== Dashboards =====================================
@ -117,53 +117,53 @@ setup.dashboards.enabled: true
# This requires a Kibana endpoint configuration. # This requires a Kibana endpoint configuration.
setup.kibana: setup.kibana:
# Kibana Host # Kibana Host
# Scheme and port can be left out and will be set to the default (http and 5601) # Scheme and port can be left out and will be set to the default (http and 5601)
# In case you specify and additional path, the scheme is required: http://localhost:5601/path # In case you specify and additional path, the scheme is required: http://localhost:5601/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601 # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
host: "192.168.28.11: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 # The cloud.id setting overwrites the `output.elasticsearch.hosts` and
# `setup.kibana.host` options. # `setup.kibana.host` options.
# You can find the `cloud.id` in the Elastic Cloud web UI. # You can find the `cloud.id` in the Elastic Cloud web UI.
#cloud.id: #cloud.id:
# The cloud.auth setting overwrites the `output.elasticsearch.username` and # The cloud.auth setting overwrites the `output.elasticsearch.username` and
# `output.elasticsearch.password` settings. The format is `<user>:<pass>`. # `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
#cloud.auth: #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 ------------------------------ #-------------------------- Elasticsearch output ------------------------------
#output.elasticsearch: #output.elasticsearch:
# Array of hosts to connect to. # Array of hosts to connect to.
#hosts: ["192.168.28.11:9200"] #hosts: ["192.168.28.11:9200"]
# Optional protocol and basic auth credentials. # Optional protocol and basic auth credentials.
protocol: "http" protocol: "http"
#username: "elastic" #username: "elastic"
#password: "changeme" #password: "changeme"
#----------------------------- Logstash output -------------------------------- #----------------------------- Logstash output --------------------------------
output.logstash: output.logstash:
# The Logstash hosts # The Logstash hosts
hosts: ["192.168.28.32:5044"] hosts: ["192.168.28.32:5044"]
# Optional SSL. By default is off. # Optional SSL. By default is off.
# List of root certificates for HTTPS server verifications # List of root certificates for HTTPS server verifications
#ssl.certificate_authorities: ["/etc/pki/root/ca.pem"] #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
# Certificate for SSL client authentication # Certificate for SSL client authentication
#ssl.certificate: "/etc/pki/client/cert.pem" #ssl.certificate: "/etc/pki/client/cert.pem"
# Client Certificate Key # Client Certificate Key
#ssl.key: "/etc/pki/client/cert.key" #ssl.key: "/etc/pki/client/cert.key"
#================================ Logging ===================================== #================================ Logging =====================================

View File

@ -3,55 +3,55 @@
<!-- logback中一共有5种有效级别分别是TRACE、DEBUG、INFO、WARN、ERROR优先级依次从低到高 --> <!-- logback中一共有5种有效级别分别是TRACE、DEBUG、INFO、WARN、ERROR优先级依次从低到高 -->
<configuration scan="true" scanPeriod="60 seconds" debug="false"> <configuration scan="true" scanPeriod="60 seconds" debug="false">
<property name="FILE_NAME" value="javatool" /> <property name="FILE_NAME" value="javatool" />
<!-- 将记录日志打印到控制台 --> <!-- 将记录日志打印到控制台 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder> <encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] [%-5p] %c{36}.%M - %m%n</pattern> <pattern>%d{HH:mm:ss.SSS} [%thread] [%-5p] %c{36}.%M - %m%n</pattern>
</encoder> </encoder>
</appender> </appender>
<!-- RollingFileAppender begin --> <!-- RollingFileAppender begin -->
<appender name="ALL" class="ch.qos.logback.core.rolling.RollingFileAppender"> <appender name="ALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 根据时间来制定滚动策略 --> <!-- 根据时间来制定滚动策略 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${user.dir}/logs/${FILE_NAME}-all.%d{yyyy-MM-dd}.log</fileNamePattern> <fileNamePattern>${user.dir}/logs/${FILE_NAME}-all.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory> <maxHistory>30</maxHistory>
</rollingPolicy> </rollingPolicy>
<!-- 根据文件大小来制定滚动策略 --> <!-- 根据文件大小来制定滚动策略 -->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>30MB</maxFileSize> <maxFileSize>30MB</maxFileSize>
</triggeringPolicy> </triggeringPolicy>
<encoder> <encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] [%-5p] %c{36}.%M - %m%n</pattern> <pattern>%d{HH:mm:ss.SSS} [%thread] [%-5p] %c{36}.%M - %m%n</pattern>
</encoder> </encoder>
</appender> </appender>
<appender name="ELK-TCP" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <appender name="ELK-TCP" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<!-- <!--
destination 是 logstash 服务的 host:port destination 是 logstash 服务的 host:port
相当于和 logstash 建立了管道,将日志数据定向传输到 logstash 相当于和 logstash 建立了管道,将日志数据定向传输到 logstash
--> -->
<destination>192.168.28.32:9251</destination> <destination>192.168.28.32:9251</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
<customFields>{"appname":"javatool"}</customFields> <customFields>{"appname":"javatool"}</customFields>
</encoder> </encoder>
</appender> </appender>
<!-- RollingFileAppender end --> <!-- RollingFileAppender end -->
<!-- logger begin --> <!-- logger begin -->
<!-- 本项目的日志记录,分级打印 --> <!-- 本项目的日志记录,分级打印 -->
<logger name="io.github.zp" level="TRACE"> <logger name="io.github.zp" level="TRACE">
<appender-ref ref="ELK-TCP" /> <appender-ref ref="ELK-TCP" />
<appender-ref ref="ALL" /> <appender-ref ref="ALL" />
</logger> </logger>
<root level="TRACE"> <root level="TRACE">
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT" />
</root> </root>
<!-- logger end --> <!-- logger end -->
</configuration> </configuration>

View File

@ -1,15 +1,28 @@
#!/usr/bin/env bash #!/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 "${BLUE}\n"
cat << EOF cat << EOF
################################################################################### ###################################################################################
# 本脚本用于替换 yum repo使用国内 yum 仓库,加速下载 # 本脚本用于替换 yum repo使用国内 yum 仓库,加速下载
# 要求:仅适用于 Linux CentOS 发行版本,并且环境必须已支持 yum 、lsb_release 命令 # 要求:仅适用于 Linux CentOS 发行版本,并且环境必须已支持 yum 、lsb_release 命令
# @author: Zhang Peng # @author: Zhang Peng
################################################################################### ###################################################################################
EOF EOF
printf "${RESET}\n"
echo -e "\n>>>>>>>>> 替换 yum repo 源" printf "\n${GREEN}>>>>>>>>> 替换 yum repo 源开始${RESET}\n"
# 备份 # 备份
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
@ -18,8 +31,6 @@ cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# version=`lsb_release -r | awk '{print substr($2,1,1)}'` # 很多机器没有 lsb_release 命令 # version=`lsb_release -r | awk '{print substr($2,1,1)}'` # 很多机器没有 lsb_release 命令
version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'` version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'`
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# 根据发型版本选择相应 yum 镜像 # 根据发型版本选择相应 yum 镜像
if [[ ${version} == 5 ]]; then if [[ ${version} == 5 ]]; then
# Cento5 已废弃,只能使用 http://vault.CentOS.org/ 替换,但由于是国外镜像,速度较慢 # Cento5 已废弃,只能使用 http://vault.CentOS.org/ 替换,但由于是国外镜像,速度较慢
@ -36,11 +47,11 @@ elif [[ ${version} == 6 ]]; then
elif [[ ${version} == 7 ]]; then elif [[ ${version} == 7 ]]; then
wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/yum/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/yum/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
else else
echo -e "版本不支持,替换 yum repo 失败" printf "\n${RED}版本不支持,替换 yum repo 失败${RESET}\n"
fi fi
# 更新缓存 # 更新缓存
yum clean all yum clean all
yum makecache yum makecache
echo -e "\n>>>>>>>>> 替换 yum repo 源成功" printf "\n${GREEN}<<<<<<<< 替换 yum repo 源结束${RESET}\n"

View File

@ -1,29 +1,45 @@
#!/usr/bin/env bash #!/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 "${BLUE}\n"
cat << EOF
################################################################################### ###################################################################################
# 安装常见 lib # 安装常见 lib
# @author: Zhang Peng # 如果不知道命令在哪个 lib可以使用 yum search xxx 来查找
# # lib 清单如下:
# 如果不知道某个命令工具是由哪个包提供的,使用 yum provides xxx
# 或 yum whatprovides xxx 来查找
###################################################################################
###################################################################################
# 执行本脚本后支持的 lib 清单:
# gcc gcc-c++ kernel-devel libtool # gcc gcc-c++ kernel-devel libtool
# openssl openssl-devel # openssl openssl-devel
# zlib zlib-devel # zlib zlib-devel
# pcre # pcre
#
# @author: Zhang Peng
################################################################################### ###################################################################################
EOF
printf "${RESET}\n"
echo -e "\n>>>>>>>>> install gcc gcc-c++ kernel-devel libtool" printf "\n${GREEN}>>>>>>>>> 安装常见 lib 开始${RESET}\n"
printf "\n${CYAN}>>>> install gcc gcc-c++ kernel-devel libtool${RESET}\n"
yum -y install make gcc gcc-c++ kernel-devel libtool yum -y install make gcc gcc-c++ kernel-devel libtool
echo -e "\n>>>>>>>>> install openssl openssl-devel" printf "\n${CYAN}>>>> install openssl openssl-devel${RESET}\n"
yum -y install make openssl openssl-devel yum -y install make openssl openssl-devel
echo -e "\n>>>>>>>>> install zlib zlib-devel" printf "\n${CYAN}>>>> install zlib zlib-devel${RESET}\n"
yum -y install make zlib zlib-devel yum -y install make zlib zlib-devel
echo -e "\n>>>>>>>>> install pcre" printf "\n${CYAN}>>>> install pcre${RESET}\n"
yum -y install pcre yum -y install pcre
printf "\n${GREEN}<<<<<<<< 安装常见 lib 结束${RESET}\n"

View File

@ -1,19 +1,22 @@
#!/usr/bin/env bash #!/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 "${BLUE}\n"
cat << EOF cat << EOF
################################################################################### ###################################################################################
# 安装基本的命令工具 # 安装常用命令工具
# @author: Zhang Peng # 命令工具清单如下:
#
# 如果不知道某个命令工具是由哪个包提供的,使用 yum provides xxx
# 或 yum whatprovides xxx 来查找
###################################################################################
EOF
cat << EOF
###################################################################################
# 执行本脚本后支持的命令工具清单:
# 核心工具df、du、chkconfig # 核心工具df、du、chkconfig
# 网络工具ifconfig、netstat、route、iptables # 网络工具ifconfig、netstat、route、iptables
# IP工具ip、ss、ping、tracepath、traceroute # IP工具ip、ss、ping、tracepath、traceroute
@ -25,72 +28,78 @@ cat << EOF
# 抓包工具tcpdump # 抓包工具tcpdump
# 压缩工具unzip、zip # 压缩工具unzip、zip
# 版本控制工具git、subversion # 版本控制工具git、subversion
#
# @author: Zhang Peng
################################################################################### ###################################################################################
EOF EOF
printf "${RESET}\n"
printf "\n${GREEN}>>>>>>>>> 安装常用命令工具开始${RESET}\n"
# 核心工具 # 核心工具
echo -e "\n>>>>>>>>> install coreutils(df、du)" printf "\n${CYAN}>>>> install coreutils(df、du)${RESET}\n"
yum install -y coreutils yum install -y coreutils
echo -e "\n>>>>>>>>> install chkconfig" printf "\n${CYAN}>>>> install chkconfig${RESET}\n"
yum install -y chkconfig yum install -y chkconfig
# 网络工具 # 网络工具
echo -e "\n>>>>>>>>> install net-tools(ifconfig、netstat、route)" printf "\n${CYAN}>>>> install net-tools(ifconfig、netstat、route)${RESET}\n"
yum install -y net-tools yum install -y net-tools
echo -e "\n>>>>>>>>> install iptables" printf "\n${CYAN}>>>> install iptables${RESET}\n"
yum install -y iptables yum install -y iptables
# IP工具 # IP工具
echo -e "\n>>>>>>>>> install iputils(ping、tracepath)" printf "\n${CYAN}>>>> install iputils(ping、tracepath)${RESET}\n"
yum install -y iputils yum install -y iputils
echo -e "\n>>>>>>>>> install traceroute" printf "\n${CYAN}>>>> install traceroute${RESET}\n"
yum install -y traceroute yum install -y traceroute
echo -e "\n>>>>>>>>> install iproute(ip、ss)" printf "\n${CYAN}>>>> install iproute(ip、ss)${RESET}\n"
yum install -y iproute yum install -y iproute
# 端口工具 # 端口工具
echo -e "\n>>>>>>>>> install lsof" printf "\n${CYAN}>>>> install lsof${RESET}\n"
yum install -y lsof yum install -y lsof
echo -e "\n>>>>>>>>> install nc" printf "\n${CYAN}>>>> install nc${RESET}\n"
yum install -y nc yum install -y nc
echo -e "\n>>>>>>>>> install netstat" printf "\n${CYAN}>>>> install netstat${RESET}\n"
yum install -y netstat yum install -y netstat
# DNS工具 # DNS工具
echo -e "\n>>>>>>>>> install bind-utils(dig、host、nslookup)" printf "\n${CYAN}>>>> install bind-utils(dig、host、nslookup)${RESET}\n"
yum install -y bind-utils yum install -y bind-utils
echo -e "\n>>>>>>>>> install whois" printf "\n${CYAN}>>>> install whois${RESET}\n"
yum install -y whois yum install -y whois
# 下载工具 # 下载工具
echo -e "\n>>>>>>>>> install curl" printf "\n${CYAN}>>>> install curl${RESET}\n"
yum install -y curl yum install -y curl
echo -e "\n>>>>>>>>> install wget" printf "\n${CYAN}>>>> install wget${RESET}\n"
yum install -y wget yum install -y wget
# 编辑工具 # 编辑工具
echo -e "\n>>>>>>>>> install emacs" printf "\n${CYAN}>>>> install emacs${RESET}\n"
yum install -y emacs yum install -y emacs
echo -e "\n>>>>>>>>> install vim" printf "\n${CYAN}>>>> install vim${RESET}\n"
yum install -y vim yum install -y vim
# 流量工具 # 流量工具
echo -e "\n>>>>>>>>> install iftop" printf "\n${CYAN}>>>> install iftop${RESET}\n"
yum install -y iftop yum install -y iftop
echo -e "\n>>>>>>>>> install nethogs" printf "\n${CYAN}>>>> install nethogs${RESET}\n"
yum install -y nethogs yum install -y nethogs
# 抓包工具 # 抓包工具
echo -e "\n>>>>>>>>> install tcpdump" printf "\n${CYAN}>>>> install tcpdump${RESET}\n"
yum install -y tcpdump yum install -y tcpdump
# 压缩工具 # 压缩工具
echo -e "\n>>>>>>>>> install unzip" printf "\n${CYAN}>>>> install unzip${RESET}\n"
yum install -y unzip yum install -y unzip
# 版本控制工具 # 版本控制工具
echo -e "\n>>>>>>>>> install git" printf "\n${CYAN}>>>> install git${RESET}\n"
yum install -y git yum install -y git
echo -e "\n>>>>>>>>> install subversion" printf "\n${CYAN}>>>> install subversion${RESET}\n"
yum install -y subversion yum install -y subversion
printf "\n${GREEN}<<<<<<<< 安装常用命令工具结束${RESET}\n"

View File

@ -1,32 +1,36 @@
#!/usr/bin/env bash #!/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)"
# ---------------------------------------------------------------------------------
################################################################################### ###################################################################################
# 在 /etc/resolv.conf 中设置 DNS 服务器 # 在 /etc/resolv.conf 中置 DNS 服务器
# 在 /etc/hosts 中设置本机域名 # 在 /etc/hosts 中置本机域名
# @author: Zhang Peng # @author: Zhang Peng
################################################################################### ###################################################################################
ip='127.0.0.1'
function getDeviceIp() {
ip=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
}
function setDNSServer() { printf "\n${GREEN}>>>>>>>>> 配置 DNS 开始${RESET}\n"
echo -e "设置DNS服务器"
cat >> /etc/resolv.conf << EOF printf "\n${CYAN}>>>> 配置 DNS 解析服务器${RESET}\n"
cat >> /etc/resolv.conf << EOF
nameserver 114.114.114.114 nameserver 114.114.114.114
nameserver 8.8.8.8 nameserver 8.8.8.8
EOF EOF
}
function setHosts() { printf "\n${CYAN}>>>> 配置本机域名和IP映射${RESET}\n"
getDeviceIp ip=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
host=`hostname` host=`hostname`
cat >> /etc/hosts << EOF cat >> /etc/hosts << EOF
${ip} ${host} ${ip} ${host}
EOF EOF
}
######################################## MAIN ######################################## printf "\n${GREEN}<<<<<<<< 配置 DNS 结束${RESET}\n"
echo -e "\n>>>>>>>>> 配置系统环境"
setDNSServer
setHosts

View File

@ -1,28 +1,42 @@
#!/usr/bin/env bash #!/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)"
# ---------------------------------------------------------------------------------
################################################################################### ###################################################################################
# 使用 NTP 进行时间同步 # 使用 NTP 进行时间同步
# 参考https://www.cnblogs.com/quchunhui/p/7658853.html # 参考https://www.cnblogs.com/quchunhui/p/7658853.html
# @author: Zhang Peng # @author: Zhang Peng
################################################################################### ###################################################################################
echo -e "\n>>>>>>>>> 设置 ntp" printf "\n${GREEN}>>>>>>>>> 设置 NTP 开始${RESET}\n"
echo -e "先安装时钟同步工具 ntp" printf "\n${CYAN}>>>> 安装 NTP 服务${RESET}\n"
yum -y install ntp yum -y install ntp
ip=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}') ip=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
/sbin/iptables -A INPUT -p UDP -i eth0 -s ${ip}/24 --dport 123 -j ACCEPT /sbin/iptables -A INPUT -p UDP -i eth0 -s ${ip}/24 --dport 123 -j ACCEPT
echo -e "启动 NTP 服务" printf "\n${CYAN}>>>> 启动 NTP 服务${RESET}\n"
systemctl start ntpd.service systemctl start ntpd.service
echo -e "立即执行时间同步" printf "\n${CYAN}>>>> 立即执行时间同步${RESET}\n"
/usr/sbin/ntpdate ntp.sjtu.edu.cn /usr/sbin/ntpdate ntp.sjtu.edu.cn
echo -e "自动定时同步时间" printf "\n${CYAN}>>>> 自动定时同步时间${RESET}\n"
echo "* 3 * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn" >> /etc/crontab echo "* 3 * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn" >> /etc/crontab
systemctl restart crond.service systemctl restart crond.service
echo -e "同步后系统时间:" printf "\n${CYAN}>>>> 同步结束,当前系统时间:${RESET}\n"
date date
printf "\n${GREEN}<<<<<<<< 设置 NTP 结束${RESET}\n"

View File

@ -1,10 +1,23 @@
#!/usr/bin/env bash #!/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)"
# ---------------------------------------------------------------------------------
################################################################################### ###################################################################################
# 彻底关闭防火墙 # 关闭防火墙
# 参考https://www.cnblogs.com/moxiaoan/p/5683743.html # 参考https://www.cnblogs.com/moxiaoan/p/5683743.html
# @author: Zhang Peng # @author: Zhang Peng
################################################################################### ###################################################################################
systemctl stop firewalld systemctl stop firewalld
systemctl disable firewalld systemctl disable firewalld
printf "\n${GREEN}<<<<<<<< 已关闭防火墙${RESET}\n"

View File

@ -1,37 +1,49 @@
#!/usr/bin/env bash #!/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)"
# ---------------------------------------------------------------------------------
printHeadInfo() { printHeadInfo() {
cat << EOF printf "${BLUE}\n"
cat << EOF
################################################################################### ###################################################################################
# Linux Centos7 系统配置脚本(根据需要选择) # Linux Centos7 系统配置脚本(根据需要选择)
# @author: Zhang Peng # @author: Zhang Peng
################################################################################### ###################################################################################
EOF EOF
printf "${RESET}\n"
} }
setLimit() { setLimit() {
cat >> /etc/security/limits.conf << EOF cat >> /etc/security/limits.conf << EOF
* - nofile 65535 * - nofile 65535
* - nproc 65535 * - nproc 65535
EOF EOF
} }
setLang() { setLang() {
cat > /etc/sysconfig/i18n << EOF cat > /etc/sysconfig/i18n << EOF
LANG="zh_CN.UTF-8" LANG="zh_CN.UTF-8"
EOF EOF
} }
closeShutdownShortkey() { closeShutdownShortkey() {
echo "关闭 Ctrl+Alt+Del 快捷键防止重新启动" printf "\n${CYAN}>>>> 关闭 Ctrl+Alt+Del 快捷键防止重新启动${RESET}\n"
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf
} }
closeSelinux() { closeSelinux() {
echo "关闭 selinux"
# see http://blog.51cto.com/13570193/2093299 # see http://blog.51cto.com/13570193/2093299
printf "\n${CYAN}>>>> 关闭 selinux${RESET}\n"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
} }
@ -43,15 +55,15 @@ setBootMode() {
# 5. 通常不用,在一些特殊情况下可以用它来做一些事情 # 5. 通常不用,在一些特殊情况下可以用它来做一些事情
# 6. X11即进到 X-Window 系统 # 6. X11即进到 X-Window 系统
# 7. 重新启动 (记得不要把 initdefault 配置为 6因为这样会使 Linux 不断地重新启动) # 7. 重新启动 (记得不要把 initdefault 配置为 6因为这样会使 Linux 不断地重新启动)
echo "设置 Linux 启动模式" printf "\n${CYAN}>>>> 配置 Linux 启动模式${RESET}\n"
sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/inittab sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/inittab
} }
# 配置 IPv4 # 配置 IPv4
configIpv4() { configIpv4() {
echo "配置 ipv4" printf "\n${CYAN}>>>> 配置 IPv4${RESET}\n"
cat >> /etc/sysctl.conf << EOF cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_fin_timeout = 2
@ -78,9 +90,9 @@ EOF
# 关闭 IPv6 # 关闭 IPv6
closeIpv6() { closeIpv6() {
echo "关闭 ipv6" printf "\n${CYAN}>>>> 关闭 IPv6${RESET}\n"
cat > /etc/modprobe.d/ipv6.conf << EOF cat > /etc/modprobe.d/ipv6.conf << EOF
alias net-pf-10 off alias net-pf-10 off
options ipv6 disable=1 options ipv6 disable=1
EOF EOF
@ -90,45 +102,42 @@ EOF
# 入口函数 # 入口函数
main() { main() {
PS3="请选择要执行的操作:" PS3="请选择要执行的操作:"
select ITEM in "设置 DNS" "设置 NTP" "关闭防火墙" "配置 IPv4" "关闭 IPv6" "全部执行" select ITEM in "配置 DNS" "配置 NTP" "关闭防火墙" "配置 IPv4" "关闭 IPv6" "全部执行"
do do
case ${ITEM} in case ${ITEM} in
"设置 DNS") "配置 DNS")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/set-dns.sh | bash sh ${root}/set-dns.sh ;;
;; "配置 NTP")
"设置 NTP") sh ${root}/set-ntp.sh ;;
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/set-ntp.sh | bash "关闭防火墙")
;; sh ${root}/stop-firewall.sh ;;
"关闭防火墙") "配置 IPv4")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/stop-firewall.sh | bash configIpv4 ;;
;; "关闭 IPv6")
"配置 IPv4") closeIpv6 ;;
configIpv4 "全部执行")
;; sh ${root}/set-dns.sh
"关闭 IPv6") sh ${root}/set-ntp.sh
closeIpv6 sh ${root}/stop-firewall.sh
;; configIpv4
"全部执行") closeIpv6
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/set-dns.sh | bash ;;
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/set-ntp.sh | bash *)
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/stop-firewall.sh | bash printf "\n${RED}输入项不支持${RESET}\n"
configIpv4 main
closeIpv6 ;;
;; esac
*) break
echo -e "输入项不支持!" done
main
;;
esac
break
done
} }
######################################## MAIN ######################################## ######################################## MAIN ########################################
filepath=$(cd "$(dirname "$0")"; root=$(pwd)
pwd) if [[ -n $1 ]]; then
root=$1
fi
printHeadInfo printHeadInfo
main main