常见配置文件
系统配置文件
/etc/passwd - 用户账户信息
# 格式: 用户名:密码占位符:UID:GID:描述:家目录:Shell
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
/etc/shadow - 用户密码信息
# 格式: 用户名:加密密码:最后修改:最小天数:最大天数:警告:不活动:过期:保留
root:$6$hash...:18600:0:99999:7:::
/etc/group - 组账户信息
# 格式: 组名:密码:GID:组成员列表
root:x:0:
sudo:x:27:user1,user2
/etc/hosts - 主机名解析
127.0.0.1 localhost
127.0.1.1 myhost
192.168.1.100 server1
::1 localhost ip6-localhost ip6-loopback
/etc/hostname - 主机名
myhost
/etc/resolv.conf - DNS配置
nameserver 8.8.8.8
nameserver 114.114.114.114
search example.com
options timeout:2 attempts:3
/etc/fstab - 文件系统挂载表
# <设备> <挂载点> <类型> <选项> <dump> <fsck>
UUID=xxx-xxx / ext4 defaults 0 1
UUID=xxx-xxx /home ext4 defaults 0 2
UUID=xxx-xxx swap swap defaults 0 0
tmpfs /tmp tmpfs defaults,noatime 0 0
/etc/sysctl.conf - 内核参数
# 网络优化
net.core.somaxconn = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
# 内存优化
vm.swappiness = 10
vm.dirty_ratio = 20
# 安全设置
net.ipv4.conf.all.accept_redirects = 0
服务配置文件
/etc/ssh/sshd_config - SSH服务配置
Port 22
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
ClientAliveInterval 300
/etc/nginx/nginx.conf - Nginx配置
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
include /etc/nginx/sites-enabled/*;
}/etc/mysql/my.cnf - MySQL配置
[mysqld]
port = 3306
bind-address = 0.0.0.0
max_connections = 200
innodb_buffer_pool_size = 1G
character-set-server = utf8mb4/etc/systemd/system/xxx.service - Systemd服务
[Unit]
Description=My Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/myapp
Restart=on-failure
[Install]
WantedBy=multi-user.target用户配置文件
~/.bashrc - Bash配置
# 别名
alias ll='ls -la'
alias grep='grep --color=auto'
# 环境变量
export PATH=$PATH:/usr/local/bin
export EDITOR=vim
# 函数
mkcd() {
mkdir -p "$1" && cd "$1"
}~/.bash_profile - 登录Shell配置
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
# PATH设置
export PATH=$HOME/bin:$PATH~/.ssh/config - SSH客户端配置
Host myserver
HostName 192.168.1.100
User admin
Port 22
IdentityFile ~/.ssh/id_rsa
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
~/.vimrc - Vim配置
" 基础设置
set nocompatible
set encoding=utf-8
set number
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
" 搜索设置
set incsearch
set hlsearch
set ignorecase
set smartcase
" 显示设置
set cursorline
set showmatch
set ruler
set showcmd日志文件位置
| 文件路径 | 说明 |
|---|---|
/var/log/messages | 系统主日志(RHEL/CentOS) |
/var/log/syslog | 系统主日志(Debian/Ubuntu) |
/var/log/auth.log | 认证日志 |
/var/log/kern.log | 内核日志 |
/var/log/dmesg | 启动日志 |
/var/log/nginx/ | Nginx日志目录 |
/var/log/mysql/ | MySQL日志目录 |
/var/log/apt/ | APT日志目录 |
/var/log/yum.log | YUM日志 |
/var/log/cron | Cron日志 |
/var/log/maillog | 邮件日志 |
/var/log/secure | 安全日志(RHEL/CentOS) |
环境变量文件
| 文件 | 说明 | 加载时机 |
|---|---|---|
/etc/environment | 系统环境变量 | 所有进程 |
/etc/profile | 系统登录配置 | 登录时 |
/etc/profile.d/*.sh | 系统登录脚本 | 登录时 |
~/.bash_profile | 用户登录配置 | 登录时 |
~/.bashrc | 用户Shell配置 | 打开Shell时 |
~/.profile | 用户通用配置 | 登录时 |
网络配置文件
/etc/network/interfaces(Debian旧版)
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8
/etc/sysconfig/network-scripts/ifcfg-eth0(RHEL/CentOS)
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
/etc/netplan/*.yaml(Ubuntu新版)
network:
version: 2
ethernets:
eth0:
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 114.114.114.114安全配置文件
/etc/sudoers - sudo配置
# 用户规范格式: 用户 主机=(运行身份) 命令
root ALL=(ALL:ALL) ALL
%wheel ALL=(ALL) ALL
username ALL=(ALL) NOPASSWD: /usr/bin/systemctl
/etc/hosts.allow 和 /etc/hosts.deny - TCP Wrappers
# hosts.allow
sshd: 192.168.1.0/255.255.255.0
ALL: localhost
# hosts.deny
sshd: ALL
/etc/limits.conf - 资源限制
# 格式: <domain> <type> <item> <value>
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
root soft nofile 655350
💡 提示: 修改配置文件后,通常需要重启服务或重新加载配置
🔗 相关笔记: 02.03_系统管理 99.01_常用命令速查表