龙蜥AnolisOS 8.8 最小化安装后,我都装了哪些必备软件?(附完整配置脚本)
龙蜥AnolisOS 8.8最小化安装后的高效生产环境配置指南
当你完成龙蜥AnolisOS 8.8的最小化安装后,系统就像一张白纸,等待你将其打造成高效的生产力工具。作为系统管理员,我们需要快速完成从裸机到生产环境的转变。本文将分享一套经过实战检验的配置流程,涵盖网络、工具集、安全调优、时间同步以及常用中间件部署,助你快速搭建稳定可靠的服务器环境。
1. 网络与软件源配置
网络连接是系统配置的第一步。对于AnolisOS 8.8,我们推荐使用阿里云镜像源以获得更快的软件下载速度。以下是具体配置步骤:
首先检查网络连接状态:
nmcli connection show如果网络未连接,可以使用以下命令激活:
nmcli connection up ens32 # 根据实际网卡名称调整配置阿里云镜像源:
# 备份原有repo文件 mkdir -p /etc/yum.repos.d/backup mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ # 创建新的repo文件 cat > /etc/yum.repos.d/anolis.repo <<EOF [BaseOS] name=AnolisOS-8.8 - Base baseurl=https://mirrors.aliyun.com/anolis/8.8/BaseOS/x86_64/os/ enabled=1 gpgcheck=0 [AppStream] name=AnolisOS-8.8 - AppStream baseurl=https://mirrors.aliyun.com/anolis/8.8/AppStream/x86_64/os/ enabled=1 gpgcheck=0 EOF更新软件包缓存:
yum clean all yum makecache提示:如果企业内网有私有镜像源,建议优先使用内网源以提高下载速度并减少外网带宽占用。
2. 基础工具集安装
最小化安装的系统缺少许多常用工具,我们需要补充这些基础软件包以提高工作效率。
2.1 必备命令行工具
安装开发和管理工具套件:
yum install -y vim-enhanced net-tools telnet lrzsz unzip tar wget curl \ bash-completion git htop iotop iftop sysstat \ gcc make cmake automake autoconf libtool这些工具提供了:
- vim-enhanced:功能更强大的文本编辑器
- net-tools:传统网络工具(ifconfig等)
- lrzsz:方便的文件传输工具
- htop/iotop/iftop:系统监控三件套
2.2 开发环境配置
对于开发环境,还需要安装语言运行时:
# Python3及相关工具 yum install -y python3 python3-pip python3-devel # Java环境 yum install -y java-11-openjdk-devel # Node.js curl -sL https://rpm.nodesource.com/setup_16.x | bash - yum install -y nodejs验证安装:
python3 --version java -version node --version npm --version3. 安全与性能调优
生产环境必须重视安全性和性能优化。以下是关键配置项:
3.1 SELinux与防火墙配置
虽然可以完全禁用SELinux,但更推荐设置为宽容模式:
# 查看当前SELinux状态 getenforce # 修改为宽容模式 sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config setenforce 0防火墙建议保持开启但配置适当规则:
systemctl enable firewalld --now # 放行常用端口 firewall-cmd --permanent --add-service=ssh firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload3.2 系统参数优化
调整系统内核参数以提高性能:
# 备份现有配置 cp /etc/sysctl.conf /etc/sysctl.conf.bak # 追加优化参数 cat >> /etc/sysctl.conf <<EOF # 增加文件描述符限制 fs.file-max = 655350 # 网络相关优化 net.ipv4.tcp_max_syn_backlog = 8192 net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 30 net.ipv4.ip_local_port_range = 1024 65000 EOF # 应用配置 sysctl -p3.3 日志管理
配置合理的日志轮转策略:
cat > /etc/logrotate.d/syslog <<EOF /var/log/messages { daily rotate 30 missingok notifempty compress delaycompress sharedscripts postrotate /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true endscript } EOF4. 时间同步服务配置
精确的时间同步对分布式系统至关重要。我们使用chrony作为时间同步服务:
安装并配置chrony:
yum install -y chrony # 配置阿里云NTP服务器 sed -i 's/^pool.*/server ntp.aliyun.com iburst/' /etc/chrony.conf systemctl enable chronyd --now验证时间同步状态:
chronyc sources -v chronyc tracking手动强制同步时间:
chronyc -a makestep5. 常用中间件安装
5.1 Zabbix Agent部署
监控是运维的基础,以下是Zabbix Agent的快速安装方法:
# 安装Zabbix官方仓库 rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-3.el8.noarch.rpm # 安装Agent yum install -y zabbix-agent2 # 配置Agent sed -i "s/^Server=.*/Server=zabbix.yourcompany.com/" /etc/zabbix/zabbix_agent2.conf sed -i "s/^ServerActive=.*/ServerActive=zabbix.yourcompany.com/" /etc/zabbix/zabbix_agent2.conf sed -i "s/^Hostname=.*/Hostname=`hostname`/" /etc/zabbix/zabbix_agent2.conf # 启动服务 systemctl enable zabbix-agent2 --now5.2 MySQL 5.7安装与配置
虽然AnolisOS 8.8默认仓库提供MariaDB,但许多应用仍需要MySQL 5.7:
# 添加MySQL官方仓库 rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm # 禁用8.0仓库,启用5.7仓库 sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo # 安装MySQL 5.7 yum --enablerepo=mysql57-community install -y mysql-community-server # 初始化MySQL systemctl enable mysqld --now获取初始密码并安全配置:
grep 'temporary password' /var/log/mysqld.log mysql_secure_installation优化MySQL配置:
cat > /etc/my.cnf.d/custom.cnf <<EOF [mysqld] # 缓冲池大小,建议为物理内存的50-70% innodb_buffer_pool_size = 2G # 日志配置 slow_query_log = 1 long_query_time = 2 log_queries_not_using_indexes = 1 # 连接数设置 max_connections = 200 wait_timeout = 300 interactive_timeout = 300 EOF systemctl restart mysqld6. 一键配置脚本
为方便重复部署,以下是整合所有配置的脚本:
#!/bin/bash # 网络与软件源配置 function setup_network_repo() { echo "配置阿里云镜像源..." mkdir -p /etc/yum.repos.d/backup mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ cat > /etc/yum.repos.d/anolis.repo <<EOF [BaseOS] name=AnolisOS-8.8 - Base baseurl=https://mirrors.aliyun.com/anolis/8.8/BaseOS/x86_64/os/ enabled=1 gpgcheck=0 [AppStream] name=AnolisOS-8.8 - AppStream baseurl=https://mirrors.aliyun.com/anolis/8.8/AppStream/x86_64/os/ enabled=1 gpgcheck=0 EOF yum clean all yum makecache } # 基础工具安装 function install_basic_tools() { echo "安装基础工具..." yum install -y vim-enhanced net-tools telnet lrzsz unzip tar wget curl \ bash-completion git htop iotop iftop sysstat \ gcc make cmake automake autoconf libtool \ python3 python3-pip python3-devel java-11-openjdk-devel } # 安全配置 function setup_security() { echo "配置SELinux和防火墙..." sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config setenforce 0 systemctl enable firewalld --now firewall-cmd --permanent --add-service=ssh firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload } # 时间同步 function setup_chrony() { echo "配置时间同步..." yum install -y chrony sed -i 's/^pool.*/server ntp.aliyun.com iburst/' /etc/chrony.conf systemctl enable chronyd --now chronyc -a makestep } # 执行所有配置 setup_network_repo install_basic_tools setup_security setup_chrony echo "基础配置已完成!"将此脚本保存为anolis_init.sh并赋予执行权限:
chmod +x anolis_init.sh ./anolis_init.sh这套配置流程在实际生产环境中经过多次验证,能够快速将AnolisOS 8.8最小化安装转变为功能完善的生产服务器。根据具体需求,你可以选择性地执行各个部分的配置,或者扩展脚本以满足特殊需求。
