update scripts
parent
90908bb378
commit
2b73cbc127
|
@ -1,4 +1,4 @@
|
|||
# Linux 傻瓜式运维脚本
|
||||
# Dunwu Shell 运维脚本
|
||||
|
||||
> **本项目脚本代码用于在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。**
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 ;;
|
||||
selectAndExecTask ;;
|
||||
"安装软件")
|
||||
./dunwu-soft.sh
|
||||
main ;;
|
||||
selectAndExecTask ;;
|
||||
"退出")
|
||||
printFootInfo
|
||||
exit 0 ;;
|
||||
*)
|
||||
printf "输入项不支持!\n"
|
||||
main ;;
|
||||
printf "\n${RED}输入项不支持!${RESET}\n"
|
||||
selectAndExecTask ;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
######################################## MAIN ########################################
|
||||
path=$(cd "$(dirname "$0")";
|
||||
pwd)
|
||||
printHeadInfo
|
||||
checkOsVersion 0
|
||||
main
|
||||
printFootInfo
|
||||
checkOsVersion 1
|
||||
selectAndExecTask
|
||||
|
|
|
@ -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
|
||||
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${RESET}请输入需要安装的软件编号:\n"
|
||||
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
|
||||
|
|
|
@ -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() {
|
||||
|
@ -16,27 +29,27 @@ main() {
|
|||
do
|
||||
case ${item} in
|
||||
"替换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 ;;
|
||||
"安装基本的命令工具")
|
||||
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-tools.sh | bash
|
||||
sh ${root}/sys/install-tools.sh
|
||||
main ;;
|
||||
"安装常用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 ;;
|
||||
"系统配置")
|
||||
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 ;;
|
||||
"全部执行")
|
||||
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" ;;
|
||||
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 "输入项不支持!\n"
|
||||
printf "${RED}输入项不支持!${RESET}\n"
|
||||
main ;;
|
||||
esac
|
||||
break
|
||||
|
@ -44,4 +57,5 @@ main() {
|
|||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
root=$(pwd)
|
||||
main
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
@ -91,34 +103,29 @@ EOF
|
|||
# 入口函数
|
||||
main() {
|
||||
PS3="请选择要执行的操作:"
|
||||
select ITEM in "设置 DNS" "设置 NTP" "关闭防火墙" "配置 IPv4" "关闭 IPv6" "全部执行"
|
||||
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
|
||||
;;
|
||||
"配置 DNS")
|
||||
sh ${root}/set-dns.sh ;;
|
||||
"配置 NTP")
|
||||
sh ${root}/set-ntp.sh ;;
|
||||
"关闭防火墙")
|
||||
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/stop-firewall.sh | bash
|
||||
;;
|
||||
sh ${root}/stop-firewall.sh ;;
|
||||
"配置 IPv4")
|
||||
configIpv4
|
||||
;;
|
||||
configIpv4 ;;
|
||||
"关闭 IPv6")
|
||||
closeIpv6
|
||||
;;
|
||||
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
|
||||
sh ${root}/set-dns.sh
|
||||
sh ${root}/set-ntp.sh
|
||||
sh ${root}/stop-firewall.sh
|
||||
configIpv4
|
||||
closeIpv6
|
||||
;;
|
||||
*)
|
||||
echo -e "输入项不支持!"
|
||||
printf "\n${RED}输入项不支持${RESET}\n"
|
||||
main
|
||||
;;
|
||||
esac
|
||||
|
@ -127,8 +134,10 @@ main() {
|
|||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
filepath=$(cd "$(dirname "$0")";
|
||||
pwd)
|
||||
root=$(pwd)
|
||||
if [[ -n $1 ]]; then
|
||||
root=$1
|
||||
fi
|
||||
|
||||
printHeadInfo
|
||||
main
|
||||
|
|
Loading…
Reference in New Issue