mirror of
https://github.com/dunwu/linux-tutorial.git
synced 2024-04-15 19:55:24 +08:00
更新运维脚本
This commit is contained in:
parent
ce8b2cfb13
commit
a7b999acdb
@ -1,109 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
###################################################################################
|
||||
# Linux CentOS 环境部署脚本
|
||||
# Author: Zhang Peng
|
||||
###################################################################################
|
||||
|
||||
function printHeadInfo() {
|
||||
# 打印头部信息
|
||||
printHeadInfo() {
|
||||
cat << EOF
|
||||
|
||||
***********************************************************************************
|
||||
* Welcome to using the deployment script for CentOS.
|
||||
* 欢迎使用 Linux CentOS 环境运维脚本
|
||||
* Author: Zhang Peng
|
||||
***********************************************************************************
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
function printFootInfo() {
|
||||
# 打印尾部信息
|
||||
printFootInfo() {
|
||||
cat << EOF
|
||||
|
||||
***********************************************************************************
|
||||
* Deployment is over.
|
||||
* Thank you for using!
|
||||
* 脚本执行结束,感谢使用!
|
||||
***********************************************************************************
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
function checkOsVersion(){
|
||||
if(($1 == 1))
|
||||
then
|
||||
# 检查操作系统环境
|
||||
checkOsVersion(){
|
||||
if(($1 == 1)); then
|
||||
echo -e "检查操作系统环境是否兼容本套脚本"
|
||||
|
||||
platform=`uname -i`
|
||||
if [[ ${platform} != "x86_64" ]]; then
|
||||
echo "this script is only for 64bit Operating System !"
|
||||
echo "脚本仅支持 64 位操作系统!"
|
||||
exit 1
|
||||
fi
|
||||
echo "the platform is ok"
|
||||
version=`lsb_release -r |awk '{print substr($2,1,1)}'`
|
||||
if [[ ${version} != 6 ]]; then
|
||||
echo "this script is only for CentOS 6 !"
|
||||
|
||||
version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'`
|
||||
if [[ ${version} != 7 ]]; then
|
||||
echo "脚本仅支持 CentOS 7!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "脚本可以在本环境运行!"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function showMenu() {
|
||||
cat << EOF
|
||||
|
||||
=================================== Deploy Menu ===================================
|
||||
【1 - System Environment】
|
||||
[sys] initial system environment
|
||||
[libs] install commonly libs
|
||||
|
||||
【2 - Common Tools】
|
||||
[2 | tools] install all tools.
|
||||
[git] install git [svn] install svn
|
||||
[jdk8] install jdk8 [maven] install maven
|
||||
[tomcat] install tomcat8 [nginx] install nginx
|
||||
[nodejs] install node.js [elk] install elk
|
||||
[redis] install redis [mongodb] install mongodb
|
||||
[kafka] install kafka
|
||||
|
||||
【3 - Recommended Tools】
|
||||
[sdk] install sdkman
|
||||
[springboot] install spring boot cli
|
||||
|
||||
Press <CTRL-D> to exit
|
||||
Please input key:
|
||||
EOF
|
||||
}
|
||||
|
||||
function chooseOper() {
|
||||
key=""
|
||||
filepath=$(cd "$(dirname "$0")"; pwd)
|
||||
while read key
|
||||
# 入口函数
|
||||
main() {
|
||||
PS3="请选择要执行的脚本分类:"
|
||||
select item in "配置系统" "安装服务"
|
||||
do
|
||||
case ${key} in
|
||||
# 2 - System Environment
|
||||
sys ) ${filepath}/sys/init.sh;;
|
||||
libs ) ${filepath}/lib/install-libs.sh;;
|
||||
|
||||
# 2 - Common Tools
|
||||
2 | tools ) ${filepath}/ops/service/install-all.sh;;
|
||||
git ) ${filepath}/ops/service/git/install-git.sh;;
|
||||
svn ) ${filepath}/ops/service/svn/install-svn.sh;;
|
||||
jdk8 ) ${filepath}/ops/service/jdk/install-jdk8.sh;;
|
||||
maven ) ${filepath}/ops/service/maven/install-maven3.sh;;
|
||||
nginx ) ${filepath}/ops/service/nginx/install-nginx.sh;;
|
||||
nodejs ) ${filepath}/ops/service/nodejs/install-nodejs.sh;;
|
||||
tomcat ) ${filepath}/ops/service/tomcat/install-tomcat8.sh;;
|
||||
elk ) ${filepath}/ops/service/elk/install-elk.sh;;
|
||||
redis ) ${filepath}/ops/service/redis/install-redis.sh;;
|
||||
mongodb ) ${filepath}/ops/service/mongodb/install-mongodb.sh;;
|
||||
kafka ) ${filepath}/ops/service/kafka/install-kafka.sh;;
|
||||
|
||||
# 3 - Recommended Tools
|
||||
sdk ) ${filepath}/ops/service/sdk/install-sdk.sh;;
|
||||
springboot ) ${filepath}/ops/service/springboot/install-springboot.sh;;
|
||||
|
||||
* ) echo "${key} is invalid key";;
|
||||
case ${item} in
|
||||
"配置系统")
|
||||
${path}/sys/main.sh
|
||||
;;
|
||||
"安装服务")
|
||||
${path}/service/main.sh
|
||||
;;
|
||||
*)
|
||||
echo -e "输入项不支持!"
|
||||
main
|
||||
;;
|
||||
esac
|
||||
|
||||
showMenu
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
path=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
printHeadInfo
|
||||
checkOsVersion 0
|
||||
showMenu
|
||||
chooseOper
|
||||
main
|
||||
printFootInfo
|
||||
|
@ -1,15 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo -e "\n>>>>>>>>> install all tools"
|
||||
|
||||
filepath=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
${filepath}/git/install-git.sh
|
||||
${filepath}/git/install-svn.sh
|
||||
${filepath}/jdk/install-jdk8.sh
|
||||
${filepath}/maven/install-maven.sh
|
||||
${filepath}/nginx/install-nginx.sh
|
||||
${filepath}/nodejs/install-nodejs.sh
|
||||
${filepath}/tomcat/install-tomcat8.sh
|
||||
${filepath}/elk/install-elk.sh
|
||||
|
39
codes/linux/ops/service/main.sh
Normal file
39
codes/linux/ops/service/main.sh
Normal file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# 打印头部信息
|
||||
printHeadInfo() {
|
||||
cat << EOF
|
||||
|
||||
***********************************************************************************
|
||||
* 欢迎使用 Linux CentOS 服务安装配置脚本
|
||||
* Author: Zhang Peng
|
||||
***********************************************************************************
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
main() {
|
||||
PS3="Please select script type: "
|
||||
select item in "git" "jdk" "maven"
|
||||
do
|
||||
path=$(cd "$(dirname "$0")"; pwd)
|
||||
case ${item} in
|
||||
"git") yum install -y git ;;
|
||||
"jdk") ${path}/jdk/install-jdk8.sh ;;
|
||||
"maven") ${path}/maven/install-maven3.sh ;;
|
||||
*)
|
||||
echo -e "输入项不支持!"
|
||||
main
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
filepath=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
######################################## MAIN ########################################
|
||||
path=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
printHeadInfo
|
||||
main
|
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
###################################################################################
|
||||
# Linux CentOS 环境初始化脚本(设置环境配置、安装基本的命令工具)
|
||||
# Author: Zhang Peng
|
||||
###################################################################################
|
||||
|
||||
cat << EOF
|
||||
***********************************************************************************
|
||||
* The initialization of linux environment is begin.
|
||||
***********************************************************************************
|
||||
EOF
|
||||
|
||||
filepath=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
# 替换 yum 镜像(使用国内镜像,加速下载)
|
||||
${filepath}/yum/change-yum-repo.sh
|
||||
|
||||
# 设置环境配置,不了解具体修改内容的情况下,请勿执行
|
||||
${filepath}/config-env.sh
|
||||
|
||||
# 安装命令行工具
|
||||
${filepath}/install-tools.sh
|
||||
|
||||
cat << EOF
|
||||
***********************************************************************************
|
||||
* The initialization of linux environment is over.
|
||||
***********************************************************************************
|
||||
EOF
|
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# 安装基本的命令工具
|
||||
# Author: Zhang Peng
|
||||
@ -8,6 +9,9 @@
|
||||
# 或 yum whatprovides xxx 来查找
|
||||
###################################################################################
|
||||
|
||||
EOF
|
||||
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# 执行本脚本后支持的命令工具清单:
|
||||
# 核心工具:df、du、chkconfig
|
||||
@ -22,6 +26,9 @@
|
||||
# 压缩工具:unzip、zip
|
||||
# 版本控制工具:git、subversion
|
||||
###################################################################################
|
||||
|
||||
EOF
|
||||
|
||||
# 核心工具
|
||||
echo -e "\n>>>>>>>>> install coreutils(df、du)"
|
||||
yum install -y coreutils
|
||||
|
51
codes/linux/ops/sys/main.sh
Normal file
51
codes/linux/ops/sys/main.sh
Normal file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
printHeadInfo() {
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# Linux CentOS 环境初始化脚本(设置环境配置、安装基本的命令工具)
|
||||
# Author: Zhang Peng
|
||||
###################################################################################
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# 入口函数
|
||||
main() {
|
||||
PS3="请选择要执行的操作:"
|
||||
select ITEM in "替换 yum 镜像" "安装基本的命令工具" "安装常用 libs" "系统配置" "全部执行"
|
||||
do
|
||||
|
||||
case ${ITEM} in
|
||||
"替换 yum 镜像")
|
||||
${filepath}/yum/change-yum-repo.sh
|
||||
;;
|
||||
"安装基本的命令工具")
|
||||
${filepath}/install-tools.sh
|
||||
;;
|
||||
"安装常用 libs")
|
||||
${filepath}/install-libs.sh
|
||||
;;
|
||||
"系统配置")
|
||||
${filepath}/sys-settings.sh
|
||||
;;
|
||||
"全部执行")
|
||||
${filepath}/yum/change-yum-repo.sh
|
||||
${filepath}/install-tools.sh
|
||||
${filepath}/install-libs.sh
|
||||
${filepath}/sys-settings.sh
|
||||
;;
|
||||
*)
|
||||
echo -e "输入项不支持!"
|
||||
main
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
filepath=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
printHeadInfo
|
||||
main
|
@ -1,38 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
printHeadInfo() {
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# Linux Centos7 设置环境配置脚本(根据需要选择)
|
||||
# 注:不了解脚本中配置意图的情况下,不要贸然执行此脚本
|
||||
# Linux Centos7 系统配置脚本(根据需要选择)
|
||||
# Author: Zhang Peng
|
||||
###################################################################################
|
||||
|
||||
function setLimit() {
|
||||
EOF
|
||||
}
|
||||
|
||||
setLimit() {
|
||||
cat >> /etc/security/limits.conf << EOF
|
||||
* - nofile 65535
|
||||
* - nproc 65535
|
||||
EOF
|
||||
}
|
||||
|
||||
function setLang() {
|
||||
setLang() {
|
||||
cat > /etc/sysconfig/i18n << EOF
|
||||
LANG="zh_CN.UTF-8"
|
||||
EOF
|
||||
}
|
||||
|
||||
function closeShutdownShortkey() {
|
||||
closeShutdownShortkey() {
|
||||
echo "关闭 Ctrl+Alt+Del 快捷键防止重新启动"
|
||||
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf
|
||||
}
|
||||
|
||||
function closeSelinux() {
|
||||
closeSelinux() {
|
||||
echo "关闭 selinux"
|
||||
|
||||
# see http://blog.51cto.com/13570193/2093299
|
||||
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
|
||||
}
|
||||
|
||||
|
||||
function setBootMode() {
|
||||
setBootMode() {
|
||||
# 1. 停机(记得不要把 initdefault 配置为 0,因为这样会使 Linux 不能启动)
|
||||
# 2. 单用户模式,就像 Win9X 下的安全模式
|
||||
# 3. 多用户,但是没有 NFS
|
||||
@ -44,7 +47,8 @@ function setBootMode() {
|
||||
sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/inittab
|
||||
}
|
||||
|
||||
function configIpv4(){
|
||||
# 配置 IPv4
|
||||
configIpv4(){
|
||||
echo "配置 ipv4"
|
||||
|
||||
cat >> /etc/sysctl.conf << EOF
|
||||
@ -72,7 +76,8 @@ vm.swappiness=10
|
||||
EOF
|
||||
}
|
||||
|
||||
function closeIpv6() {
|
||||
# 关闭 IPv6
|
||||
closeIpv6() {
|
||||
echo "关闭 ipv6"
|
||||
|
||||
cat > /etc/modprobe.d/ipv6.conf << EOF
|
||||
@ -83,18 +88,46 @@ EOF
|
||||
echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
echo -e "\n>>>>>>>>> 配置系统环境"
|
||||
# 入口函数
|
||||
main() {
|
||||
PS3="请选择要执行的操作:"
|
||||
select ITEM in "设置 DNS" "设置 NTP" "关闭防火墙" "配置 IPv4" "关闭 IPv6" "全部执行"
|
||||
do
|
||||
|
||||
case ${ITEM} in
|
||||
"设置 DNS")
|
||||
${filepath}/set-dns.sh
|
||||
;;
|
||||
"设置 NTP")
|
||||
${filepath}/set-ntp.sh
|
||||
;;
|
||||
"关闭防火墙")
|
||||
${filepath}/stop-firewall.sh
|
||||
;;
|
||||
"配置 IPv4")
|
||||
configIpv4
|
||||
;;
|
||||
"关闭 IPv6")
|
||||
closeIpv6
|
||||
;;
|
||||
"全部执行")
|
||||
${filepath}/set-dns.sh
|
||||
${filepath}/set-ntp.sh
|
||||
${filepath}/stop-firewall.sh
|
||||
configIpv4
|
||||
closeIpv6
|
||||
;;
|
||||
*)
|
||||
echo -e "输入项不支持!"
|
||||
main
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
filepath=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
# 关闭 selinux
|
||||
closeSelinux
|
||||
|
||||
# 设置 DNS 服务器和本机 Host
|
||||
${filepath}/set-dns.sh
|
||||
|
||||
# 设置时间同步
|
||||
setNtp
|
||||
|
||||
echo -e "\n>>>>>>>>> 配置系统环境结束"
|
||||
printHeadInfo
|
||||
main
|
@ -1,11 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# 本脚本用于替换 yum repo,使用国内 yum 仓库,加速下载
|
||||
# 要求:仅适用于 Linux CentOS 发行版本,并且环境必须已支持 yum 、lsb_release 命令
|
||||
# Author: Zhang Peng
|
||||
###################################################################################
|
||||
|
||||
EOF
|
||||
|
||||
echo -e "\n>>>>>>>>> 替换 yum repo 源"
|
||||
|
||||
# 备份
|
||||
|
Loading…
Reference in New Issue
Block a user