1: 網卡的配置文件 [ 同樣可以使用命令setup來執行網卡參數 2: DNS文件 註:網卡的配置文件裡面如果配置了DNS,它的優先順序是高於這個配置文件的。 3: hosts文件 /etc/hosts 用戶IP與名稱(功能變數名稱)的對應解析的配置文件 在實際的生產環境中很有用(一般所有的內網機器host ...
1: 網卡的配置文件
[
root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #網卡設備名稱
HWADDR=00:0C:29:26:96:BD #MAC地址 TYPE=Ethernet #乙太網 UUID=e982e20a-e7ef-4246-8e44-a7c0c474c708 #Linux系統內部的標識,唯一 ONBOOT=yes #開機啟動 NM_CONTROLLED=yes #BOOTPROTO=dhclient BOOTPROTO=static #引導協議,一般為static(靜態),dhclient(自動獲取) IPADDR=192.168.126.128 #IP地址
NETMASK=255.255.255.0 #子網掩碼 GATEWAY=192.168.126.2 #網關 DNS=111.13.148.14
同樣可以使用命令setup來執行網卡參數
2: DNS文件
[root@localhost ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-script search localdomain nameserver 192.168.126.2
註:網卡的配置文件裡面如果配置了DNS,它的優先順序是高於這個配置文件的。
3: hosts文件
/etc/hosts 用戶IP與名稱(功能變數名稱)的對應解析的配置文件
在實際的生產環境中很有用(一般所有的內網機器hosts文件都保持一致),主要用於伺服器遷移
[root@centos6 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.197.100 centos6.6 [root@centos6 ~]# hostname centos6.6 [root@centos6 ~]# ping centos6.6 PING centos6.6 (192.168.197.100) 56(84) bytes of data. 64 bytes from centos6.6 (192.168.197.100): icmp_seq=1 ttl=64 time=0.051 ms 64 bytes from centos6.6 (192.168.197.100): icmp_seq=2 ttl=64 time=0.047 ms 64 bytes from centos6.6 (192.168.197.100): icmp_seq=3 ttl=64 time=0.047 ms ^C -- centos6.6 ping statistics -- 3 packets transmitted, 3 received, 0% packet loss, time 2867ms rtt min/avg/max/mdev = 0.047/0.048/0.051/0.006 ms
實際生產環境的作用:
1. 開發、產品、測試人員用於通過正式的功能變數名稱來測試產品
2. 伺服器之間調用可以用功能變數名稱,方便以後的遷移(各程式之間調用功能變數名稱,機房遷移之後只需修改相應的hosts文件即可)
4: 主機名文件
/etc/sysconfig/network 修改機器名及網卡啟動、網關配置文件
修改上述的HOSTNAME永久生效(修改主機名)
5: fstab文件
/etc/fstab 記錄開機要掛載的文件系統文件
開機自動掛載磁碟,設置文件系統掛載信息的文件
文件信息一共包含六列(具體解析可 man fstab 查看)
第一列: 被掛載的設備名稱
第二列: 掛載點位置
第三列: 文件系統類型
第四列: 掛載選項(只讀、可寫、其他等等)
第五列: 需不需要備份(0就是不備份)
第六列: 需不需要開機檢查(0就是不需要,需要設置為1)
6: /etc/rc.local文件
存放開機自啟動服務命令(同於windows裡面的開始菜單中啟動菜單)
可以將命令直接寫入到配置文件的末行
註: 實際生產環境中,一般服務開機自啟動都會寫入這個配置文件裡面,這樣只需要查看此配置文件就可以得知伺服器運行哪些服務。
7: inittab文件
/etc/inittab 設定系統啟動時init進程將把系統設置成什麼樣的運行級別及加相關的啟動文件配置的文件
[root@localhost ~]# cat /etc/inittab # inittab is only used by upstart for the default runlevel. #只被用於突然發起的預設運行級別 # # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # System initialization is started by /etc/init/rcS.conf # # Individual runlevels are started by /etc/init/rc.conf # # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf # # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, # with configuration in /etc/sysconfig/init. # # For information on how to write upstart event handlers, or how # upstart works, see init(5), init(8), and initctl(8). # # Default runlevel. The runlevels used are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:3:initdefault:
註: linux開機啟動流程如下:
開機自檢----MBR引導程式-----GRUB菜單----載入內核----運行init進程----讀取/etc/inittab配置文件----執行/etc/rc.d/rc.sysinit腳本----執行/etc/rc.local腳本(讀取運行級別)----啟動終端登錄進程----登錄系統
8: 軟體啟動服務文件
/etc/init.d 安裝的軟體啟動服務(系統的啟動服務)所在目錄
使用yum、rpm安裝的軟體啟動程式都在這個目錄下
9: 全局環境變數文件
/etc/profile 系統全局變數的配置文件
[root@localhost init.d]# cat /etc/profile # /etc/profile # System wide environment and startup programs, for login setup #系統全局變數和啟動程式 # Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you #除非你知道你要做什麼,否則不要更改 # are doing. It's much better to create a custom.sh shell script in #更好的是去創建腳本在/etc/profile.d,去改變 # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates. pathmunge () { case ":${PATH}:" in *:"$1":*) ;; *) if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi esac } if [ -x /usr/bin/id ]; then if [ -z "$EUID" ]; then # ksh workaround EUID=`id -u` UID=`id -ru` fi USER="`id -un`" LOGNAME=$USER MAIL="/var/spool/mail/$USER" fi # Path manipulation if [ "$EUID" = "0" ]; then pathmunge /sbin pathmunge /usr/sbin pathmunge /usr/local/sbin else pathmunge /usr/local/sbin after pathmunge /usr/sbin after pathmunge /sbin after fi HOSTNAME=`/bin/hostname 2>/dev/null` HISTSIZE=1000 if [ "$HISTCONTROL" = "ignorespace" ] ; then export HISTCONTROL=ignoreboth else export HISTCONTROL=ignoredups fi export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL # By default, we want umask to get set. This sets it for login shell # Current threshold for system reserved uid/gids is 200 # You could check uidgid reservation validity in # /usr/share/doc/setup-*/uidgid file if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then umask 002 else umask 022 fi for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null 2>&1 fi fi done unset i unset -f pathmunge export TMOUT=300 HISTSIZE=50 HISTFILESIZE=50
與之關聯的還有一個文件/etc/profile.d,可以存放登錄後自動執行的腳本
[root@centos6 ~]# cd /etc/profile.d/ [root@centos6 profile.d]# vi welcome.sh echo "welcome to mingongge's blog" [root@centos6 profile.d]# chmod +x welcome.sh [root@centos6 profile.d]# logout Last login: Thu Dec 22 13:51:55 2016 from 192.168.197.1 welcome to mingongge's blog
10: motd文件
/etc/motd 用戶登錄提示信息
編輯過後,再登錄就顯示自己編輯的文本。
11: group文件
/etc/group 用戶的組名與相關信息
12: 用戶賬號相關信息
/etc/passwd 系統所有用戶賬號信息文件
13: 用戶密碼相關文件
/etc/shadow 系統所有用戶密碼信息文件
/etc/gshadow 系統所有組密碼信息文件
14: 系統信息文件
/var/log/messages 系統日誌文件
/var/log/secure 登陸系統存取信息文件(系統安全日誌文件)
15: 定時任務配置文件
/var/spool/cron/ 定時任務配置文件
DESCRIPTION Crontab is the program used to install, remove or list the tables #crontab是程式用來安裝,移除或者列出一個表去驅動cron進程。 used to drive the cron(8) daemon. Each user can have their own crontab, and though these are files in /var/spool/ , they are not #這些定時文件到在/var/spool/cron下 intended to be edited directly. For SELinux in mls mode can be even more crontabs - for each range. For more see selinux(8). The cron jobs could be allow or disallow for different users. For classical crontab there exists cron.allow and cron.deny files. If cron.allow file exists, then you must be listed therein in order to be allowed to use this command. If the cron.allow file does not exist but the cron.deny file does exist, then you must not be listed in the cron.deny file in order to use this command. If nei- ther of these files exists, only the super user will be allowed to use this command. The second option is using PAM authentication, where you set up users, which could or couldn’t use crontab and also system cron jobs from /etc/cron.d/. The temporary directory could be set in enviroment variables. If it’s not set by user than /tmp is used.