码迷,mamicode.com
首页 > 系统相关 > 详细

Linux系统重要文件

时间:2019-12-05 17:16:08      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:nbsp   ttl   ldo   运行   parallel   x86_64   必须   阿里云   exec   

 

 

 

 

 

 

 


 

 

 

 

 

Linux系统重要文件介绍与配置

 

 

一网卡配置文件

 

(一)网卡配置文件参数介绍

 


文件路径信息:/ec/sysconfig/network-scripts/ifcfg-eth0

文件作用说明:配置网卡地址信息(IP地址掩码地址网关地址DNS地址信息)

[root@centos7 ~]# cat    /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=9d9e2656-f3ac-4f75-8722-3136d239985d
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.200
PREFIX=24
GATEWAY=10.0.0.254
IPV6_PRIVACY=no
DNS1=223.5.5.5

 

 

 

 

 

 

TYPE=Ethernet   指定网络类型——以太网类型

3G、4G、5G--人工智能自动驾驶

DEFROUTE=yes---是否激活默认路由(网络知识会说)

NAME=eth0---网卡名称信息,逻辑名称
DEVICE=eth0--网卡名称信息,设备名称

UUID=9d9e2656-f3ac-4f75-8722-3136d239985d    eth0网卡设备编号

逻辑名称和设备名称的区别?

 

 

 

 

 

 

快速修改IP地址

[root@centos7 ~]# sed -i   s/200/201/g   /etc/sysconfig/network-scripts/ifcfg-eth0
[root@centos7 ~]# cat    /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=9d9e2656-f3ac-4f75-8722-3136d239985d
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.201
PREFIX=24
GATEWAY=10.0.0.254
IPV6_PRIVACY=no
DNS1=223.5.5.5
[root@centos7 ~]# service  network  restart 
Restarting network (via systemctl):  

 

 

 

 

 

 

(二)网卡配置文件生效


方法一:利用systemctl命令   systemctl restart network    企业环境不建议  

方法二:利用service命令       service network restart   企业环境不建议

方法三:利用ifxx命令,指定网卡重启          ifdown eth0   &&   ifup eth0  企业环境配置,建议使用

 

 

 

 

 

(三)修改网卡名称信息

 

(1)修改网卡文件中名称信息


vi ifcfg-ens33
NAME=eth0
DEVICE=etho

[root@centos72 ~]# sed -i  s/ens33/eth0/g  /etc/sysconfig/network-scripts/ifcfg-ens33 
[root@centos72 ~]# cat  /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=faef9329-c9bb-4ba8-84d9-853c3409bb2e
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.72
GATEWAY=10.0.0.1
NETMASK=255.255.255.0
DNS1=223.5.5.5
DNS2=8.8.8.8

 

 

 

 

 

(2)网卡文件名称重命名

[root@centos72 ~]# mv  /etc/sysconfig/network-scripts/ifcfg-ens33  /etc/sysconfig/network-scripts/ifcfg-eth0

 

 

 

 

 

(3)让系统内核加载网卡名称修改信息

 

[root@centos72 ~]#vim  /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed ‘s, release .*$,,g‘ /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rhgb quiet  net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
~                                                                                                       
"/etc/default/grub" 7L, 247C written                                                  
[root@centos72 ~]# cat    /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed ‘s, release .*$,,g‘ /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rhgb quiet  net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"

 

 

 

 

 

 

 

(4)加载修改配置信息


 grub2-mkconfig   -o     /boot/grub2/grub.cfg

[root@centos72 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1062.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-cb26ac281315402a9928e9a4c3bedfcd
Found initrd image: /boot/initramfs-0-rescue-cb26ac281315402a9928e9a4c3bedfcd.img
done

 

 

 

 

 

 

(5)重启操作系统


reboot   

[root@centos72 ~]# reboot 

Connection closed by foreign host.

Disconnected from remote host(10.0.0.72:22) at 11:23:14.

Type `help to learn how to use Xshell prompt.

[c:\~]$ ssh  10.0.0.72


Connecting to 10.0.0.72:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Mon Dec  2 11:15:23 2019 from 10.0.0.1
[root@centos72 ~]# mv  /etc/sysconfig/network-scripts/ifcfg-ens33  /etc/sysconfig/network-scripts/ifcfg-eth0^C
[root@centos72 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:fc:69:f8 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.72/24 brd 10.0.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::6a03:a879:3759:698a/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

 

 

 

 

 

 

 

二域名服务配置文件


文件路径信息:/etc/resolv.conf
文件作用说明:访问名称或者域名信息

vi  /etc/resolv.conf
nameserver 223.5.5.5(DNS服务器地址)
PS:DNS服务器将域名解析成IP地址

223.5.5.5              阿里云公司
114.114.114.114   电信公司

[root@centos7 ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
search com
nameserver 223.5.5.5

 

 

 

 

注意我在北方,所以不能ping通114.114.114.114

[root@centos7 ~]# ping   114.114.114.114
PING 114.114.114.114 (114.114.114.114) 56(84) bytes of data.
^C
--- 114.114.114.114 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 2999ms

[root@centos7 ~]# ping   223.5.5.5
PING 223.5.5.5 (223.5.5.5) 56(84) bytes of data.
64 bytes from 223.5.5.5: icmp_seq=1 ttl=128 time=58.8 ms
64 bytes from 223.5.5.5: icmp_seq=2 ttl=128 time=58.3 ms
64 bytes from 223.5.5.5: icmp_seq=3 ttl=128 time=56.9 ms
^C
--- 223.5.5.5 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 56.928/58.057/58.856/0.820 ms

 

 

 

 

 

 

 

三本地域名解析文件

 

文件路径信息:/etc/hosts
文件作用说明:实现本地名称解析(用于访问不同服务器)用于网站测试

web服务器、数据库服务器、存储服务器、监控服务器、日志服务器、备份服务器、审计服务器、缓存服务器器

相当于公司的各个职位:销售、行政、运营

上面在架构里面出现,需要通过网络进行交流

[root@centos7 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

 

 

 

 

web服务器——网络——数据库服务器192.173.16.122 dbe1,  存储服务器187.169.45.231 date01,监控服务器177 187 56 937abbix01
           

   

注意本地的域名解析优先级更高     

[root@centos7 ~]# ip  a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:ea:b8:14 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::951a:d6ce:9fbd:c7b7/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

 

 

 

 

[root@centos7 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.200   www.baidu.com

 

 

 

 

[root@centos7 ~]# ping   www.baidu.com
PING www.baidu.com (10.0.0.200) 56(84) bytes of data.
64 bytes from www.baidu.com (10.0.0.200): icmp_seq=1 ttl=64 time=0.058 ms
64 bytes from www.baidu.com (10.0.0.200): icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from www.baidu.com (10.0.0.200): icmp_seq=3 ttl=64 time=0.042 ms
^C
--- www.baidu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.040/0.046/0.058/0.011 ms

 

 

 

 

 

 

 

 

 

 

四开机自动运行命令文件

 

 

文件路径信息:/etc/rc.local

文件作用:让系统启动后,自动运行命令信息文件内容信息:#!/bin/bash脚本文件


PS:确认/etc/rc.d/rc.local文件必须有执行权限

chmod +x   /etc/rc.d/rc.local

脚本文件:将复杂工作简单化将重复工作高效化堆命令文件脚本文件如何执行:

 


方法一:
sh   脚本文件.sh

方法二:

必须确认脚本文件有执行权限

x--execute脚本文件.sh

需求:系统启动好

文件内容信息:
1)将重要数据做好初始备份
2)系统启动好自动清除回收站数据

3)实现自动存储设备挂载

 

 

 

 

 

 

 

技术图片

 

 

 

 

 

[root@centos7 ~]# ll    /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Nov 26 17:33 /etc/rc.local -> rc.d/rc.local
[root@centos7 ~]# ll  rc.d/rc.local
ls: cannot access rc.d/rc.local: No such file or directory
[root@centos7 ~]# ll  /root/rc.d/rc.local
ls: cannot access /root/rc.d/rc.local: No such file or directory
[root@centos7 ~]# ll  /etc/rc.d/rc.local
-rw-r--r--. 1 root root 579 Dec  2 12:39 /etc/rc.d/rc.local
[root@centos7 ~]# chmod  +x  /etc/rc.d/rc.local
[root@centos7 ~]# ll  /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 579 Dec  2 12:39 /etc/rc.d/rc.local

 

 

 

 

 

[root@centos7 ~]# cat  /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run chmod +x /etc/rc.d/rc.local to ensure
# that this script will be executed during boot.
mkdir  -p  /backup
cp  /etc/hosts   /backup
rm  -rf  /tmp/*
mount /dev/cdrom /mnt
touch /var/lock/subsys/local

 

 

 

 

 

 

Linux系统重要文件

标签:nbsp   ttl   ldo   运行   parallel   x86_64   必须   阿里云   exec   

原文地址:https://www.cnblogs.com/wang618/p/11974597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!