day07-系统重要配置文件

01.知识点回顾

01.vim快捷键
  快捷键
  G 光标快速移动到文件行尾
  10G 光标快速移动到第10行
  gg 光标快速移动到文件行首
  $ end
  光标快速移动到行首 Home ^ 0
  编辑模式
  i 插入
  C 删除光标所在行到行尾,并且进入编辑模式
  x 删除一个字母
  删除模式
  dd 删除一行
  D 删除光标所在位置到行尾
  d^ 删除光标所在到行首
  dG 删除光标所在到文件末尾
  dw 删除单词
  复制模式
  yy 复制当前行
  yy3 复制光标所在往下3行
  p 黏贴
  底行模式查找
  /
 显示行号:set nu
 撤销操作 返回上一次操作 u

 解决办法
  1、保存上次编辑操作
  	vim -r
  	:wq!
  	删掉.swp文件
  2、不保存上次编辑操作
  	删掉.swp文件

02.系统的重要配置文件
 	1)、网卡配置
 	  TYPE=Ethernet 网络类型 以太网
    BOOTPROTO=none 配置网络类型 自动获取ip 静态ip=none 静态地址=static
    NAME=ens33 网络名字
    DEVICE=ens33 网络硬件名字
    ONBOOT=yes 开机自动连接网络服务
    IPADDR=10.0.0.200  ip地址
    PREFIX=24 子网掩码
    GATEWAY=10.0.0.2 网关
    DNS1=223.5.5.5 域名解析服务

   ifdown ens33  && ifup ens33
   2)、/etc/hostname
       hostname
       hostnamectl
       cat /etc/hostname
       uname -n
      临时修改
      1、
      永久修改
      1、了解
      2、hostnamectl set-hostname  xxx
   3)/etc/hosts
   10.0.0.200 www.baidu.com

每天学习都要按照我明天要上去分享。
02.Linux 系统配置文件

1./etc/sysconfig/network-scripts/ifcfg-ens33

2./etc/hostname
3./etc/hosts
4./etc/resolv.conf
5./etc/rc.local
6./etc/inittab
7./etc/profile
8./etc/fstab
9./etc/issue /etc/issue.net
10./etc/motd

4./etc/resolv.conf

作用: DNS的配置文件
[root@linux ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 223.5.5.5

修改DNS配置:
[root@linux ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 223.5.5.5
nameserver 8.8.8.8

使用nslookup 查看使用哪个DNS服务器做的域名解析
[root@linux ~]# nslookup www.qq.com
Server:		114.114.114.114
Address:	114.114.114.114#53

Non-authoritative answer:
www.qq.com	canonical name = ins-r23tsuuf.ias.tencent-cloud.net.
Name:	ins-r23tsuuf.ias.tencent-cloud.net
Address: 221.198.70.47
Name:	ins-r23tsuuf.ias.tencent-cloud.net
Address: 2408:8711:10:1002::19
Name:	ins-r23tsuuf.ias.tencent-cloud.net
Address: 2408:8711:10:1003::30


特点:
1.resolv.conf中修改后直接生效
2.配置网卡的时候必须配置DNS
[root@linux ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=10.0.0.200
PREFIX=24
GATEWAY=10.0.0.2
DNS1=223.5.5.5				# 必须配置,会覆盖/etc/resolv.conf
3.如果网卡中没有DNS,手动配置resolv.conf,重启网卡不会覆盖resolv.conf.



centos ubuntu系统 麒麟
centos和麒麟相同 ubuntu网卡配置不同	# 后面讲如何自动切换到root
oldboy@oldboy-lnb:~$ sudo su -		# ubuntu切换到root管理员账号
[sudo] password for oldboy: 		# 输入的是oldboy普通账号的密码 1
root@oldboy-lnb:~#
root@oldboy-lnb:~# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      addresses:
      - 10.0.0.201/24
      nameservers:
        addresses:
        - 223.5.5.5
        search: []
      routes:
      - to: default
        via: 10.0.0.2
  version: 2


5./etc/rc.local
作用: 开机自动执行里面的命令。
注意: rc.local是一个软链接(windows的快捷方式)
[root@linux ~]# ll /etc/rc.local 	    # 快捷方式
lrwxrwxrwx 1 root root 13 Apr 20  2022 /etc/rc.local -> rc.d/rc.local
[root@linux ~]# ll /etc/rc.d/rc.local   # 源文件位置
-rw-r--r-- 1 root root 473 Apr 20  2022 /etc/rc.d/rc.local

案例.开机在/root创建rc.txt文件
第一步: 编辑/etc/rc.local
[root@linux ~]#vim /etc/rc.local
第二步: 写入命令
到最后一行写入
touch /root/rc.txt

第三步: 保持退出
:wq
补充:
:wq 保持并退出
:q  退出(没有做任何操作)
:q! 强制退出不保存
:wq! 强制保存并退出


第四步: 给源文件执行权限x		执行1次就可以了。
[root@linux ~]# ll /etc/rc.d/rc.local
-rw-r--r-- 1 root root 494 Jul  3 19:27 /etc/rc.d/rc.local
[root@linux ~]# chmod +x /etc/rc.d/rc.local
[root@linux ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 494 Jul  3 19:27 /etc/rc.d/rc.local

第五步: 重启系统查看结果
[root@linux ~]# reboot
[root@linux ~]# ll
total 0
-rw-r--r-- 1 root root 0 Jul  3 19:33 rc.txt
6./etc/inittab
作用: 配置开机自动运行级别 (面试题/笔试题)
Linux操作系统7个运行级别。每个级别表示不同的功能。
0   # 表示系统关机
1   # 表示单用户模式,如果忘记密码,通过单用户模式找回修改
2   # 表示多用户模式,不支持NFS。
3   # 表示完全多用户,默认我们使用的3级别
4   # 保留待开发
5   # 桌面模式(企业系统不安装桌面)
6   # 表示系统重启
7./etc/profile
作用: 永久存放环境变量的配置文件。
什么是变量:
[root@linux ~]# name=oldboy
[root@linux ~]# echo $name
oldboy
[root@linux ~]# mkdir $name
[root@linux ~]# ll
total 0
drwxr-xr-x 2 root root 6 Jul  3 20:16 oldboy

演示:
[root@linux ~]# dir=/etc/sysconfig/network-scripts/
[root@linux ~]# cd $dir
[root@linux network-scripts]# pwd
/etc/sysconfig/network-scripts



系统中存在的变量: PATH路径变量
PATH中存放着命令的执行路径。
[root@linux ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin


which查看命令的绝对路径:
[root@linux ~]# which touch
/usr/bin/touch
[root@linux ~]# which aaaaa
which: no aaaaa in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)



Linux命令执行流程:
第一步: 在命令行输入touch 1.txt
第二步: 系统查找PATH变量中所有的路径下有没有touch这个命令,如果存在则执行
	   如果没有在PATH变量中的路径下,则系统提示command not Found
	   [root@linux ~]# aaaaa
	   -bash: aaaaa: command not found

演示PATH变量
1.将touch命令移动到/opt目录下
[root@linux ~]# mv /usr/bin/touch /opt/

2.执行touch命令
[root@linux ~]# touch a.txt
-bash: /usr/bin/touch: No such file or directory

3.解决不能执行touch命令方法
方法1: 使用绝对路径执行touch
[root@linux ~]# /opt/touch a.txt

方法2: 重新定义PATH变量,将/opt路径加入进去
查看原来的PATH内容
[root@linux ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
将/opt目录添加到PATH变量中
[root@linux ~]# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/opt/
[root@linux ~]# touch hehe.txt


永久生效方法:
1.将PATH变量写入/etc/profile
vim /etc/profile
写到文件的末尾
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/opt/
2.让配置文件生效方法
方法1.重新连接xshell 重启系统  重点。
方法2.使用source /etc/profile 直接生效  . /etc/profile  了解

练习完成后修改回原样:
[root@linux ~]# mv /opt/touch /usr/bin/

8./etc/fstab
作用: 开机自动挂载
系统挂载cdrom 光驱
第一步: 将cdrom连接到虚拟机

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

第二步: 在系统中查看cdrom 在系统中显示的
[root@linux ~]# ll /dev/cdrom
lrwxrwxrwx 1 root root 3 Jul  3 20:11 /dev/cdrom -> sr0


第三步: 给cdrom开一个门(将cdrom挂载到系统中的/mnt目录)
通过/mnt目录实际访问的是cdrom
[root@linux ~]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.


第四步: 查看cdrom中的文件
[root@linux ~]# cd /mnt/
[root@linux mnt]# ll
total 544
dr-xr-xr-x 3 root root   2048 Mar 15  2023 EFI
dr-xr-xr-x 3 root root   2048 Mar 15  2023 images
dr-xr-xr-x 2 root root   2048 Mar 15  2023 isolinux
dr-xr-xr-x 5 root root   2048 Mar 24  2023 kylin-sm-package
-r--r--r-- 1 root root    441 Mar 31  2023 LICENSE
dr-xr-xr-x 2 root root   2048 Mar 15  2023 manual
dr-xr-xr-x 2 root root 538624 Mar 24  2023 Packages
dr-xr-xr-x 2 root root   4096 Mar 24  2023 repodata
-r--r--r-- 1 root root   2883 Mar 31  2023 TRANS.TBL

查看是否挂载成功:
[root@linux ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               963M     0  963M   0% /dev
tmpfs                  979M     0  979M   0% /dev/shm
tmpfs                  979M  8.9M  970M   1% /run
tmpfs                  979M     0  979M   0% /sys/fs/cgroup
/dev/mapper/klas-root   47G  3.7G   44G   8% /
tmpfs                  979M     0  979M   0% /tmp
/dev/sda1             1014M  169M  846M  17% /boot
tmpfs                  196M     0  196M   0% /run/user/0
/dev/sr0               4.3G  4.3G     0 100% /mnt			#挂载成功

卸载cdrom使用,卸载的时候出门后在卸载。
[root@linux ~]# umount /mnt

如果不退出,会提示: target is busy
[root@linux ~]# cd /mnt/
[root@linux mnt]# umount /mnt
umount: /mnt: target is busy.
[root@linux mnt]# cd


查看硬件的类型:
[root@linux ~]# blkid
/dev/mapper/klas-swap: UUID="deddfd66-1a7d-4653-b97b-0e0f8933f51b" TYPE="swap"
/dev/sr0: BLOCK_SIZE="2048" UUID="2023-03-31-21-06-57-00" LABEL="Kylin-Server-10" TYPE="iso9660"
/dev/mapper/klas-root: UUID="09db8ffd-281e-4bff-aa49-14f6f656a459" BLOCK_SIZE="512" TYPE="xfs"
/dev/sda2: UUID="lqyH0s-0kKa-fs7G-kpGh-1sdk-RbLE-GNzXmh" TYPE="LVM2_member" PARTUUID="9a148942-02"
/dev/sda1: UUID="2b4ae922-aa11-4f08-b98a-e99355d21546" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="9a148942-01"


写入开机自动挂载: /etc/fstab  (笔试题)
vim /etc/fstab
...
/dev/cdrom              /mnt                    iso9660 defaults 0 0
第一列: 设备的名称
第二列: 挂载点
第三列: 文件类型
第四列: 挂载的参数默认 defaults
第五列: 0 是否备份
第六列: 0 是否开机自动检查

知识点小结:

1.resolv.conf
  配置DNS
vim /etc/resolv.conf
nameserver 223.5.5.5
nameserver 114.114.114.114
 和网卡关系
2.rc.local 开机自动运行 需要给源文件执行x权限
3.inittab linux运行级别
0
1
2
3
4
5
6
4./etc/profile
PATH变量
命令执行流程
5./etc/fstab
练习挂载cdrom
将cdrom写入/etc/fstab 开机自动挂载
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值