1.DNS的配置文件:/etc/resolv.conf

Linux系统中两个文件都可以配置DNS
第一个网卡配置文件:
[root@linuxsd ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
UUID=6e83ba96-c99b-4848-9303-2d4ac2fa9c31
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.200
PREFIX=24
GATEWAY=10.0.0.2
DNS1=223.5.5.5
第二个: resolv.conf 
[root@linuxsd ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 223.5.5.5

.........................................................

两个关系:
1.如果网卡配置了DNS,
重启网卡会覆盖resolv.conf
2.如果网卡中不配置DNS则不影响resolv.conf 手动写入resolv.conf
3.在访问域名时读取的resolv.conf中的DNS服务器

[root@linuxsd ~]# yum -y install bind-utils

在企业中应该如何配置:
网卡和resolv.conf都需要配置
网卡配置备用:
DNS1=223.5.5.5
DNS2=114.114.114.114

resolv.conf配置备用的DNS
vim /etc/resolv.conf
nameserver 114.114.114.114
nameserver 223.5.5.5
nameserver 8.8.8.8

重启网卡命令:service network restart

2.开机自动执行命令(自动执行脚本):/etc/rc.local

要给源文件一个执行权限:
[root@linuxsd ~]# chmod +x /etc/rc.d/rc.local
[root@linuxsd ~]# ll /etc/rc.d/rc.local 
-rwxr-xr-x. 1 root root 473 Oct  2  2020 /etc/rc.d/rc.local


快捷方式:
[root@linuxsd ~]# ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Jun 29 17:46 /etc/rc.local -> rc.d/rc.local
源文件:
[root@linuxsd ~]# ll /etc/rc.d/rc.local 
-rw-r--r--. 1 root root 473 Oct  2  2020 /etc/rc.d/rc.local

[root@linuxsd ~]# vim /etc/rc.local
写入:
mkdir -p /root/1/2/3/4/5

重启测试
[root@linuxsd ~]# reboot

3.永久存放系统变量的文件:/etc/profile

只要通过xshell重新连接或者重启系统都会执行一遍profile中的配置
什么是变量: 用一个固定的值 表示一堆经常变化的内容
书本的目录--->内容
第一页--->第一页中的内容
x=1 y=x+1 y=2
变量定义:
[root@linuxsd ~]# name=oldboy
[root@linuxsd ~]# echo $name
oldboy

Linux执行命令的流程:
1.我们输入命令
2.系统会查找命令(命令存放在/bin目录下)
3.系统查找的变量文件PATH 在PATH变量中查找我们输入的命令是否在路径中
如果在PATH中找到了命令的路径则执行
如果在PATH中找不到则提示 command not Found

查找命令所在的位置:

[root@linuxsd ~]# which mkdir
/usr/bin/mkdir

案例:

将touch移动到/tmp目录
[root@linuxsd ~]# mv /usr/bin/touch /tmp/

[root@linuxsd ~]# touch 1.txt
-bash: /usr/bin/touch: No such file or directory
解决方案:
1.将touch移动到/usr/bin
2.重新定义PATH变量 将命令所在的目录编辑到PATH中
[root@linuxsd ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@linuxsd ~]#               
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp'

临时生效重启或者退出失效

在Linux系统中在访问/bin目录时实际访问的/usr/bin
lrwxrwxrwx. 1 root root 7 Jun 29 17:45 /bin -> usr/bin



提高工作效率 重复操作网卡的配置文件
/etc/sysconfig/network-scripts/ifcfg-eth0

[root@linuxsd ~]# eth0=/etc/sysconfig/network-   scripts/ifcfg-eth0

[root@linuxsd ~]# vim /etc/profile 写入永久有效/
eth0=/etc/sysconfig/network-scripts/ifcfg-eth0

[root@linuxsd ~]# echo $eth0
[root@linuxsd ~]# cat $eth0
[root@linuxsd ~]# vim $eth0 

4.开机自动挂载硬件:/etc/fstab
4.1 挂载步骤:

/dev/sda3       /       xfs defaults 0 0

每列的含义:
第一列: /dev/sda3  表示设备名称
第二列: /          表示挂载点 硬件设备入口
第三列: xfs        文件系统类型
第四列: defaults   挂载的参数默认即可
第五列: 0          开机是否备份   0为不备份 1 为备份
第六列: 0          开机是否已自检 0为不检查 1为检查

第一个步骤:插入iso进行文件到光驱中(安装虚拟机时已插入)

第二个步骤:查看光驱所在Linux中所在位置
[root@linuxsd ~]# ll /dev/cdrom
lrwxrwxrwx. 1 root root 3 Jul  6 11:25 /dev/cdrom -> sr0

第三个步骤:创建一个文件入口(实际就是一个/下目录),或者已经存在的目录/mnt
[root@linuxsd ~]# mkdir /data(或者/mnt)

第四个步骤:挂载 给硬件设备开通一个入口
[root@linuxsd ~]# mount /dev/cdrom /data
mount: /dev/sr0 is write-protected, mounting read-only

重启后挂载生效: 使用 df -h 查看
[root@linuxsd ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        980M     0  980M   0% /dev
tmpfs           991M     0  991M   0% /dev/shm
tmpfs           991M  9.5M  981M   1% /run
tmpfs           991M     0  991M   0% /sys/fs/cgroup
/dev/sda3        18G  1.9G   16G  11% /
/dev/sda1       197M  110M   88M  56% /boot
tmpfs           199M     0  199M   0% /run/user/0

第五个步骤:写入开机自动挂载:  写入到最下面一行
查看光驱的uuid和类型:
[root@linuxsd ~]# blkid
/dev/sda1: UUID="801a08ae-5c17-4216-8bc3-c2017d60bcc1" TYPE="xfs" 
/dev/sda2: UUID="982bac46-60f8-4ddc-96c8-10ecd4f4f26c" TYPE="swap" 
/dev/sda3: UUID="d5355063-98d4-4309-8c1a-4531a343b1ab" TYPE="xfs" 
/dev/sr0: UUID="2020-11-04-11-36-43-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 

写入开机挂在内容:
[root@linuxsd ~]# vim /etc/fstab
# Created by anaconda on Thu Jun 29 17:44:56 2023
# Accessible filesystems, by reference, are maintained  under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or   blkid(8) for more info

UUID=d5355063-98d4-4309-8c1a-4531a343b1ab /                       xfs     defaults        0 0
UUID=801a08ae-5c17-4216-8bc3-c2017d60bcc1 /boot                   xfs     defaults        0 0
UUID=982bac46-60f8-4ddc-96c8-10ecd4f4f26c swap                    swap    defaults        0 0
/dev/cdrom    /data    iso9660        defaults 0 0

4.2 卸载设备步骤:

注意: 不能在设备中进行卸载 否则会提示目标忙
# umount:卸载挂载命令
[root@linuxsd data]# umount /data
umount: /data: target is busy.
     (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))
 
切换到家目录或者其他路径进行卸载使用umount
[root@linuxsd data]# cd
[root@linuxsd ~]# umount /data
[root@linuxsd ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        980M     0  980M   0% /dev
tmpfs           991M     0  991M   0% /dev/shm
tmpfs           991M  9.5M  981M   1% /run
tmpfs           991M     0  991M   0% /sys/fs/cgroup
/dev/sda3        18G  1.9G   16G  11% /
/dev/sda1       197M  110M   88M  56% /boot
tmpfs           199M     0  199M   0% /run/user/0
      

4.3 总结:简版挂载步骤

挂载设备:
1.创建入口目录 mkdir /data
2.挂载设备     mount /dev/cdrom /data
3.写入开机挂载配置文件  
vim /etc/fstab
/dev/cdrom    /data    iso9660        defaults 0 0

5.Linux运行级别配置文件:/etc/inittab

init  0   表示关机
init  1   表示单用户模式,忘记密码可以进入单用户模式找回(扩  展)
init  2   表示多用户 但是不支持NFS网络文件系统
init  3   表示完全多用户,系统开机默认运行次级别
init  4   表示待开发,未使用
init  5   表示桌面模式 需要安装DESKTOP图形化
init  6   表示重启

 [root@linuxsd ~]# runlevel  # 默认运行级别
 N 3

6.清空两个文件:/etc/issue /etc/issue.net

 [root@linuxsd ~]# > /etc/issue
[root@linuxsd ~]# > /etc/issue.net 

7.开机自动显示的字符串:etc/motd

[root@linuxsd ~]# cat /etc/motd
诚毅求真 笃学强技!!!

8.网卡配置文件:

[root@oldboy ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet    # 网络类型 以太网 Fastethernet(快速以太网)
BOOTPROTO=none   # 配置获取IP地址的方式
                 # none   手动配置
                 # static 手动配置
                 # dhcp   自动获取
NAME=eth0        # 网卡在系统中的名称
UUID=6e83ba96-c99b-4848-9303-2d4ac2fa9c31  # 硬件设备的唯一标识 在配置文件中删除
DEVICE=eth0      # 网卡的硬件名称
ONBOOT=yes       # 开机是否自动运行网络
IPADDR=10.0.0.200 # IP地址 局域网内唯一 公网唯一
PREFIX=24        # 子网掩码 决定了网络中可用的ip地址数
10.0.0.1-10.0.0.254/24
GATEWAY=10.0.0.2  # 网关 去往不同网段的必经之路
DNS1=223.5.5.5    # 域名解析服务 将域名解析成IP地址

9.主机名称:/etc/hostname

主机名称表示本机 系统开机或者重启 自动读取hostname配置文件
[root@hehe ~]# cat /etc/hostname 
oldboy
查看当前的主机名称:
[root@oldboy ~]# hostname
oldboy
修改主机名称方式:
第一种方式:临时修改(重启失效)  不会修改配置文件
[root@oldboy ~]# hostname hehe
然后重新连接xshell生效
[root@hehe ~]# reboot   # 重启后失效

扩展:
[root@oldboy ~]# bash
[root@hehe ~]# 

第二种方式:永久修改主机名称 编辑配置文件必须重启生效
[root@hehe ~]# vim /etc/hostname 
oldgirl
[root@hehe ~]# cat /etc/hostname 
oldgirl

第三种方式: 临时生效+永久生效 重点
[root@hehe ~]# hostnamectl set-hostname linuxsd
[root@hehe ~]# cat /etc/hostname
linuxsd

持续分享运维干货,感谢大家的阅读和关注!

请输入图片描述

发表评论

召唤看板娘