当前位置:首页>Linux>【第23期】Linux系统初始化脚本:从裸机到生产级的一键方案

【第23期】Linux系统初始化脚本:从裸机到生产级的一键方案

  • 2026-06-30 23:17:32
【第23期】Linux系统初始化脚本:从裸机到生产级的一键方案

做运维这么多年,我见过太多这样的场景:新服务器到货,上架装好系统,丢那儿就不管了。等到业务跑上去,三天两头出状况——SSH被爆破、OOM被杀进程、磁盘写满没人管、连接数爆了服务直接挂。回过头一问:系统装完之后,你做了什么初始化?对方一脸茫然:装完不就用了么?

这就是问题所在。一个裸装的 Linux 系统,说白了就是一间毛坯房——能住人,但住得不舒服,也不安全。今天这篇,我就把这套压箱底的初始化脚本完整分享出来。从安全加固到性能调优,再到常用软件的自动化部署,一键跑完,你的系统就直接达到生产标准。

适用范围:CentOS 7/8/9、Rocky Linux、AlmaLinux、Ubuntu 20.04/22.04/24.04、Debian 11/12。脚本里会自动识别发行版,不用你操心。

一、安全加固:别让服务器裸奔

安全这事儿,怎么强调都不为过。我见过一台新服务器,从装好系统到被黑客拿下,只用了不到48小时。攻击者扫到了默认22端口,用弱口令字典暴力破解,进去之后直接装了挖矿程序。等我们发现的时候,CPU已经满载跑了一个星期。

所以第一步,先把门焊死。

1.1 SSH 加固

SSH 是服务器的第一道门,也是最容易被盯上的一扇门。默认配置下,它几乎就是在向攻击者招手:端口22、允许root登录、密码认证。改起来其实很简单:

# 备份原始配置 cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak # 修改关键参数 sed -i 's/^#\?Port 22/Port 2222/' /etc/ssh/sshd_config sed -i 's/^#\?PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config sed -i 's/^#\?PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config sed -i 's/^#\?X11Forwarding yes/X11Forwarding no/' /etc/ssh/sshd_config sed -i 's/^#\?MaxAuthTries 6/MaxAuthTries 3/' /etc/ssh/sshd_config sed -i 's/^#\?LoginGraceTime 2m/LoginGraceTime 30/' /etc/ssh/sshd_config # 追加禁止空密码 echo 'PermitEmptyPasswords no' >> /etc/ssh/sshd_config # 重启生效 systemctl restart sshd

几个要点挨个说:

改端口:把22改成2222(或者随便一个高位端口)。这不是什么高级安全手段,但能挡住90%以上的自动化扫描。那些扫22端口的脚本,可不会傻到从1扫到65535。

禁止 root 直登:这是铁律。先用普通用户登录,再 su 或 sudo 提权。就算密码泄露了,攻击者拿到的也是个低权限账号。

关闭密码认证:改用密钥登录。密钥的强度远比密码靠谱,而且丢了可以立刻吊销。

最大尝试次数:从6降到3,减少暴力破解的时间窗口。配合后面的 fail2ban,基本就把SSH爆破这条路堵死了。

1.2 配置密钥登录

禁用密码之前,得先配好密钥。不然把自己锁在外面,那可真叫一个尴尬:

# 生成密钥对(本地电脑执行) ssh-keygen -t ed25519 -C "admin@company.com" # 复制公钥到服务器 ssh-copy-id -p 2222 user@server_ip # 验证密钥登录(关闭密码认证前务必测试!) ssh -p 2222 user@server_ip

这里推荐用 ed25519 算法,比传统的 RSA 更快更安全,密钥也更短。RSA 当然也能用,但已经是上一代方案了。

1.3 防火墙配置

防火墙不是万能的,但没有防火墙是万万不能的。很多人觉得云服务器有安全组就够了,这话没错,但主机层面的防火墙是最后一道防线。安全组是云厂商层面的,万一配置出错呢?多层防御总归更靠谱。

CentOS/RHEL 系列用 firewalld,Ubuntu/Debian 用 ufw:

# CentOS/RHEL - firewalld systemctl enable firewalld systemctl start firewalld firewall-cmd --permanent --remove-service=ssh firewall-cmd --permanent --add-port=2222/tcp firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.0/8" accept' firewall-cmd --reload # Ubuntu/Debian - ufw apt install -y ufw ufw default deny incoming ufw default allow outgoing ufw allow 2222/tcp ufw allow 80/tcp ufw allow 443/tcp ufw allow from 10.0.0.0/8 ufw --force enable

这里有个很实用的技巧:允许内网段(比如 10.0.0.0/8)的全部流量。这样内网服务器之间通信不受限制,但来自外网的访问只能走开放的几个端口。

1.4 用户与权限管理

一个新系统,第一件事就是创建管理用户。永远不要用 root 跑业务,这不是建议,是规定:

# 创建管理用户 useradd -m -s /bin/bash admin # 设置强密码(16位以上,包含大小写、数字、特殊字符) passwd admin # 添加到 wheel/sudo 组 usermod -aG wheel admin        # CentOS/RHEL usermod -aG sudo admin         # Ubuntu/Debian # 配置 sudo 免密码(可选,仅限密钥登录场景) echo 'admin ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/admin chmod 440 /etc/sudoers.d/admin # 锁定不需要的系统账号 for user in games lp news uucp proxy list irc gnats; do    usermod -L $user 2>/dev/null done

密码策略也得配上。别指望用户自觉设置强密码,用 pam_pwquality 模块强制要求:

# 密码复杂度策略 echo 'minlen=12' >> /etc/security/pwquality.conf echo 'minclass=3' >> /etc/security/pwquality.conf echo 'maxrepeat=3' >> /etc/security/pwquality.conf echo 'difok=5' >> /etc/security/pwquality.conf # 密码过期策略 sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS   90/' /etc/login.defs sed -i 's/^PASS_MIN_DAYS.*/PASS_MIN_DAYS   7/' /etc/login.defs sed -i 's/^PASS_MIN_LEN.*/PASS_MIN_LEN     12/' /etc/login.defs sed -i 's/^PASS_WARN_AGE.*/PASS_WARN_AGE   14/' /etc/login.defs

minlen=12:密码最少12位

minclass=3:至少包含3种字符类型(大写、小写、数字、特殊字符)

maxrepeat=3:不允许同一个字符连续出现3次以上

difok=5:新密码必须与旧密码至少5个字符不同

PASS_MAX_DAYS=90:密码90天强制更换

1.5 安装 fail2ban

fail2ban 是个好东西。它监控日志文件,发现某个 IP 在短时间内多次认证失败,就直接把它拉进防火墙黑名单。简单、粗暴、有效:

# CentOS/RHEL yum install -y epel-release yum install -y fail2ban # Ubuntu/Debian apt install -y fail2ban # 配置 cat > /etc/fail2ban/jail.local << 'EOF' [DEFAULT] bantime = 3600 findtime = 600 maxretry = 3 banaction = firewallcmd-ipset [sshd] enabled = true port = 2222 maxretry = 3 bantime = 86400 findtime = 300 EOF systemctl enable fail2ban systemctl start fail2ban

配置里的参数含义很简单:600秒内失败3次,封禁24小时。这招对付SSH爆破特别管用,日志里能看到大量被ban的IP,心里踏实。

1.6 系统安全基线

还有一些系统级别的安全设置,不起眼但很关键:

# 禁止 Ctrl+Alt+Del 重启 systemctl mask ctrl-alt-del.target # 限制 su 命令只能被 wheel 组使用 sed -i 's/^#\?auth.*pam_wheel.so/\auth\trequired\tpam_wheel.so use_uid/' /etc/pam.d/su # 设置 umask echo 'umask 027' >> /etc/profile echo 'umask 027' >> /etc/bashrc # 锁定关键文件防止篡改 chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow # 注意:如果需要添加用户,需要先 chattr -i 解锁 # 历史命令记录增强 echo 'export HISTSIZE=10000' >> /etc/profile echo 'export HISTFILESIZE=20000' >> /etc/profile echo 'export HISTTIMEFORMAT="%F %T "' >> /etc/profile echo 'export PROMPT_COMMAND="history -a"' >> /etc/profile # 禁用不用的文件系统模块 echo 'install cramfs /bin/true' >> /etc/modprobe.d/disablefs.conf echo 'install freevxfs /bin/true' >> /etc/modprobe.d/disablefs.conf echo 'install jffs2 /bin/true' >> /etc/modprobe.d/disablefs.conf echo 'install hfs /bin/true' >> /etc/modprobe.d/disablefs.conf echo 'install hfsplus /bin/true' >> /etc/modprobe.d/disablefs.conf echo 'install squashfs /bin/true' >> /etc/modprobe.d/disablefs.conf echo 'install udf /bin/true' >> /etc/modprobe.d/disablefs.conf

那个 chattr +i 要注意,锁定之后连 root 都不能修改这些文件。需要添加用户的时候,记得先 chattr -i 解锁,改完再锁回去。我一开始用这个功能的时候,就把自己坑过好几次。

二、内核参数调优:让系统跑得更快更稳

安全搞定了,接下来是性能。Linux 内核的参数默认值偏向保守,什么场景都能用,但什么场景都不是最优。调优的核心思路就一条:根据实际业务需求,把系统资源的利用效率拉到最高。

所有内核参数都写在 /etc/sysctl.conf 里,一条 sysctl -p 就能生效。下面是我经过多次实战打磨后的参数组合:

cat >> /etc/sysctl.conf << 'EOF' # ===== 网络优化 ===== # 开启SYN Cookie,防止SYN洪水攻击 net.ipv4.tcp_syncookies = 1 # SYN队列大小,默认128太小,调到1024 net.ipv4.tcp_max_syn_backlog = 1024 # 已建立连接队列 net.core.somaxconn = 2048 # TIME_WAIT状态的连接最大数量 net.ipv4.tcp_max_tw_buckets = 6000 # 快速回收TIME_WAIT连接(NAT环境下不建议开启) net.ipv4.tcp_tw_recycle = 0 # 允许重用TIME_WAIT连接 net.ipv4.tcp_tw_reuse = 1 # TCP keepalive时间,默认7200秒太长,改为600秒 net.ipv4.tcp_keepalive_time = 600 net.ipv4.tcp_keepalive_intvl = 30 net.ipv4.tcp_keepalive_probes = 5 # 启用TCP快速打开 net.ipv4.tcp_fastopen = 3 # 连接跟踪表大小(根据内存调整,公式:CONNTRACK_SIZE=内存GB*200000) net.netfilter.nf_conntrack_max = 655360 # 本地端口范围,默认32768-60999太窄 net.ipv4.ip_local_port_range = 1024 65535 # ===== 内存优化 ===== # 减少swap使用倾向(0=尽量不用,100=积极使用) vm.swappiness = 10 # 允许超量分配内存 vm.overcommit_memory = 1 # 内存溢出时杀死进程的策略 vm.overcommit_ratio = 90 # OOM时保护系统进程 vm.panic_on_oom = 0 # ===== 文件系统优化 ===== # 单进程最大文件打开数 fs.file-max = 1048576 # inode缓存最大数量 fs.inotify.max_user_watches = 524288 # ===== 其他 ===== # 核心转储 kernel.core_pattern = /var/crash/core-%e-%p-%t # 禁止普通用户访问内核日志 kernel.dmesg_restrict = 1 # 限制ptrace(防止进程调试注入) kernel.yama.ptrace_scope = 1 EOF sysctl -p

挑几个重点参数解释一下:

net.core.somaxconn = 2048:这个参数控制每个监听端口能排队的最大连接数。默认128在高并发场景下根本不够用。Nginx、Redis 这类服务,一旦连接数上来,超出这个值的请求直接就被内核丢掉了,你的应用层甚至收不到这些请求。

vm.swappiness = 10:告诉内核尽量用物理内存,少用swap。对于跑数据库或缓存服务的机器,swap一上来性能就断崖式下跌。设成10意味着只有内存用到90%以上才会考虑swap。

vm.overcommit_memory = 1:允许超量分配内存。很多应用(比如Redis fork子进程做RDB快照)需要短时间内申请大量内存,实际上并不会全部用完。默认策略0会在某些情况下拒绝合理的内存申请,导致进程启动失败。

net.ipv4.tcp_tw_reuse = 1:高并发短连接场景下,大量连接会进入 TIME_WAIT 状态。开启复用可以让这些端口尽快被新连接使用,避免端口耗尽。

配合 sysctl 调优,用户级别的资源限制也得配上:

cat >> /etc/security/limits.conf << 'EOF' *    soft    nofile    65535 *    hard    nofile    65535 *    soft    nproc     65535 *    hard    nproc     65535 *    soft    core      unlimited *    hard    core      unlimited root soft    nofile    65535 root hard    nofile    65535 EOF

nofile 是最大打开文件数,nproc 是最大进程数。这两个值对高并发服务影响巨大。我之前调过一个电商系统,峰值QPS上到2万的时候,Nginx 疯狂报错 "too many open files",查了一下发现默认的 nofile 只有1024。改到65535之后,问题立消失。

三、系统优化与清理

系统跑久了,日志文件越来越大、临时文件堆成山、无用服务占用资源。这些事儿不处理,再好的硬件也扛不住。

3.1 日志管理

日志是排查问题的利器,但不加限制地记录日志,磁盘分分钟被撑爆。见过一台生产服务器,/var/log 占了50GB,系统盘一共才40GB,直接导致磁盘写满服务全挂:

# 配置 journald 日志限制 mkdir -p /etc/systemd/journald.conf.d cat > /etc/systemd/journald.conf.d/limit.conf << 'EOF' [Journal] SystemMaxUse=500M SystemMaxFileSize=100M MaxRetentionSec=30day ForwardToSyslog=no EOF systemctl restart systemd-journald # 配置 logrotate cat > /etc/logrotate.d/custom << 'EOF' /var/log/messages /var/log/secure /var/log/cron {    daily    rotate 7    compress    delaycompress    missingok    notifempty    create 0640 root root    sharedscripts    postrotate        /bin/kill -HUP $(cat /var/run/syslogd.pid 2>/dev/null) 2>/dev/null || true    endscript } EOF

核心思路:系统日志最多保留500MB,单文件不超过100MB,超过30天自动清理。业务日志用 logrotate 按天切割,保留7天压缩存档。

3.2 禁用无用服务

新装系统通常会启动一堆你用不到的服务。每个服务都是潜在的攻击面,也是资源消耗者:

# 禁用无用服务 for svc in avahi-daemon cups bluetooth postfix \           ModemManager accounts-daemon; do    systemctl stop $svc 2>/dev/null    systemctl disable $svc 2>/dev/null done # 关闭图形界面(服务器不需要) systemctl set-default multi-user.target # 关闭IPv6(如果内网不用) echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf echo 'net.ipv6.conf.default.disable_ipv6 = 1' >> /etc/sysctl.conf sysctl -p

3.3 NTP 时间同步

时间不同步,认证会失败、日志对不上、分布式系统会出问题。这事儿必须配:

# 安装并配置 chrony yum install -y chrony 2>/dev/null || apt install -y chrony systemctl enable chronyd systemctl start chronyd # 或者用 ntpdate 快速同步一次 ntpdate ntp.aliyun.com

3.4 系统更新

新装系统的第一件事就是打补丁。安全漏洞的修复等不起:

# CentOS/RHEL yum update -y --exclude=kernel* yum clean all # Ubuntu/Debian apt update && apt upgrade -y apt autoremove -y apt clean

注意我加了 --exclude=kernel*。为什么?因为内核升级需要重启,我们先把用户空间的包更新完,内核单独处理,避免更新过程中服务中断。

四、常用软件自动化部署

每台服务器都应该有一套标准工具集。运维人员登上去,基本的排查工具得随手可用,不能临时去装。

# 系统工具 yum install -y vim wget curl net-tools lsof tree \    htop iotop iftop nmon ncdu bash-completion \    lrzsz bind-utils tcpdump strace sysstat \    lsof telnet rsync unzip bzip2 xz psmisc 2>/dev/null # 或者 Ubuntu/Debian apt install -y vim wget curl net-tools lsof tree \    htop iotop iftop nmon ncdu bash-completion \    lrzsz dnsutils tcpdump strace sysstat \    telnet rsync unzip bzip2 xz psmisc -y

几个常用工具说一下用途:

htop:比 top 好看100倍,进程树、CPU/内存柱状图一目了然

iftop:实时网络流量监控,哪个 IP 占带宽一目了然

iotop:IO 占用排行,排查磁盘瓶颈必备

ncdu:交互式磁盘占用分析,比 du -sh 好用太多

strace:系统调用追踪,进程卡住、报错时用它跟踪到底

tcpdump:抓包分析,网络问题的终极武器

4.1 配置 Vim

默认的 Vim 配置很难用,花一分钟调一下,编辑效率高不少:

cat > /etc/vimrc.local << 'EOF' set number set tabstop=4 set shiftwidth=4 set expandtab set autoindent set smartindent set ruler set showmode set showcmd set hlsearch set incsearch set ignorecase set smartcase syntax on EOF # 让所有用户的 vim 加载这个配置 echo 'source /etc/vimrc.local' >> /etc/vimrc

4.2 配置 bash 增强

让终端用起来更舒服:

cat >> /etc/profile.d/custom.sh << 'EOF' # 彩色 ls alias ls='ls --color=auto' alias ll='ls -lh' alias la='ls -lha' # 常用快捷 alias grep='grep --color=auto' alias df='df -h' alias du='du -h' alias free='free -h' alias netstat='netstat -tlnp' # 中文支持 export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 # 退出时清屏(防止敏感信息残留) # trap 'history -w' EXIT EOF

4.3 安装 Docker(可选)

现在的服务器,不装 Docker 都不好意思说自己是运维。当然,不是所有场景都需要,但装上总没错:

# 一键安装 Docker curl -fsSL https://get.docker.com | sh -s docker --mirror Aliyun # 配置 Docker 镜像加速 mkdir -p /etc/docker cat > /etc/docker/daemon.json << 'EOF' {  "registry-mirrors": [    "https://mirror.baidubce.com",    "https://docker.1ms.run"  ],  "log-driver": "json-file",  "log-opts": {    "max-size": "50m",    "max-file": "3"  },  "storage-driver": "overlay2",  "live-restore": true } EOF systemctl enable docker systemctl start docker # 添加当前用户到 docker 组 usermod -aG docker admin

五、完整初始化脚本

把上面所有操作整合到一个脚本里,新服务器到手,传上去跑一遍就完事。脚本自动识别发行版,不用手动切换命令:

#!/bin/bash # ============================================ # Linux 服务器初始化脚本 v2.0 # 适用于: CentOS/RHEL 7+, Ubuntu 20.04+, Debian 11+ # 用法: bash init_server.sh # ============================================ set -e # 颜色输出 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' info()  { echo -e "${GREEN}[+] $1${NC}"; } warn()  { echo -e "${YELLOW}[!] $1${NC}"; } error() { echo -e "${RED}[-] $1${NC}"; exit 1; } # 检测发行版 if [ -f /etc/redhat-release ]; then    OS="centos" elif [ -f /etc/debian_version ]; then    OS="debian" else    error "不支持的系统" fi info "检测到系统: $OS" # 检查 root 权限 if [ "$(id -u)" -ne 0 ]; then    error "请使用 root 权限运行此脚本" fi # ---- 1. SSH加固 ---- info "正在加固 SSH 配置..." cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak sed -i 's/^#\?Port 22/Port 2222/' /etc/ssh/sshd_config sed -i 's/^#\?PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config sed -i 's/^#\?PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config sed -i 's/^#\?X11Forwarding yes/X11Forwarding no/' /etc/ssh/sshd_config sed -i 's/^#\?MaxAuthTries 6/MaxAuthTries 3/' /etc/ssh/sshd_config echo 'PermitEmptyPasswords no' >> /etc/ssh/sshd_config # ---- 2. 创建管理用户 ---- info "创建管理用户..." if ! id admin &>/dev/null; then    useradd -m -s /bin/bash admin    echo "请为 admin 用户设置密码:"    passwd admin    if [ "$OS" = "centos" ]; then        usermod -aG wheel admin    else        usermod -aG sudo admin    fi    echo 'admin ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/admin    chmod 440 /etc/sudoers.d/admin fi # ---- 3. 防火墙 ---- info "配置防火墙..." if [ "$OS" = "centos" ]; then    systemctl enable firewalld    systemctl start firewalld    firewall-cmd --permanent --remove-service=ssh    firewall-cmd --permanent --add-port=2222/tcp    firewall-cmd --permanent --add-service=http    firewall-cmd --permanent --add-service=https    firewall-cmd --reload else    apt install -y ufw    ufw default deny incoming    ufw allow 2222/tcp    ufw allow 80/tcp    ufw allow 443/tcp    ufw --force enable fi # ---- 4. 内核调优 ---- info "优化内核参数..." cat >> /etc/sysctl.conf << 'SYSCTL' net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_max_syn_backlog = 1024 net.core.somaxconn = 2048 net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.tcp_tw_recycle = 0 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_keepalive_time = 600 net.ipv4.tcp_keepalive_intvl = 30 net.ipv4.tcp_keepalive_probes = 5 net.ipv4.tcp_fastopen = 3 net.ipv4.ip_local_port_range = 1024 65535 vm.swappiness = 10 vm.overcommit_memory = 1 fs.file-max = 1048576 kernel.dmesg_restrict = 1 kernel.yama.ptrace_scope = 1 SYSCTL sysctl -p # 文件描述符限制 cat >> /etc/security/limits.conf << 'LIMITS' *    soft    nofile    65535 *    hard    nofile    65535 *    soft    nproc     65535 *    hard    nproc     65535 LIMITS # ---- 5. 日志管理 ---- info "配置日志管理..." mkdir -p /etc/systemd/journald.conf.d cat > /etc/systemd/journald.conf.d/limit.conf << 'JOURNAL' [Journal] SystemMaxUse=500M SystemMaxFileSize=100M MaxRetentionSec=30day ForwardToSyslog=no JOURNAL systemctl restart systemd-journald # ---- 6. 时间同步 ---- info "配置时间同步..." if [ "$OS" = "centos" ]; then    yum install -y chrony    systemctl enable chronyd    systemctl start chronyd else    apt install -y chrony    systemctl enable chrony    systemctl start chrony fi # ---- 7. 安装常用工具 ---- info "安装常用工具..." if [ "$OS" = "centos" ]; then    yum install -y epel-release    yum install -y vim wget curl net-tools lsof tree \        htop iotop iftop nmon ncdu bash-completion \        lrzsz bind-utils tcpdump strace sysstat \        rsync unzip bzip2 xz psmisc fail2ban else    apt install -y vim wget curl net-tools lsof tree \        htop iotop iftop nmon ncdu bash-completion \        lrzsz dnsutils tcpdump strace sysstat \        rsync unzip bzip2 xz psmisc fail2ban fi # ---- 8. 禁用无用服务 ---- info "禁用无用服务..." for svc in avahi-daemon cups bluetooth; do    systemctl stop $svc 2>/dev/null    systemctl disable $svc 2>/dev/null done systemctl set-default multi-user.target # ---- 9. Vim配置 ---- info "配置 Vim..." cat > /etc/vimrc.local << 'VIM' set number set tabstop=4 set shiftwidth=4 set expandtab set autoindent set hlsearch set incsearch syntax on VIM grep -q "vimrc.local" /etc/vimrc 2>/dev/null || echo 'source /etc/vimrc.local' >> /etc/vimrc # ---- 10. 系统更新 ---- info "正在更新系统..." if [ "$OS" = "centos" ]; then    yum update -y --exclude=kernel*    yum clean all else    apt update && apt upgrade -y    apt autoremove -y    apt clean fi info "==========================================" info "服务器初始化完成!" info "请执行以下操作:" info "1. 测试密钥登录: ssh -p 2222 admin@IP" info "2. 确认密钥登录正常后重启: reboot" info "3. 重启后验证服务状态" info "=========================================="

六、验证清单:跑完脚本之后做什么

脚本跑完不是结束,验证才是关键。以下清单建议逐一过一遍:

SSH验证:新开一个终端窗口,用密钥 + 2222 端口登录 admin 用户,确认能正常进入。这一步必须在关闭当前root会话之前完成!

防火墙验证firewall-cmd --list-allufw status,确认端口规则正确

内核参数验证sysctl -a | grep somaxconn 确认值已生效

fail2ban验证fail2ban-client status sshd

时间同步验证chronyc tracking

服务验证systemctl list-units --type=service --state=running 查看运行中的服务

磁盘验证df -h 确认磁盘正常

重启验证reboot 之后确认所有配置仍然生效(尤其是 sysctl 和 limits.conf 是否持久化)

总结一下

系统初始化这事儿,说白了就是把"毛坯房"变成"精装房"。安全加固是门锁和防盗窗,内核调优是水电改造,常用工具是家具家电。一套脚本跑完,新服务器直接达到生产标准,不用每次手动折腾。

这套脚本在我手里迭代了好几个版本,每台新机器都用它。最开始是几行命令,后来发现漏了日志管理,补上;又发现 fail2ban 没装,再加;内核参数也是踩过坑才调到最优。现在这套算是比较完整了,直接拿去用就行。

当然,不同业务场景可能还需要额外调整。比如跑数据库的机器,IO 调度器和内存参数要再细调;跑容器的机器,cgroup 和网络配置要额外关注。这些咱们后面慢慢聊。

下期预告: 系统初始化搞定了,下一篇咱们来讲讲——如何搭建一套完整的监控告警体系。Prometheus + Grafana + Alertmanager,从安装到配置到自定义告警规则,让你的服务器永远处在你的掌控之中。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 08:28:08 HTTP/2.0 GET : https://f.mffb.com.cn/a/493864.html
  2. 运行时间 : 0.116531s [ 吞吐率:8.58req/s ] 内存消耗:4,800.87kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=580faebe92ec24d66f7b036eff61dba0
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000730s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000814s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000304s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000286s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000548s ]
  6. SELECT * FROM `set` [ RunTime:0.000204s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000575s ]
  8. SELECT * FROM `article` WHERE `id` = 493864 LIMIT 1 [ RunTime:0.001393s ]
  9. UPDATE `article` SET `lasttime` = 1783038488 WHERE `id` = 493864 [ RunTime:0.006568s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 67 LIMIT 1 [ RunTime:0.000311s ]
  11. SELECT * FROM `article` WHERE `id` < 493864 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000628s ]
  12. SELECT * FROM `article` WHERE `id` > 493864 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000389s ]
  13. SELECT * FROM `article` WHERE `id` < 493864 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.002194s ]
  14. SELECT * FROM `article` WHERE `id` < 493864 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.003574s ]
  15. SELECT * FROM `article` WHERE `id` < 493864 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.028300s ]
0.118120s