CentOS7初始环境配置指南
1. 基础组件安装与系统更新
# 安装常用工具
yum install -y wget vim
# 更换国内YUM源
cd /etc/yum.repos.d/
rm -rf /etc/yum.repos.d/*.repo
wget https://mirrors.aliyun.com/repo/Centos-7.repo
wget https://mirrors.aliyun.com/repo/epel-7.repo
wget https://mirrors.aliyun.com/repo/epel.repo
wget https://mirrors.aliyun.com/repo/epel-testing.repo
yum install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm
# 清理并重建缓存
yum clean all
yum makecache
yum check-update
# 系统全面升级
yum update -y
# 安装增强工具
yum install -y bash-completion ntp net-tools tree
2. 修改主机标识
# 永久设定主机名称
hostnamectl set-hostname Zabbix-Server01
3. 执行安全加固脚本
根据企业安全规范运行基线检查脚本。
4. 实用软件包详解
- SSH服务端:支持远程管理
yum install openssh-server - 网络诊断工具:包含netstat/ifconfig
sudo yum install net-tools - 进程监控工具:交互式资源查看
sudo yum install htop - 文件管理器:类Norton Commander
sudo yum install mc - 目录树展示:
sudo yum install tree
[root@CentOS7 opt]# tree -L 2
.
├── openssl-3.3.1
│ ├── ACKNOWLEDGEMENTS.md
│ ├── apps
│ ├── AUTHORS.md
│ ├── build.info
│ ├── CHANGES.md
│ ├── cloudflare-quiche
│ ├── CODE-OF-CONDUCT.md
│ ├── config
│ ├── config.com
│ ├── configdata.pm.in
│ ├── Configurations
│ ├── Configure
│ ├── CONTRIBUTING.md
│ ├── crypto
│ ├── demos
│ ├── doc
│ ├── engines
│ ├── README-PROVIDERS.md
│ ├── README-QUIC.md
│ ├── ssl
│ ├── SUPPORT.md
│ ├── test
│ ├── tlsfuzzer
│ ├── tlslite-ng
│ ├── tools
│ ├── util
│ ├── VERSION.dat
│ ├── VMS
│ └── wycheproof
├── openssl-3.3.1.tar.gz
└── rh
11 directories, 20 files
[root@CentOS7 opt]#
- 手册查看器:获取命令帮助
sudo yum install man
以上工具覆盖基础运维需求,可根据业务场景选择性安装。
5. 调整系统时区与时间同步
# 设置时区为上海
sudo timedatectl set-timezone Asia/Shanghai
# 查看NTP状态
timedatectl status
Local time: Fri 2023-01-06 14:41:01 CST
Universal time: Fri 2023-01-06 06:41:01 UTC
RTC time: Fri 2023-01-06 06:41:01
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
6. 历史命令管理
# 清除当前对话记录并保存
history -wc
# 删除历史文件
rm -f ~/.bash_history
# 为历史命令添加时间戳并设置容量
vim /etc/profile
# 末尾追加
export HISTTIMEFORMAT="%F %T "
export HISTFILESIZE=100000
# 立即生效
source /etc/profile
history -wc:将内存记录写入文件后清空。history -c:仅清除当前内存记录,不写入文件。- 仅为Bash用户添加时间戳,编辑
/etc/bashrc。 - 为所有登录会话添加时间戳,编辑
/etc/profile。
7. 常用运维指令集
# 磁盘空间查看
df -h
fdisk -l
# 端口监听状态
ss -tulpn | grep 8080
# 端口监听状态(备选)
netstat -tulpn | grep 8080
# 实时监控端口变化(每2秒刷新)
watch -n 2 'netstat -tulpn'
# 进程查找
ps -ef | grep mysql
# 清除历史记录
> ~/.bash_history
history -c