wsl2子系统centos8 配置
centos8 配置
更新源
# 备份源
mkdir repo_bak
mv /etc/yum.repos.d/*.repo repo_bak/
# 更新源 wget
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 或者 curl
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
yum clean all # 清除系统所有的yum缓存
yum repolist
yum grouplist
yum makecache # 生成yum缓存
或者手动更改三个文件
CentOS-Linux-AppStream.repo
CentOS-Linux-BaseOS.repo
CentOS-Linux-Extras.repo
注释掉 mirrorlist= 替换baseurl
- 清华云镜像地址
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/virt/$basearch/advanced-virtualization/
- 阿里云镜像地址
baseurl=https://mirrors.aliyun.com/centos-vault//$contentdir/$releasever/AppStream/$basearch/os/
其他命令
yum -y install sudo
yum -y install wget vim
yum -y net-tools
dnf install langpacks-en glibc-all-langpacks -y # 安装命令语言包
yum install -y passwd # 用户密码管理
dnf -y install git
dnf -y install make
dnf -y install initscripts # 启用 service 命令
解决wsl 无法使用systemctl 问题
参考:hosinokoe's blog 博客repair-systemctl-in-CentOS8-on-WSL2
- 方法一: 安装genie
dnf install -y mock perl openssh-server # 安装依赖
# 下载安装包
dnf install -y epel-release wget
wget https://github.com/arkane-systems/genie/releases/download/v1.44/genie-1.44-1.fc34.x86_64.rpm
dnf install -y genie-1.44-1.fc34.x86_64.rpm
genie -s
systemctl start mysql
vim ~/.bashrc # 添加自启动
if [ "`ps -eo pid,lstart,cmd | grep systemd | grep -v -e grep -e systemd- | sort -n -k2 | awk 'NR==1 { print $1 }'`" != "1" ]; then
genie -s
fi
- 方法二(没试过)
sudo dnf install python2 -y
sudo ln -s /usr/bin/python2 /usr/bin/python
sudo mv /usr/bin/systemctl /usr/bin/systemctl.old
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py >temp
sudo mv temp /usr/bin/systemctl
sudo chmod +x /usr/bin/systemctl