Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
buyfakett committed Jan 29, 2023
1 parent cf6924d commit f75b22e
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 66 deletions.
36 changes: 0 additions & 36 deletions README.en.md

This file was deleted.

41 changes: 11 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
# centos7_initialization
# centos7_initialization

#### 介绍
{**以下是 Gitee 平台说明,您可以替换此简介**
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
初始化centos7用的脚本

#### 软件架构
软件架构说明
如果遇到执行不了请执行

```bash
vim 脚本名

#### 安装教程
:set ff=unix

1. xxxx
2. xxxx
3. xxxx
:x
```

#### 使用说明
脚本不是很成熟,有bug请及时在github反馈哦~ 或者发作者邮箱:[email protected]

1. xxxx
2. xxxx
3. xxxx
觉得作者写的不错的话可以支持一下作者,请作者喝一杯咖啡哦~

#### 参与贡献
![](./pay_img/ali.webp)![](./pay_img/wechat.webp)

1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request


#### 特技

1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
202 changes: 202 additions & 0 deletions initialization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#!/bin/bash
####################################################参数修改开始########################################################################

#检查版本(0是不检查;1是检测gitee;2是检测github)
inspect_script=1
#是否全部执行(y为全部执行)
if_all=n

####################################################参数修改结束########################################################################

flag=n
PWD=$pwd

#颜色参数,让脚本更好看
Green="\033[32m"
Font="\033[0m"
Red="\033[31m"

#本地脚本版本号
shell_version=v1.0.0
#远程仓库作者
git_project_author_name=buyfakett
#远程仓库项目名
git_project_project_name=centos7_initialization
#远程仓库名
git_project_name=${git_project_author_name}/${git_project_project_name}

#打印帮助文档
function echo_help(){
echo -e "${Green}
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
#脚本是为了初始化centos7而准备的
#脚本不是很成熟,有bug请及时在github反馈哦~
#或者发作者邮箱:[email protected]
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
${Font}"
}

#root权限
function root_need(){
if [[ $EUID -ne 0 ]]; then
echo -e "${Red}你现在不是root权限,请使用sudo命令或者联系网站管理员${Font}"
exit 1
fi
}

#检查版本
function is_inspect_script(){
yum install -y wget jq

if [ $inspect_script == 1 ];then
remote_version=$(wget -qO- -t1 -T2 "https://gitee.com/api/v5/repos/${git_project_name}/releases/latest" | jq -r '.tag_name')
elif [ $inspect_script == 2 ];then
remote_version=$(wget -qO- -t1 -T2 "https://api.github.com/repos/${git_project_name}/releases/latest" | jq -r '.tag_name')
fi

if [ ! "${remote_version}"x = "${shell_version}"x ];then
if [ $inspect_script == 1 ];then
wget -N "https://gitee.com/${git_project_name}/releases/download/${remote_version}/$0"
elif [ $inspect_script == 2 ];then
wget -N "https://github.com/${git_project_name}/releases/download/${remote_version}/$0"
fi
else
echo -e "${Green}您现在的版本是最新版${Font}"
fi
echo -e "${Green}您已更新最新版本,请重新执行${Font}"
exit 1
}

#检测输入封装的方法
function judge(){
read -p "输入y继续:" para

case $para in
[yY])
flag=y
;;
[nN])
flag=n
;;
*)
echo "输入不对,请重新输入"
judge
esac
}

#更新yum包
function update(){
yum install -y wget
cd /etc/yum.repos.d
clear
echo -e "${Green}
0:不换源
1:阿里
2:网易
3:清华大学
${Font}"
read -p "是否换源:" para
case $para in
0)
echo -e "您已选择不换源"
;;
1)
mv Centos-Base.repo Centos-Base.repo.bak
wget -O Centos-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache
;;
2)
mv Centos-Base.repo Centos-Base.repo.bak
wget -O Centos-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all && yum makecache
;;
3)
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
yum clean all && yum makecache
;;
*)
echo "输入不对,请重新输入"
update
esac
yum install -y yum-utils device-mapper-persistent-data lvm2
yum update -y

cd $PWD
}

#下载docker
function install_docker(){
sed -i 's/#$ModLoad imtcp/$ModLoad imtcp/g' /etc/rsyslog.conf
sed -i 's/#$InputTCPServerRun 514/$InputTCPServerRun 514/g' /etc/rsyslog.conf
systemctl restart rsyslog

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum clean all && yum makecache
yum -y install docker-ce docker-ce-cli containerd.io && systemctl start docker && systemctl enable docker

cat << EOF > /etc/docker/daemon.json
{
"registry-mirrors": [
"https://pee6w651.mirror.aliyuncs.com"
],
"data-root": "/data/data-docker",
"log-driver": "syslog",
"log-opts": {
"syslog-address": "tcp://127.0.0.1:514",
"tag": "docker/{{.Name}},"
}
}
EOF
systemctl restart docker

cat << EOF > /etc/rsyslog.d/rule.conf
\$EscapeControlCharactersOnReceive off
# 删除日志首位空格,只保留原日志
\$template CleanMsgFormat,"%msg:2:$%\n"
\$template docker,"data/logs/docker/%syslogtag:F,44:1%/%\$YEAR%-%\$MONTH%-%\$DAY%.log"
if \$syslogtag contains 'docker' then ?docker;CleanMsgFormat
& ~
EOF
systemctl restart rsyslog

systemctl restart docker

curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
}

#全部执行(不用输入y)
function all(){
update
install_docker
}

#需要手动确认
function not_all(){
update
echo -e "${Green}是否安装docker${Font}"
judge
if [[ "$flag"x == "y"x ]];then
install_docker
flag=n
fi
}

function main(){
root_need
if [ ! $inspect_script == 0 ];then
echo -e "${Green}您已开始检查版本${Font}"
is_inspect_script
else
echo -e "${Green}您已跳过检查版本${Font}"
fi

echo_help
[ "$if_all"x == "y"x ] && all || not_all
}

main
Binary file added pay_img/ali.webp
Binary file not shown.
Binary file added pay_img/wechat.webp
Binary file not shown.

0 comments on commit f75b22e

Please sign in to comment.