Centos7 系统初始化
centos 7初始化系统
1、关闭selinux:
setenfore 0
sed -i “s/enable/disabled/” /etc/config/selinx
2、关闭firewalld:sys:
systemctl stop firewalld
systemctl disabled firewalld
3、设置会话连接超时时间和History历史记录配置:在/etc/profile文件中末尾添加2行:
vim /etc/profile
export TMOUT=1800
export HISTTIMEFORMAT="%F %T whoami "
4、更新阿里云yum源
备份yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
下载阿里云yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
清理yum源缓存
yum -y clean all
产生缓存
yum makecache
查看当前源
yum repolist
更新软件
yum -y update
5、配置时间同步:
yum install -y vim && yum install -y ntpdate && /usr/sbin/ntpdate 1.cn.pool.ntp.org
执行
crontab -e
命令,添加:
0 * * * * /usr/sbin/ntpdate 1.cn.pool.ntp.org
内容
6、YUM安装必要软件:
yum install -y wget epel-release net-tools vim
7、关闭不必要的服务
systemctl stop postfix && systemctl disable postfix
systemctl stop NetworkManager && systemctl disable NetworkManager
8、内核优化
cat > /etc/sysctl.conf << EOF
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
fs.file-max = 131072
kernel.panic=1
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_no_metrics_save = 1
net.core.netdev_max_backlog = 3072
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.tcp_max_tw_buckets = 720000
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_fin_timeout = 5
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_retries1 = 2
net.ipv4.tcp_retries2 = 10
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_syncookies = 1
EOF
sysctl -p
cat >> /etc/security/limits.conf << EOF
* soft nproc 2048
* hard nproc 16384
* soft nofile 8192
* hard nofile 65536
EOF
9、设置静态ip
- 首先进入 /etc/sysconfig/network-scripts/ifcfg-ens33
vim /etc/sysconfig/network-scripts/ifcfg-ens33
- 然后把原内容删除设置以下内容
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.229.10
NETMASK=255.255.255.0
GATEWAY=192.168.229.2
DNS1=8.8.8.8
DNS2=114.114.114.114
- 保存并退出
这样就可以得到一个系统初始化好的CentOS 7 系统,进行快照就可以重复使用