Centos7.6~8.5 初始化服务器环境
Centos7.6~8.5 初始化服务器环境

Centos7.6~8.5 初始化服务器环境

Centos7.6~8.5

自动时间校对

# 设置时区
timedatectl set-timezone Asia/Shanghai
# 24小时
localectl set-locale LC_TIME=en_US.UTF-8
localectl set-locale LANG=zh_CN.UTF-8

localectl status

# 自动对时
yum install -y chrony

vim /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
#pool 2.centos.pool.ntp.org iburst(注释该行)
pool ntp1.aliyun.com iburst
pool ntp2.aliyun.com iburst
pool ntp3.aliyun.com iburst
pool ntp4.aliyun.com iburst
pool ntp5.aliyun.com iburst
pool ntp6.aliyun.com iburst

systemctl enable chronyd
systemctl restart chronyd
systemctl status chronyd

chronyc sources

# date
Mon Sep 15 19:40:28 CST 2025

换源

官方推荐

https://developer.aliyun.com/article/831597

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 

# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo


yum clean all && yum makecache
yum repolist 

阿里vault

cat /etc/centos-release
# CentOS Linux release 8.5.2111

# 备份
mkdir -p /root/repo-backup-$(date +%F)
mv /etc/yum.repos.d/*.repo /root/repo-backup-$(date +%F)/


sudo tee /etc/yum.repos.d/CentOS-Vault-Aliyun-8.5.repo > /dev/null <<'EOF'
[BaseOS]
name=CentOS-8.5.2111 - BaseOS (Aliyun Vault)
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[AppStream]
name=CentOS-8.5.2111 - AppStream (Aliyun Vault)
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[Extras]
name=CentOS-8.5.2111 - Extras (Aliyun Vault)
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[PowerTools]
name=CentOS-8.5.2111 - PowerTools (Aliyun Vault)
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF

sudo tee /etc/yum.repos.d/CentOS-Vault-aliyun.repo > /dev/null << 'EOF'
[centos7.6-os]
name=CentOS-7.6.1810 - OS - aliyun
baseurl=http://mirrors.aliyun.com/centos-vault/7.6.1810/os/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.aliyun.com/centos-vault/7.6.1810/os/$basearch/RPM-GPG-KEY-CentOS-7

[centos7.6-updates]
name=CentOS-7.6.1810 - Updates - aliyun
baseurl=http://mirrors.aliyun.com/centos-vault/7.6.1810/updates/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.aliyun.com/centos-vault/7.6.1810/os/$basearch/RPM-GPG-KEY-CentOS-7

[centos7.6-extras]
name=CentOS-7.6.1810 - Extras - aliyun
baseurl=http://mirrors.aliyun.com/centos-vault/7.6.1810/extras/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.aliyun.com/centos-vault/7.6.1810/os/$basearch/RPM-GPG-KEY-CentOS-7

[centos7.6-centosplus]
name=CentOS-7.6.1810 - CentOSPlus - aliyun
baseurl=http://mirrors.aliyun.com/centos-vault/7.6.1810/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/7.6.1810/os/$basearch/RPM-GPG-KEY-CentOS-7
EOF

# 更新缓存
yum clean all && yum makecache
dnf clean all && dnf makecache

# 更新包
yum update -y
dnf update -y

安装宝塔

url=https://download.bt.cn/install/install_panel.sh;if [ -f /usr/bin/curl ];then curl -sSO $url;else wget -O install_panel.sh $url;fi;bash install_panel.sh ssl251104

# 开心  baota.la
curl https://baota.la/install/update6.sh|bash

添加硬盘

fdisk -l
# 根据分区大小选择要格式化并挂载的硬盘,没有格式化的没有Device
Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: Virtual Disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: Virtual Disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 977F811C-B8CA-48C4-8A0B-59727A6A9A33

Device       Start      End  Sectors  Size Type
/dev/sda1     2048     4095     2048    1M BIOS boot
/dev/sda2     4096  3719167  3715072  1.8G Linux filesystem
/dev/sda3  3719168 41940991 38221824 18.2G Linux filesystem


# 创建分区表
fdisk /dev/sdb
n
p
1
回车
回车
w

# 格式化
mkfs -t ext4 -c /dev/sdb1
# 挂载
mount /dev/sdb1 /www
# 开机挂载
vi /etc/fstab
/dev/sdb1 /www ext4 defaults 0 0

# 对于重启挂载顺序会变的盘,请使用如下uuid方式
lsblk -f
vi /etc/fstab
UUID=c2c20226-f001-4e11-82bf-7ea99edfbbf3 /www ext4 defaults 0 2
# mount -a

安装 雷池WAF

https://help.waf-ce.chaitin.cn/node/01973fc6-df0f-7650-bafa-8ed8d2fc2bc1

bash -c "$(curl -fsSLk https://waf-ce.chaitin.cn/release/latest/manager.sh)"

安装 1Panel

bash -c "$(curl -sSL https://resource.fit2cloud.com/1panel/package/v2/quick_start.sh)"

手动安装 Docker

yum install -y yum-utils device-mapper-persistent-data lvm2
yum install epel-release -y
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r

tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://cf-workers-docker-io-7p7.pages.dev/",
    "https://hub.rat.dev/",
    "https://docker.1panel.live/",
    "https://docker.m.daocloud.io/"
  ]
}
EOF
# 安装旧版
# yum install docker-ce-19.03.15-3.el7 docker-ce-cli-19.03.15-3.el7 containerd.io -y

# 新版会爆依赖错误  slirp4netns fuse-overlayfs
# 解决方案
yum install -y wget fuse3 
wget https://buildlogs.centos.org/c7-extras.i386/slirp4netns/20200428221211/0.4.3-4.el7_8.x86_64/slirp4netns-0.4.3-4.el7_8.x86_64.rpm
rpm -ivh slirp4netns-0.4.3-4.el7_8.x86_64.rpm
wget https://buildlogs.centos.org/c7-extras.i386/fuse-overlayfs/20200428141645/0.7.2-6.el7_8.x86_64/fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
rpm -ivh fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm

yum install -y docker-ce docker-ce-cli docker-compose-plugin

systemctl enable docker
systemctl start docker

手动python3

sudo yum groupinstall -y "Development Tools"

sudo yum install -y epel-release
sudo yum install -y gcc gcc-c++ make cmake git wget curl vim nano automake autoconf libtool libuuid-devel pkg-config bzip2 bzip2-devel zlib zlib-devel xz xz-devel openssl openssl-devel ncurses ncurses-devel sqlite sqlite-devel readline readline-devel gdb valgrind libffi-devel tk-devel

# curl https://pyenv.run | bash
git clone https://github.com/pyenv/pyenv.git /www/.pyenv

# 添加环境变量
vim ~/.bashrc
# export PYENV_ROOT="$HOME/.pyenv"
export PYENV_ROOT="/www/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
export PYTHON_BUILD_MIRROR_URL="https://mirrors.huaweicloud.com/python"
export PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM=1
eval "$(pyenv init --path)"
eval "$(pyenv init -)"


pyenv --version

# Centos 7.6 ssl版本过低,需要升级
yum install -y openssl11 openssl11-devel
export LDFLAGS="-L/usr/lib64/openssl11"
export CPPFLAGS="-I/usr/include/openssl11"

pyenv install 3.10.5
pyenv global 3.10.5
pyenv local 3.10.5


python -m ssl
python -c "import ssl; print(ssl.OPENSSL_VERSION)"

FastGitHub

https://github.com/WangGithubUser/FastGitHub

yum install -y libicu

# https://github.com/WangGithubUser/FastGitHub/releases/download/v2.1.5/fastgithub_linux-x64.zip

sudo ./fastgithub start


git config --global http.proxy http://127.0.0.1:38457
git config --global https.proxy http://127.0.0.1:38457
# git config --global --unset http.proxy
# git config --global --unset https.proxy