Administrator
Published on 2025-03-21 / 3 Visits
0
0

Centos常见使用问题

Centos7更换过期源

cd /etc/yum.repos.d/
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 或者 curl http://mirrors.aliyun.com/repo/Centos-7.repo > CentOS-Base.repo
yum clean all
yum makecache

或者使用文件:CentOS-Base.repo

Centos8更换过期源

参考:http://heawill.top/console/posts/editor?name=bc0df2b4-746e-42aa-9059-e18d9849dea4

如果需要额外安装screen等软件,可以加:

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Ubuntu22.04 Docker下Centos7的精简版调优

docker下运行centos7镜像,因为其镜像很精简,很多软件都没有,下面进行调优处理。

systemctl问题

执行时会提示:failed to get d-bus connection operation not permitted

curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
chmod +x /usr/bin/systemctl

SSH Server 安装

yum install openssh-server

//下面必须,执行时一直回车即可,不然sshd启动不来
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

//root用户允许登录
vi /etc/ssh/sshd_config
//配置修改
PermitRootLogin yes

systemctl start sshd
systemctl enable sshd

时间

rm /etc/localtime
ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum -y install ntp ntpdate
ntpdate ntp.aliyun.com

问题

通过测试,在Ubuntu22.04 Docker下运行Centos7会有许多问题,比如systemctl和timedatectl出错问题,openssh-server少证书问题,虽然通过上面方法处理,但是另外还有mysql重新运行容器后就运行不起来,得重装;运行几天出现容器进不去,出现Failed to allocate manager object, freezing等错误。

后续推荐使用centos8版本的容器,systemctl和timedatectl等指令都正常。


Comment