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/) 机器上安装常用命令工具或开发软件。**

View File

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

View File

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

View File

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

View File

@ -1,13 +1,26 @@
#!/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
###################################################################################
EOF
printf "${RESET}\n"
menus=( "替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出" )
main() {
@ -15,33 +28,34 @@ main() {
select item in "${menus[@]}"
do
case ${item} in
"替换yum镜像")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/change-yum-repo.sh | bash
main ;;
"安装基本的命令工具")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-tools.sh | bash
main ;;
"安装常用libs")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-libs.sh | bash
main ;;
"系统配置")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/sys-settings.sh | bash
main ;;
"全部执行")
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/change-yum-repo.sh | bash
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-tools | bash
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-libs.sh | bash
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/sys-settings.sh | bash
printf "执行完毕,退出。\n" ;;
"退出")
exit 0 ;;
*)
printf "输入项不支持!\n"
main ;;
"替换yum镜像")
sh ${root}/sys/change-yum-repo.sh
main ;;
"安装基本的命令工具")
sh ${root}/sys/install-tools.sh
main ;;
"安装常用libs")
sh ${root}/sys/install-libs.sh
main ;;
"系统配置")
sh ${root}/sys/sys-settings.sh ${root}/sys
main ;;
"全部执行")
sh ${root}/sys/change-yum-repo.sh
sh ${root}/sys/install-tools.sh
sh ${root}/sys/install-libs.sh
sh ${root}/sys/sys-settings.sh ${root}/sys
printf "${GREEN}执行完毕,退出。${RESET}\n" ;;
"退出")
exit 0 ;;
*)
printf "${RED}输入项不支持!${RESET}\n"
main ;;
esac
break
done
}
######################################## MAIN ########################################
root=$(pwd)
main

View File

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

View File

@ -14,74 +14,74 @@
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 ===============================
filebeat.config.modules:
# Glob pattern for configuration loading
path: ${path.config}/modules.d/*.yml
# Glob pattern for configuration loading
path: ${path.config}/modules.d/*.yml
# Set to true to enable config reloading
reload.enabled: true
# Set to true to enable config reloading
reload.enabled: true
# Period on which files under path should be checked for changes
#reload.period: 10s
# Period on which files under path should be checked for changes
#reload.period: 10s
#==================== Elasticsearch template setting ==========================
setup.template.settings:
index.number_of_shards: 3
#index.codec: best_compression
#_source.enabled: false
index.number_of_shards: 3
#index.codec: best_compression
#_source.enabled: false
#================================ General =====================================
@ -96,7 +96,7 @@ name: 127.0.0.1
# Optional fields that you can specify to add additional information to the
# output.
fields:
profile: development
profile: development
#============================== Dashboards =====================================
@ -117,53 +117,53 @@ setup.dashboards.enabled: true
# This requires a Kibana endpoint configuration.
setup.kibana:
# Kibana Host
# 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
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
host: "192.168.28.11:5601"
# Kibana Host
# 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
# 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 `<user>:<pass>`.
#cloud.auth:
# The cloud.auth setting overwrites the `output.elasticsearch.username` and
# `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
#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:
# Array of hosts to connect to.
#hosts: ["192.168.28.11:9200"]
#-------------------------- Elasticsearch output ------------------------------
#output.elasticsearch:
# Array of hosts to connect to.
#hosts: ["192.168.28.11:9200"]
# Optional protocol and basic auth credentials.
protocol: "http"
#username: "elastic"
#password: "changeme"
# Optional protocol and basic auth credentials.
protocol: "http"
#username: "elastic"
#password: "changeme"
#----------------------------- Logstash output --------------------------------
output.logstash:
# The Logstash hosts
hosts: ["192.168.28.32:5044"]
# The Logstash hosts
hosts: ["192.168.28.32:5044"]
# Optional SSL. By default is off.
# List of root certificates for HTTPS server verifications
#ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
# Optional SSL. By default is off.
# List of root certificates for HTTPS server verifications
#ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
# Certificate for SSL client authentication
#ssl.certificate: "/etc/pki/client/cert.pem"
# Certificate for SSL client authentication
#ssl.certificate: "/etc/pki/client/cert.pem"
# Client Certificate Key
#ssl.key: "/etc/pki/client/cert.key"
# Client Certificate Key
#ssl.key: "/etc/pki/client/cert.key"
#================================ Logging =====================================

View File

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

View File

@ -1,15 +1,28 @@
#!/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
###################################################################################
# 本脚本用于替换 yum repo使用国内 yum 仓库,加速下载
# 要求:仅适用于 Linux CentOS 发行版本,并且环境必须已支持 yum 、lsb_release 命令
# @author: Zhang Peng
###################################################################################
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
@ -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=`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 镜像
if [[ ${version} == 5 ]]; then
# Cento5 已废弃,只能使用 http://vault.CentOS.org/ 替换,但由于是国外镜像,速度较慢
@ -36,11 +47,11 @@ elif [[ ${version} == 6 ]]; 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
else
echo -e "版本不支持,替换 yum repo 失败"
printf "\n${RED}版本不支持,替换 yum repo 失败${RESET}\n"
fi
# 更新缓存
yum clean all
yum makecache
echo -e "\n>>>>>>>>> 替换 yum repo 源成功"
printf "\n${GREEN}<<<<<<<< 替换 yum repo 源结束${RESET}\n"

View File

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

View File

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

View File

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

View File

@ -1,28 +1,42 @@
#!/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 进行时间同步
# 参考https://www.cnblogs.com/quchunhui/p/7658853.html
# @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
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
echo -e "启动 NTP 服务"
printf "\n${CYAN}>>>> 启动 NTP 服务${RESET}\n"
systemctl start ntpd.service
echo -e "立即执行时间同步"
printf "\n${CYAN}>>>> 立即执行时间同步${RESET}\n"
/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
systemctl restart crond.service
echo -e "同步后系统时间:"
printf "\n${CYAN}>>>> 同步结束,当前系统时间:${RESET}\n"
date
printf "\n${GREEN}<<<<<<<< 设置 NTP 结束${RESET}\n"

View File

@ -1,10 +1,23 @@
#!/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
# @author: Zhang Peng
###################################################################################
systemctl stop firewalld
systemctl disable firewalld
printf "\n${GREEN}<<<<<<<< 已关闭防火墙${RESET}\n"

View File

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