更新脚本

pull/11/head
Zhang Peng 2019-05-08 17:13:04 +08:00
parent e7f78bb486
commit 931d86e2d3
14 changed files with 212 additions and 152 deletions

View File

@ -1,9 +1,30 @@
# Linux 运维 # Linux 傻瓜式运维脚本
> **本项目脚本代码用于在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。** > **本项目脚本代码用于在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。**
使用说明:
1下载脚本
```sh
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/download.sh | bash
```
2执行脚本
```sh
cd /tmp/dunwu-ops
./dunwu-ops.sh
```
3清除脚本
```sh
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/clear.sh | bash
```
本项目总结、收集 Linux 环境下运维常用到的脚本工具,大致分为三类: 本项目总结、收集 Linux 环境下运维常用到的脚本工具,大致分为三类:
- [系统运维脚本](sys) - [系统运维脚本](sys)
- [服务、应用运维脚本](service) - [服务、应用运维脚本](soft)
- [构建、编译项目脚本(目前支持 Java、Javascript 应用)](build) - [构建、编译项目脚本(目前支持 Java、Javascript 应用)](build)

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
path=/tmp/dunwu-ops/
printf "\n>>>>>>>>> remove ${path}"
if [[ -d ${path} ]]; then
rm -f ${path}
printf "清除脚本成功"
else
printf "${path} 不存在,无法执行清除脚本操作"
fi

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
path=/tmp/dunwu-ops
mkdir -p ${path}
printf "\n>>>>>>>>> download scripts to ${path}"
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/dunwu-ops.sh -O ${path}/dunwu-ops.sh
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/dunwu-soft.sh -O ${path}/dunwu-soft.sh
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/dunwu-sys.sh -O ${path}/dunwu-sys.sh
chmod +x ${path}/dunwu-ops.sh
chmod +x ${path}/dunwu-soft.sh
chmod +x ${path}/dunwu-sys.sh

View File

@ -6,7 +6,7 @@ cat << EOF
*********************************************************************************** ***********************************************************************************
* 欢迎使用 Linux CentOS 环境运维脚本 * 欢迎使用 Linux CentOS 环境运维脚本
* Author: Zhang Peng * @author: Zhang Peng
*********************************************************************************** ***********************************************************************************
EOF EOF
@ -44,22 +44,23 @@ checkOsVersion(){
fi fi
} }
# 入口函数 menus=("配置系统" "安装软件" "退出")
main() { main() {
PS3="请选择要执行的脚本分类" PS3="请输入命令编号"
select item in "配置系统" "安装服务" select item in ${menus[@]}
do do
case ${item} in case ${item} in
"配置系统") "配置系统")
${path}/sys/main.sh ./dunwu-sys.sh
;; main ;;
"安装服务") "安装软件")
${path}/service/main.sh ./dunwu-soft.sh
;; main ;;
"退出")
exit 0 ;;
*) *)
echo -e "输入项不支持!" printf "输入项不支持!\n"
main main ;;
;;
esac esac
break break
done done
@ -67,7 +68,6 @@ done
######################################## MAIN ######################################## ######################################## MAIN ########################################
path=$(cd "$(dirname "$0")"; pwd) path=$(cd "$(dirname "$0")"; pwd)
printHeadInfo printHeadInfo
checkOsVersion 0 checkOsVersion 0
main main

View File

@ -0,0 +1,46 @@
#!/usr/bin/env bash
cat << EOF
***********************************************************************************
* 欢迎使用 Linux CentOS 软件安装配置脚本
* @author: Zhang Peng
***********************************************************************************
EOF
menus=("git" "zsh" "jdk8" "maven" "nodejs" "mongodb" "redis" "tomcat8" "kafka" "rocketmq" "zookeeper")
printMenu() {
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"
}
main() {
read -t 30 index
if [[ -n $index ]]; then
no=`expr ${index} - 1`
len=${#menus[*]}
if [[ ${index} -gt ${len} ]]; then
echo "输入项不支持!"
exit -1
fi
key=${menus[$no]}
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/${key}-install.sh | bash
else
echo "输入项不支持!"
exit -1
fi
}
######################################## MAIN ########################################
printMenu
main

View File

@ -0,0 +1,47 @@
#!/usr/bin/env bash
cat << EOF
###################################################################################
# Linux CentOS 环境初始化脚本(设置环境配置、安装基本的命令工具)
# @author: Zhang Peng
###################################################################################
EOF
menus=("替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出")
main() {
PS3="请输入命令编号:"
select item in ${menus[@]}
do
case ${item} in
"替换yum镜像")
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/change-yum-repo.sh | bash
main ;;
"安装基本的命令工具")
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-tools.sh | bash
main ;;
"安装常用libs")
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-libs.sh | bash
main ;;
"系统配置")
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/sys-settings.sh | bash
main ;;
"全部执行")
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/change-yum-repo.sh | bash
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-tools | bash
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-libs.sh | bash
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/sys-settings.sh | bash
printf "执行完毕,退出。\n" ;;
"退出")
exit 0 ;;
*)
printf "输入项不支持!\n"
main ;;
esac
break
done
}
######################################## MAIN ########################################
main

View File

@ -76,21 +76,39 @@ curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/lin
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash
``` ```
## Redis 安装 ## Redis 安装配置
说明: 说明:
下载 redis `5.0.4` 并解压安装到 `/opt/redis` 路径下。 - 下载 redis `5.0.4` 并解压安装到 `/opt/redis` 路径下。
- 替换配置,使得 Redis 可以远程访问,并设置默认密码为 123456。
- 注册 redis 服务,并设置为开机自启动
使用方法: 使用方法:
执行以下任意命令即可执行安装脚本。 执行以下任意命令即可按照默认配置安装脚本。
```sh ```sh
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash
``` ```
定制化配置
```sh
# 下载脚本到本地
wget https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh
chmod +x redis-install.sh
./redis-install.sh 5.0.4 /opt/redis 6379 123456
```
说明:
- 第一个参数是 redis 版本号;
- 第二个参数是 redis 安装路径;
- 第三个参数是 redis 服务端口号;
- 第四个参数是访问密码
## Tomcat8 安装 ## Tomcat8 安装
说明: 说明:

View File

@ -1,40 +0,0 @@
#!/usr/bin/env bash
cat << EOF
***********************************************************************************
* 欢迎使用 Linux CentOS 软件安装配置脚本
* Author: Zhang Peng
***********************************************************************************
EOF
path=$(cd "$(dirname "$0")"; pwd)
main() {
PS3="Please select script type: "
select item in "git" "zsh" "jdk" "maven" "nodejs" "mongodb" "redis" "tomcat" "kafka" "rocketmq" "zookeeper"
do
path=$(cd "$(dirname "$0")"; pwd)
case ${item} in
"git") yum install -y git ;;
"zsh") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/zsh-install.sh | bash ;;
"jdk") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/jdk8-install.sh | bash ;;
"maven") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/maven-install.sh | bash ;;
"nodejs") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/nodejs-install.sh | bash ;;
"mongodb") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash ;;
"redis") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash ;;
"tomcat") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/tomcat8-install.sh | bash ;;
"kafka") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/kafka-install.sh | bash ;;
"rocketmq") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/rocketmq-install.sh | bash ;;
"zookeeper") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/zookeeper-install.sh | bash ;;
*)
echo -e "输入项不支持!"
main
;;
esac
break
done
}
######################################## MAIN ########################################
main

View File

@ -1,24 +0,0 @@
#!/usr/bin/env bash
cat << EOF
###################################################################################
# 配置 Redis 脚本
# @system: 适用于 CentOS
# @author: Zhang Peng
###################################################################################
EOF
path=/opt/redis/redis-5.0.4
if [[ -n $1 ]]; then
path=$1
fi
echo -e "\n>>>>>>>>> config redis"
cp ${path}/redis.conf ${path}/redis.conf.default
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/config/redis-remote-access.conf -O ${path}/redis.conf
echo -e "\n>>>>>>>>> add firewall port"
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload

View File

@ -20,6 +20,16 @@ if [[ -n $2 ]]; then
root=$2 root=$2
fi fi
port=6379
if [[ -n $3 ]]; then
port=$3
fi
password=123456
if [[ -n $4 ]]; then
path=$4
fi
echo -e "\n>>>>>>>>> install libs" echo -e "\n>>>>>>>>> install libs"
yum install -y zlib zlib-devel gcc-c++ libtool openssl openssl-devel tcl yum install -y zlib zlib-devel gcc-c++ libtool openssl openssl-devel tcl
@ -28,7 +38,28 @@ mkdir -p ${root}
wget -O ${root}/redis-${version}.tar.gz http://download.redis.io/releases/redis-${version}.tar.gz wget -O ${root}/redis-${version}.tar.gz http://download.redis.io/releases/redis-${version}.tar.gz
echo -e "\n>>>>>>>>> install redis" echo -e "\n>>>>>>>>> install redis"
path=${root}/redis-${version}
tar zxf ${root}/redis-${version}.tar.gz -C ${root} tar zxf ${root}/redis-${version}.tar.gz -C ${root}
cd ${root}/redis-${version} cd ${path}
make && make install make && make install
cd - cd -
echo -e "\n>>>>>>>>> config redis"
cp ${path}/redis.conf ${path}/redis.conf.default
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/config/redis-remote-access.conf -O ${path}/redis.conf
cp ${path}/redis.conf /etc/redis/${port}.conf
sed -i "s/^port 6379/port ${port}/g" /etc/redis/${port}.conf
sed -i "s/^requirepass 123456/requirepass ${password}/g" /etc/redis/${port}.conf
echo -e "\n>>>>>>>>> add firewall port"
firewall-cmd --zone=public --add-port=${port}/tcp --permanent
firewall-cmd --reload
echo -e "\n>>>>>>>>> add redis service"
# 注册 redis 服务,并设置开机自启动
cp ${path}/utils/redis_init_script /etc/init.d/redis_${port}
sed -i "s/^REDISPORT=.*/REDISPORT=${port}/g" /etc/init.d/redis_${port}
chmod +x /etc/init.d/redis_${port}
chkconfig --add redis_${port}
service redis_${port} start

View File

@ -1,51 +0,0 @@
#!/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

View File

@ -96,13 +96,13 @@ do
case ${ITEM} in case ${ITEM} in
"设置 DNS") "设置 DNS")
${filepath}/set-dns.sh curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/set-dns.sh | bash
;; ;;
"设置 NTP") "设置 NTP")
${filepath}/set-ntp.sh curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/set-ntp.sh | bash
;; ;;
"关闭防火墙") "关闭防火墙")
${filepath}/stop-firewall.sh curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/stop-firewall.sh | bash
;; ;;
"配置 IPv4") "配置 IPv4")
configIpv4 configIpv4
@ -111,9 +111,9 @@ case ${ITEM} in
closeIpv6 closeIpv6
;; ;;
"全部执行") "全部执行")
${filepath}/set-dns.sh curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/set-dns.sh | bash
${filepath}/set-ntp.sh curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/set-ntp.sh | bash
${filepath}/stop-firewall.sh curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/stop-firewall.sh | bash
configIpv4 configIpv4
closeIpv6 closeIpv6
;; ;;

View File

@ -1,12 +0,0 @@
# 脚本使用说明
## 替换 yum repo 源
由于 CentOS 默认 yum 源,访问速度很慢,所以推荐使用国内镜像。
使用方法:执行以下任意命令即可执行脚本。
```sh
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
```