linux系统安装及配置

本文详细介绍了在VMware中安装和配置LinuxCentOS7系统的过程,包括设置网卡(NAT和局域网)、系统安全优化(关闭防火墙和SELinux)、配置yum源、安装常用工具、优化SSH连接速度、同步时间和修改主机名/IP地址等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

linux系统安装及配置

1. 系统安装

下载使用vmware安装linux,contos7虚拟机(本文主要记录linux系统优化部分内容关于此内容可见优秀的文章例如(https://blog.youkuaiyun.com/hjp2020/article/details/106156642)。

2. 添加网卡

第1块网卡 nat模式: eth0 10.0.0.210 模拟公网
第2块网卡 :eth1 172.16.1.210 局域网

3. 系统优化

  1. 关闭防火墙及selinux
    	#1.关闭防火墙 firewalld
    	systemctl stop firewalld
    	systemctl disable firewall
    	
    	#2.关闭selinux(两个步骤:1.修改配置文件 2.重新启动)
    	#1.修改配置
    	sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
    	#2.重新启动
    	getenforce
    	setenforce 0
    	getenforce #结果不是enforcing即表示关闭selinux
    
  2. 配置yum源
    1. 步骤
    2. 详细代码
    #备份
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    
    #修改base源为阿里云
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
    
    #增加epel源
    curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    
    #清除缓存
    yum clean all
    
    #查看yum源(公有云不用配置yum源都是内部配置好的)
    yum repolist
    
  3. 安装常用工具
    yum install -y vim tree wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telent bc psmisc httpd-tools bind-utils nethogs expect
    yum install -y cowsay sl
    
  4. 优化ssh连接速度
    • 优化前:需要查询ip对应域名,此过程需要耗费一定时间,连接就会比较慢,间接导致某些服务速度就会较慢,优化即加速连接,加快服务的速度。
    • 优化方式:修改/etc/ssh/sshd_config配置。
    cat >>/etc/ssh/sshd_config<<EOF
    UseDNS no #相当于网络命令的-n选项
    GSSAPIAuthentication no #关闭GSS认证
    EOF
    
    # 重启ssh服务
    systemctl restart sshd
    
    # 检查(过滤查看,输出三个结果都为no即配置正确,不应该有其他输出)
    egrep '^(UseDNS|GSSAPIAuth)' /etc/ssh/sshd_config
    
  5. 同步时间
    # 查看时区
    timedatectl status 
    
    # 如果不对,设置时间,以上海为例
    timedatectl set-timezone Asia/Shanghai
    
    # 如果时间不对,同步一次即可,如果节点时间不同,需要同步时间
    yum install -y ntpdate
    crontab -l
    
    # 1. sync time whale
    */2 * * * * /sbin/ntpdate ntp1.aliyun.com $>/dev/unll 
    
  6. 修改主机名和ip地址
    #!/bin/bash
    #abthor:whale
    #desc: change ip and hostneme
    #version: v7.0
    #!/bin/bash
    #abthor:whale
    #desc: change ip and hostneme
    #version: v7.0
    #升级一些判断
    
    #判断参数格式是否为2
    [ $# -ne 2 ] && {
        echo "脚本使用方式不正确"\
        echo "正确方式:$) 主机名 ip地址"
        exit 1
    }
    #获取当前主机ip地址
    ip=`hostname -I |awk '{print $1}'|sed 's#.*\.'`
    #新的ip
    ip_new=`echo $2 |sed 's#^.*\.'`
    #新的主机名
    hostname=$1
    #修改ip
    sed -i "s#10.0.0.$ip#10.0.0.$ip_new#g"
    /etc/sysconfig/network-scripts/ifcfg-eth0
    sed -i "s#172.16.1.$ip#172.16.1.$ip_new#g"
    /etc/sysconfig/network-scripts/ifcfg-eth1
    #重启网卡
    systemctl restart network
    #修改主机名
    hostnamectl set-hostname $hostname
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

D. D

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值