跳到主要内容
方的代码随记
返回

/etc 常用配置文件详解

更新于:

一、/etc/fstab —— 开机自动挂载

#
# /etc/fstab
# Created by anaconda on Fri Aug  5 15:14:21 2022
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=61d529c8-a942-4f8b-bd7c-c2a7506eaa2e /boot     ext4    defaults        1 2
/dev/mapper/VolGroup-lv_home /home                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0

二、/etc/exports —— NFS 共享

/public *(ro)    # 将 /public 只读共享给所有用户
/opt   *(ro)     # 将 /opt 只读共享给所有用户

三、/etc/auto.master —— 触发挂载主配置

/misc   /etc/auto.misc
/mysssrauto      /opt/ssr.txt
/net    -hosts
+dir:/etc/auto.master.d
+auto.master

格式为 mount-point [map-type[,format]:]map [options],详见 auto.master(5)。

四、/etc/yum.repos.d/ —— yum 源目录

以 centos7.repo 为例:

[centos-kernel]
name=CentOS LTS Kernels for $basearch
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=kernel&infra=$infra
#baseurl=http://mirror.centos.org/altarch/7/kernel/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[centos-kernel-experimental]
name=CentOS Experimental Kernels for $basearch
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=experimental&infra=$infra
#baseurl=http://mirror.centos.org/altarch/7/experimental/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

五、/etc/hosts —— 本地 DNS 解析(优先级高于 DNS)

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

六、/etc/httpd/conf/httpd.conf —— HTTP 主配置

/etc/httpd/conf.d/*.conf    # httpd 调用的配置文件

七、/etc/named.conf —— 负责解析的域名(DNS 服务)

options {
        directory       "/var/named";
        allow-transfer  { 192.168.4.207; };
};
zone "tedu.cn" IN {
        type master;
        file "tedu.cn.zone";
};
zone "lol.com" IN {
        type master;
        file "lol.com.zone";
};

八、/etc/resolv.conf —— DNS 域名解析

# Generated by NetworkManager
search localdomain
nameserver 10.211.55.1

九、/etc/dhcp/dhcpd.conf —— DHCP 服务

subnet 192.168.4.0 netmask 255.255.255.0 {
  range 192.168.4.100  192.168.4.200;
  option domain-name-servers 192.168.4.7;
  option routers 192.168.4.254;
  default-lease-time 600;
  max-lease-time 7200;
}

十、/etc/chrony.conf —— NTP 时间服务

server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
logdir /var/log/chrony

十一、网卡配置 —— /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"
IPV6INIT="yes"
BOOTPROTO="dhcp"
UUID="aa318344-f954-47c3-9483-51faf166e551"
ONBOOT="yes"

十二、/etc/shells —— 系统可用 shell

/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/bin/tcsh
/bin/csh

十三、/etc/rc.d/rc.local —— 开机自启动脚本

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

追加一行即可实现开机启动,例如:

echo '/usr/local/nginx/sbin/nginx' >> /etc/rc.d/rc.local

十四、/etc/sudoers —— 提权配置

必须用 visudo 编辑。核心片段:

## Allow root to run any commands anywhere
root    ALL=(ALL)   ALL

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)   ALL

## Same thing without a password
# %wheel ALL=(ALL)  NOPASSWD: ALL

## Read drop-in files from /etc/sudoers.d
#includedir /etc/sudoers.d

分享这篇文章:

上一篇
搭建 File Browser 文件管理系统
下一篇
/etc/profile 环境变量模板