模板机
重新安装一台 Linux
优化
软件
yum
创建虚拟机
注意:一共2块网卡
一个nat模式
一个lan区段模式
安装系统
修改网卡名:ens××--->eth0 eth1
在安装界面 光标移动到install centos7,按tab键 在最后输入 net.ifnames=0 biosdevname=0
如果忘了在安装启动系统时修改网卡名,就等系统装完后改
vim /boot/grub2/grub.cfg
找到Linux16的行,找第一个就行,并在行尾加上biosdevname=0 net.ifnames=0,加完后确认下防火墙和selinux是否关闭(如果没关闭可能无法生效),然后重启虚拟机
重启动后网卡可能启动不了,xshell无法连接。
因为原来网卡名是ens33,现在被改为eth0,所以网卡配置文件可能受到影响了。
cd到/etc/sysconfig/network-scripts/
cd /etc/sysconfig/network-scripts/
把ifcfg-ens33 修改成 ifcfg-eth0
mv ifcfg-ens33 ifcfg-eth0
然后再到ifcfg-eth0 配置文件内的NMAE和DEVICE也改成eth0
最后重启网卡 systemctl restart network
xshell即可链接
注意:更改网卡最好是在安装系统时完成,那样更简便快捷。
配置网卡
eth0 **.0.0.200 配置网关,DNS
eth1 172.16.1.*** 不配置网关,DNS
Linux系统基础优化
1、配置yum源base,epel
2、安装常用软件
3、关闭服务器和selinux
4、ssh连接慢解决
5、网络服务 关闭NetworkManager保留network
6、配置时间同步 定时任务
关闭防火墙和selinux
# 关闭防火墙 firewalld 、 iptables
systemctl stop firewalld
systemctl disable firewalld
# 关闭selinux(增强版的安全工具)
临时关闭 setenforce 0
getenforce #关闭 disabled 或 Permissive selinux关闭
永久关闭 --->重启Linux系统后生效
vi /etc/selinux/config
将上图选中的SELINUX=enforcing 修改为disabled 彻底关闭
enforcing --->selinux 启动状态
permissive---> selinux关闭状态,但是会提示警告信息
disabled ---->selinux彻底关闭状态
配置yum源base、epel
http://mirrors.aliyun/com/repo/Centos-7.repo
配置base源
crul -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun/com/repo/Centos-7.repo
配置epel源
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun/com/repo/Centos-7.repo
常用工具
yum istall -y tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat
iotop iftop htop unzip nc nmap telnet bc psmisc httpd-tools bind-utils nethogs
ssh连接慢解决
ssh服务端配置文件
vim /etc/ssh/sshd_config
改完重启ssh即可:systemctl restart sshd
网络服务关闭NetworkManager保留network
systemctl disable NetworkManager
systemctl stop NetworkManager
配置时间同步 定时任务
crontab -e ----> */2 * * * * /sbin/ntpdate ntp.aliyun.com &>/dev/null
PS1(修改环境变量)
控制命令行格式
命令行上色:export PS1='[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[31;1m\]\w\[\e[0m\]]\\s '
永久上色:vi /etc/porfile 将上面的命令添加到最后一行
source /etc/profile 立即生效 或者重新连接
u代表用户 h代表主机名 W代表路径 w绝对路径
export PS1='[\u@\h \w]\$' 修改后显示绝对路径
hosts解析
在一个局域网中通过主机名 互相访问Linux的服务器
在公网配置DNS:img.oldboy.com --DNS A记录 --->10.0.0.7
内网搭建的内部的DNS服务器服务(服务器数量巨大)
服务器数量不多---修改/etc/hosts文件 写入 解析记录
/etc/hosts应用场景,配置ip地址与主机名对应关系,类似于DNS
访问自己搭建的测试环境 jd.com --->10.0.0.200 10.0.0.200 jd.com
让局域网中的设备通过域名(主机名),互相访问
检查各项配置
检查防火墙:status firewalld.service
检查selinux:getenforce grep SELINUX= /etc/selinux/config
检查yum源:yum repolist
检查ssh服务:egrep -i 'GSSAPIA|UseDNS' /etc/ssh/sshd_config
检查网络服务: systemctl status NetworkManager
同步时间定时任务: crontab -l
检查hosts解析: cat /etc/hosts