一 安装centos7
下载centos7
去github下载centos系统ZIP包,链接:https://github.com/wsldl-pg/CentWSL/releases
解压下载的文件(不要放C盘),得到“CentOS7.exe”和“rootfs.tar”两个文件。
安装centos7
右键以管理员身份运行“CentOS7.exe”,等待安装完成
设置root账号密码
sudo passwd root
二 更换镜像源
删除官方镜像源
rm /etc/yum.repos.d/CentOS-Base.repo
更改镜像源为阿里云,不替换请求很慢或者超时
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
三 安装常用安装包
因为上面是最小安装,所以要安装常用安装包
yum -y update
yum -y install gcc gcc-c++ make wget
yum -y install openssh-clients openssh-server
yum -y install vim
yum -y install tar
yum -y install net-tools
yum -y install ncurses
四 ssh连接
出现 Failed to get D-Bus connection: Operation not permitted
解决方法:
1.备份文件
mv /usr/bin/systemctl /usr/bin/systemctl.old
2 下载systemctl文件
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
3 赋予权限
chmod +x /usr/bin/systemctl
4 生成SSH 主机密钥文件
检查密钥文件是否存在
ls /etc/ssh/ssh_host_*_key
生成新的密钥对:
sudo ssh-keygen -A
5.设置开机启动ssh,
在 ~/.bashrc 末尾添加:
if [ -z "$(ps aux | grep sshd | grep -v grep)" ]; then
sudo /usr/sbin/sshd
fi
6 查看ip
ip addr show
五 安装docker
# 添加 Docker 仓库
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装 Docker
sudo yum install -y docker-ce docker-ce-cli containerd.io
# 启动 Docker 守护进程(手动)
sudo dockerd &
设置开机自启动
在 ~/.bashrc 末尾添加:
if ! pgrep -f "dockerd" > /dev/null; then
sudo dockerd > /dev/null 2>&1 &
fi