VMware装Rocky 9后必做的几件事:配网络、开SSH、装监控,一条龙搞定

发布时间:2026/5/31 2:19:26

VMware装Rocky 9后必做的几件事:配网络、开SSH、装监控,一条龙搞定 VMware虚拟机安装Rocky 9后的高效运维指南刚完成Rocky Linux 9的安装只是开始真正的挑战在于如何快速搭建一个稳定、安全且易于管理的服务器环境。作为RHEL的完美替代品Rocky Linux继承了企业级Linux的可靠性但在虚拟化环境中仍需要针对性的配置优化。本文将带你完成从基础网络配置到高级监控集成的全流程操作特别针对VMware虚拟化环境中的常见痛点提供解决方案。1. 网络配置突破虚拟机连接瓶颈虚拟机网络不通是新手面对的第一道关卡。在VMware中Rocky 9默认使用NetworkManager管理网络但自动获取IP并不总是可靠。我们先解决基础连接问题再深入优化配置。1.1 桥接与NAT模式实战桥接模式下需要手动配置静态IP这是生产环境推荐的做法。执行以下命令查看网卡名称nmcli device status通常显示为ens33或ens160。接着编辑连接配置nmcli connection modify ens33 ipv4.addresses 192.168.1.100/24 \ ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8 8.8.4.4 \ ipv4.method manual connection.autoconnect yes对于NAT模式更简单的配置方式是启用DHCPnmcli connection modify ens33 ipv4.method auto两种模式的关键差异对比如下特性桥接模式NAT模式IP分配需手动配置自动获取外部访问直接暴露在局域网通过主机NAT转换适用场景需要固定IP的生产环境临时测试环境安全性需单独配置防火墙天然有一定隔离提示修改配置后必须激活更改nmcli connection up ens33使用ping google.com测试连通性1.2 防火墙策略优化Rocky 9默认启用firewalld可能导致SSH连接被拦截。开放常用端口firewall-cmd --permanent --add-servicessh firewall-cmd --permanent --add-port9090/tcp # 为后续监控预留 firewall-cmd --reload2. 安全加固与SSH最佳实践允许root通过SSH登录是便捷但危险的操作。我们采用更安全的密钥认证方案。2.1 创建专用管理账户useradd -m -s /bin/bash admin passwd admin usermod -aG wheel admin2.2 配置SSH密钥认证在本地主机生成密钥对ssh-keygen -t ed25519 -f ~/.ssh/rocky_admin将公钥上传至服务器ssh-copy-id -i ~/.ssh/rocky_admin.pub admin服务器IP然后修改SSH配置sudo vi /etc/ssh/sshd_config关键参数修改为PermitRootLogin no PasswordAuthentication no PubkeyAuthentication yes AllowUsers admin重启服务生效sudo systemctl restart sshd3. 系统监控方案深度集成3.1 资源监控三件套安装基础监控工具sudo dnf install -y htop iotop iftophtop提供实时进程监控iotop显示磁盘I/Oiftop分析网络流量。组合使用可以快速定位性能瓶颈。3.2 PrometheusGrafana方案对于长期监控推荐以下安装流程安装Prometheussudo dnf install -y prometheus sudo systemctl enable --now prometheus添加node_exporter需先下载最新版tar xvf node_exporter-*.tar.gz sudo cp node_exporter-*/node_exporter /usr/local/bin/ sudo useradd -rs /bin/false node_exporter创建systemd服务sudo vi /etc/systemd/system/node_exporter.service写入以下内容[Unit] DescriptionNode Exporter [Service] Usernode_exporter ExecStart/usr/local/bin/node_exporter [Install] WantedBymulti-user.target安装Grafanasudo dnf install -y grafana sudo systemctl enable --now grafana-server访问http://服务器IP:3000完成Grafana配置添加Prometheus数据源后导入Node Exporter仪表板。4. 性能调优关键参数4.1 文件描述符限制对于高并发应用修改limits.confsudo vi /etc/security/limits.conf添加* soft nofile 65535 * hard nofile 655354.2 内核参数优化创建专属配置文件sudo vi /etc/sysctl.d/99-rocky-tuning.conf写入以下优化参数vm.swappiness 10 net.core.somaxconn 4096 net.ipv4.tcp_max_syn_backlog 4096 net.ipv4.tcp_fin_timeout 30应用更改sudo sysctl -p /etc/sysctl.d/99-rocky-tuning.conf4.3 定期维护任务设置自动化日志轮转sudo dnf install -y logrotate sudo cp /etc/logrotate.conf /etc/logrotate.conf.bak添加自定义规则到/etc/logrotate.d/目录下相应配置文件例如nginx日志轮转/var/log/nginx/*.log { daily missingok rotate 14 compress delaycompress notifempty create 0640 nginx nginx sharedscripts postrotate /bin/kill -USR1 cat /run/nginx.pid 2/dev/null 2/dev/null || true endscript }5. 存储管理进阶技巧5.1 LVM动态扩展实战查看当前卷组信息sudo vgdisplay扩展逻辑卷假设卷组有剩余空间sudo lvextend -L 20G /dev/mapper/rl-root sudo xfs_growfs / # 对于XFS文件系统5.2 磁盘性能测试使用fio工具进行基准测试sudo dnf install -y fio fio --namerandwrite --ioenginelibaio --iodepth32 \ --rwrandwrite --bs4k --direct1 --size1G --numjobs4 \ --runtime60 --time_based --group_reporting关键指标关注IOPS随机读写性能Latency操作延迟Throughput顺序读写带宽6. 自动化运维工具链6.1 Ansible基础配置安装控制端sudo dnf install -y ansible创建inventory文件[rocky_servers] rocky9 ansible_host192.168.1.100 ansible_useradmin ansible_ssh_private_key_file~/.ssh/rocky_admin测试连接ansible rocky_servers -m ping6.2 常用管理Playbook示例系统更新playbookupdate.yml--- - hosts: rocky_servers become: yes tasks: - name: Update all packages dnf: name: * state: latest update_cache: yes执行playbookansible-playbook -i inventory update.yml通过组合这些工具和技术你的Rocky Linux虚拟机将具备企业级的管理能力和稳定性。记得定期检查系统日志journalctl -xe和监控仪表板主动发现潜在问题比被动修复更有效率。

相关新闻