美文网首页
vmware 安装centos7设置

vmware 安装centos7设置

作者: wayyyy | 来源:发表于2023-06-18 21:34 被阅读0次

记录下每次安装虚拟机后需要进行的设置,以centos 7.9 mini 版本为例

centos 7 镜像下载

centos 7 镜像下载

vmware 安装,这里不再描述。

设置静态IP

参考:最详细的讲解,如何使用VMnet8模式给虚拟网络配置静态IP

配置DNS

编辑 /etc/resolv.conf,加入:

nameserver 8.8.8.8
配置主机名

如下命令配置主机名:

# hostnamectl --static set-hostname viros1
设置 /etc/hosts

编辑 /etc/hosts

192.168.48.20 viros1
192.168.48.21 viros2
192.168.48.22 viros3
关闭防火墙
# systemctl status firewalld.service
# systemctl stop firewalld.service
# systemctl disable firewalld.service
Disable SELinux

配置 SELINUX=disabled 在 /etc/selinux/config 文件:

image.png

然后重启系统,查看:

# getenforce
  Disabled
设置时区
# timedatectl set-timezone Asia/Shanghai  # 设置时区
# timedatectl set-local-rtc 0  # 将当前的 UTC 时间写入硬件时钟
# systemctl restart rsyslog  # 重启依赖时间的服务
# systemctl restart crond    # 重启依赖时间的服务
安装ssh服务
# yum install -y openssl openssh-server

更改配置文件,用vim 编辑 /etc/ssh/sshd_config

#PermitRootLogin yes    找到这一行,将行首的"#"掉,允许root用户登录
#PasswordAuthentication yes     找到这一行,将行首的"#"掉,允许密码登录

然后重启ssh服务

systemctl restart sshd
  • 配置免密登录
    # ssh-keygen -t rsa  # 输入命令之后一直回车用于生成我们的公私钥
    # ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.1.100  # 将我们的公钥拷贝至192.168.1.100,用作免密登录192.168.1.100时的认证
    
    image.png
配置aliyun源

可以配置ali的yum源,安装软件更快捷。

# yum install -y wget
# cd /etc/yum.repos.d
# mv CentOS-Base.repo CentOS-Base.repo.bak
# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo --no-check-certificate
# yum clean all && yum makecache

如果需要还原至官方的yum源

# rpm -Uvh --force http://mirror.centos.org/centos-7/7.9.2009/os/x86_64/Packages/centos-release-7-9.2009.0.el7.centos.x86_64.rpm
安装常用的软件

centos 7 安装gcc 7+ 的版本

# yum install centos-release-scl
# yum install devtoolset-8
# scl enable devtoolset-8 bash  # 可以将这个命令写入到 /etc/profile 文件中

centos 7 安装 cmake3

# yum install -y epel-release
# yum install -y cmake3

其他:

# yum install -y vim wget telnet curl net-tools bind-utils tree make autoconf automake
常用软件Proxy配置
  • 全局(不推荐)
    编辑 /etc/profile 文件,加入:

    export proxy="http://192.168.48.1:7890"
    export http_proxy=$proxy
    export https_proxy=$proxy
    #unset proxy           # 取消,放开注释
    #unset http_proxy      # 取消,放开注释
    #unset https_proxy     # 取消,放开注释
    

    然后执行:source /etc/profile

    但使用中发现,为什么我docker拉取国外的镜像还是失败呢?
    这是是因为systemd 引导启动的 service 默认不会读取这些变量,所以需要手动修改 service 启动文件,在其中加入环境变量解决。参考: 使用ssr也无法pull k8s的镜像问题
    如法,修改 /usr/lib/systemd/system/docker.service

    [Service]
    Environment="http_proxy=http://192.168.48.1:7890"
    Environment="https_proxy=http://192.168.48.1:7890"
    
    image.png

    然后再执行:systemctl daemon-reload && systemctl restart docker

  • yum
    编辑 /etc/yum.conf 文件,在最后增加:

    proxy=http://192.168.1.1:8080
    
  • git

    # git config --global http.proxy http://192.168.48.1:7890  # 关闭:git config --global --unset http.proxy
    # git config --global https.proxy https://192.168.48.1:7890  # 关闭:git config --global --unset https.proxy  
    

相关文章

网友评论

      本文标题:vmware 安装centos7设置

      本文链接:https://www.haomeiwen.com/subject/ihpsydtx.html