分区划分
手动划分
根分区:/
size >= 5GB
生产环境: size = 磁盘总额的4% ~ 6%
交换分区:swap
当物理内存 < 8GB时, size = 物理内存 x 1.5;
当物理内存 >= 8GB时, size = 8GB ~ 16GB;
系统引导分区:/boot
size = 200MB
应用分区:/usr
生产环境: size = 磁盘总额的10%
数据分区:/data
生产环境: size = 磁盘总额的30% ~ 40%
1 2 3
| free -h df -h | grep -E "/$|/boot|/usr|/data"
|
自动分区
根分区:/
交换分区:swap
系统引导分区:/boot
应用分区:/usr
准备工作
修改主机名
本地配置文件:/etc/hostname
1 2 3 4
| hostnamectl set-hostname cat /etc/hostname
logout
|
配置IP地址
本地配置文件:/etc/sysconfig/network-scripts/ifcfg-*
方式一: 修改配置文件
1 2
| vi /etc/sysconfig/network-scripts/ifcfg-ens33 systemctl restart network
|
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp > none 或 static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=ecc7964d-e900-4057-91f0-70dc4801e8a2
DEVICE=ens33
ONBOOT=no > yes
IPADDR=192.168.139.110
PREFIX=24 或 NETMASK=255.255.255.0
GATEWAY=192.168.139.2
DNS1=114.114.114.114
DNS2=8.8.8.8
方式二: nmtui命令(图形化)
方式三: nmcli命令(命令行)
1
| nmcli connection modify ens33 ipv4.addresses "ip地址/掩码位数" ipv4.gateway 网关 ipv4.dns DNS服务器的ip地址 ipv4.method manual connection.autoconnect yes connection.interface-name ens33
|
查看网卡配置:
添加操作用户
1 2 3
| useradd test; passwd test
ls /var/spool/mail/ /home/
|
Changing password for user test.
New password: **********
Retype new password: **********
passud: all authentication tokens updated successfully
安装常用软件
1 2
| yum install wget lrzsz vim telnet -y yum list installed | grep -E "wget|lrzsz|vim|telnet"
|
配置Yum源
1 2 3
| mv /etc/repos.d/CentOS-Base.repo /etc/repos.d/CentOS-Base.repo.bak wget -O /etc/yum.repos.d/CentOS-Base.repo mirrors.aliyun.com/repo/Centos-7.repo yum repolist | grep aliyun
|
关闭防火墙和SELinux服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| systemctl stop firewalld systemctl disable firewalld systemctl status firewalld | grep Active
getenforce
setenforce 0
sed -i "s/=enforcing/=disabled/" /etc/selinux/config; reboot getenforce
|
修改SSH服务配置
1 2 3 4 5 6
| sed -i -e "s/#Port 22/Port 2388/" -e "s/#PermitRootLogin yes/PermitRootLogin no/" -e "s/#PermitEmptyPasswords/PermitEmptyPasswords/" /etc/ssh/sshd_config echo "UseDNS no" >> /etc/ssh/sshd_config; reboot
ss -anpt | grep 2388
|
修改文件描述符
1 2 3 4 5 6
| ulimit -n
echo "* - nofile 65535" >> /etc/security/limits.conf logout ulimit -n
|
设置登录超时
1 2 3 4 5 6 7 8
| export TMOUT=10 echo $TMOUT
echo "export TMOUT=300" > /etc/profile source /etc/profile echo $TMOUT
|