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. 系统优化
- 关闭防火墙及selinux
systemctl stop firewalld
systemctl disable firewall
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
getenforce
setenforce 0
getenforce
- 配置yum源
- 步骤
- 详细代码
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum repolist
- 安装常用工具
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
- 优化ssh连接速度
- 优化前:需要查询ip对应域名,此过程需要耗费一定时间,连接就会比较慢,间接导致某些服务速度就会较慢,优化即加速连接,加快服务的速度。
- 优化方式:修改/etc/ssh/sshd_config配置。
cat >>/etc/ssh/sshd_config<<EOF
UseDNS no #相当于网络命令的-n选项
GSSAPIAuthentication no #关闭GSS认证
EOF
systemctl restart sshd
egrep '^(UseDNS|GSSAPIAuth)' /etc/ssh/sshd_config
- 同步时间
timedatectl status
timedatectl set-timezone Asia/Shanghai
yum install -y ntpdate
crontab -l
*/2 * * * * /sbin/ntpdate ntp1.aliyun.com $>/dev/unll
- 修改主机名和ip地址
#!/bin/bash
[ $# -ne 2 ] && {
echo "脚本使用方式不正确"\
echo "正确方式:$) 主机名 ip地址"
exit 1
}
ip=`hostname -I |awk '{print $1}'|sed 's#.*\.'`
ip_new=`echo $2 |sed 's#^.*\.'`
hostname=$1
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