修改主机名
$ hostnamectl set-hostname template
设置静态IP
# 从 CentOS-7 就开始推荐使用 nmcli 来配置网络了(CentOS-8同样适用)
# https://andyx.net/configuring_static_ip_address_in_rhel8_centos8_system_with_nmcli_nmtui_ifcfg/
# 配置IP
$ nmcli con mod enp0s3 ipv4.addresses 192.168.1.100/24
# 配置网关
$ nmcli con mod enp0s3 ipv4.gateway 192.168.1.1
# 设置手动模式(dhcp = auto, static = manual)
$ nmcli con mod enp0s3 ipv4.method manual
# 配置DNS
$ nmcli con mod enp0s3 ipv4.dns "8.8.8.8"
# 配置开机启动
$ nmcli con mod enp0s3 connection.autoconnect yes
# 实际上述命令执行结果依然是存储在 /etc/sysconfig/network-scripts/ifcfg-* 文件中,所以直接按原有方式修改该文件也是可以的
SSH公钥认证
# 密码认证常常不安全,所以采用公钥认证
# 修改 /etc/ssh/sshd_config 文件
# 关闭密码认证
PasswordAuthentication no
# 启用公钥认证
PubkeyAuthentication yes
# 重启sshd服务即生效
$ systemctl restart sshd
# 注意要先将客户机的公钥上传至目标服务器上,否则后面可能就没办法ssh连过去了(密码认证被禁)
# 客户机上生成公私钥命令
$ ssh-keygen -t rsa -C "zlikun@studio"
# 会生成公私钥文件,私钥文件应妥善保存,不要外泄
# ~/.ssh/id_rsa
# ~/.ssh/id_rsa.pub
# 将公钥上传至目标服务器上
# 括起来部分是默认值,如果公私钥存放目录按默认路径存储,则不用特别指定
# SSH服务默认端口22,如果未修改过可以不指定端口
$ ssh-copy-id [-i ~/.ssh/id_rsa.pub] <username>@<host>[:<port>]
修改时区、设置时间同步
# 设置时区
$ timedatectl set-timezone Asia/Shanghai
# 设置硬件时间不随系统时间变化
$ timedatectl set-local-rtc 0
# 设置时间自动同步,实际只是启用时间服务器,可以是 `chrony` ,也可以是 `ntp`
$ timedatectl set-ntp yes
# 查看时间/时区设置
$ timedatectl
更新YUM源
# 目前国内YUM源比较多,以阿里云为例
# https://developer.aliyun.com/mirror/centos
$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
$ curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
$ yum makecache
# 另外网易云用得也比较多
# https://mirrors.163.com/.help/centos.html
安装常用软件
# 必备软件
$ yum install -y vim git lrzsz
# 可选软件
$ yum install -y epel-release python-pip java-1.8.0-openjdk java-1.8.0-openjdk-devel