目录

VMware安装CentOS

misaraty 更新 | 2024-12-26
前言
VMware-设置-网络适配器-桥接模式(复制物理……勾选),重启。

CentOS7-Minimal

1
2
3
4
vi XXX # vim打开文件
i # 转入修改模式
Esc->:wq # 保存并退出
Esc->:q! # 不保存并退出
  • 安装SSH
1
2
3
4
5
6
cd /etc/sysconfig/network-scripts/
vi ifcfg-ens33
ONBOOT=yes
service network restart

yum install openssh-server net-tools -y
注意
有时ifconfig会失效,我们可以yum remove openssh-server net-tools -y,然后重新安装,重启虚拟机,即可解决问题。
  • 重置密码
1
passwd misaraty
1
2
3
4
5
6
7
# 对于 CentOS 7
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.bfsu.edu.cn|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo
         
sudo yum makecache
  • 安装依赖包
1
2
yum install gcc gcc-c++ gcc-gfortran -y
yum install wget make gdb cmake git zip unzip bzip2 java-1.8.0-openjdk -y
  • 设置时间
1
timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海
  • 关闭防火墙
1
2
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
  • 关闭selinux
1
2
gedit /etc/sysconfig/selinux
SELINUX=disabled
警告

下面这行是错误的,

1
SELINUXTYPE=disabled #错误
1
2
setenforce 0 #临时关闭SELinux
getenforce #查看SELinux状态
  • 升级内核和软件包
1
2
yum -y update #升级所有包同时也升级软件和系统内核
yum -y upgrade #只升级所有包,不升级软件和系统内核

1

  • 切换到Vault仓库

 备份原有仓库配置,

1
2
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/

 配置Vault仓库,

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
cat > /etc/yum.repos.d/CentOS-Vault.repo <<EOF
[base]
name=CentOS-7 - Base
baseurl=http://vault.centos.org/centos/7.9.2009/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-7 - Updates
baseurl=http://vault.centos.org/centos/7.9.2009/updates/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-7 - Extras
baseurl=http://vault.centos.org/centos/7.9.2009/extras/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF

 刷新缓存并检查仓库状态,

1
2
3
yum clean all
yum makecache
yum repolist
  • 安装openssl
1
2
3
4
5
6
7
8
9
wget https://www.openssl.org/source/openssl-3.0.13.tar.gz
tar -xvzf openssl-3.0.13.tar.gz
cd openssl-3.0.13

./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
make
make install

openssl version
  • 安装curl
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
wget https://curl.se/download/curl-8.5.0.tar.gz
tar -xzf curl-8.5.0.tar.gz
cd curl-8.5.0
make clean
./configure --prefix=/usr/local --with-openssl --with-libcurl=/usr/local LDFLAGS="-Wl,-rpath,/usr/local/lib"
make
make install


ldd /usr/local/bin/curl | grep libcurl

mv /usr/lib64/libcurl.so.4 /usr/lib64/libcurl.so.4.bak
mv /usr/lib/libcurl.so.4 /usr/lib/libcurl.so.4.bak
mv /usr/lib64/libcurl.so.4.3.0 /usr/lib64/libcurl.so.4.3.0.bak
mv /usr/lib/libcurl.so.4.3.0 /usr/lib/libcurl.so.4.3.0.bak
ln -s /usr/local/lib/libcurl.so.4.8.0 /usr/lib64/libcurl.so.4
ln -s /usr/local/lib/libcurl.so.4.8.0 /usr/lib/libcurl.so.4
ldconfig
  • 安装patchelf
1
2
3
4
5
6
7
8
wget https://github.com/NixOS/patchelf/releases/download/0.17.2/patchelf-0.17.2.tar.gz
tar -xvzf patchelf-0.17.2.tar.gz
cd patchelf-0.17.2

./configure
make
make install
patchelf --set-rpath /usr/local/lib /usr/local/bin/curl

CentOS7-LiveGNOME

报错

/etc/sysconfig/network-scripts内找不到ifcfg-ens33

解决
1
2
cp ifcfg-lo ifcfg-ens33
gedit ifcfg-ens33

根据ifconfig命令修改ifcfg-ens33

1
2
3
4
5
DEVICE=ens33
NETMASK=255.255.255.0
BROADCAST=172.16.218.255
ONBOOT=yes
BOOTPROTO=static

重启服务,

1
service network restart

问题

若安装已停止维护的Centos,如何更新呢?

解决
可以修改/etc/yum.repos.d/CentOS-Base.repo文件,将关键词centos换为centos-vault等。
2


  1. Centos7更新 ↩︎

  2. centos-vault 镜像使用帮助 ↩︎