Skip to content

Commit 12def54

Browse files
author
gclm
committed
feat(增加centos的初始化配置脚本):
1. 更换镜像 2. 更换终端名 3. 安装基础组件 vim curl wget 4. 修改扩展分区
1 parent 9b04559 commit 12def54

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

centos.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
centos_version="$1"
4+
5+
# 更换镜像为华为云 centos
6+
echo "==> 更换镜像为华为云"
7+
cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
8+
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-"$centos_version"-reg.repo
9+
dnf -y clean all
10+
dnf -y update
11+
12+
# 更换终端名
13+
hostname="centos$centos_version"
14+
echo "==> 修改hostname为$hostname"
15+
hostnamectl set-hostname centos
16+
hostnamectl --pretty
17+
hostnamectl --static
18+
hostnamectl --transient
19+
20+
# 安装基础组件
21+
dnf install -y curl wget vim
22+
23+
# 配置交换分区
24+
echo "==> 修改之前交换分区"
25+
swapon -s
26+
free -m
27+
echo "==> 开始配置交换分区"
28+
fallocate -l 2G /swap
29+
chmod 600 /swap
30+
mkswap /swap
31+
swapon /swap
32+
echo "/swap swap swap sw 0 0" >> /etc/fstab
33+
echo "==> 修改之后交换分区"
34+
swapon -s
35+
free -m
36+
37+

0 commit comments

Comments
 (0)