vmware模板机centos7.7制作

vmware模板机centos7.7制作

1、网卡模块

1>修改网卡名称为eth0

PEERDNS=no
这个选项可令 /etc/resolv.conf 在系统重启后不会被重写。

mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0

cat /etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
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=eth0
DEVICE=eth0
ONBOOT=yes
PEERDNS=no

2>修改grub配置,添加net.ifnames=0 biosdevname=0 字段

[root@localhost ~]# cat /etc/sysconfig/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb net.ifnames=0 biosdevname=0 quiet"
GRUB_DISABLE_RECOVERY="true"

3>生成grub启动菜单重启系统生效

   grub2-mkconfig -o /boot/grub2/grub.cfg
   reboot

2、防火墙、swap、swap,禁用开机启动项

systemctl stop firewalld && systemctl disable firewalld
setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
swapoff -a

注释fstab内swap挂载选项
cat /etc/fstab
#/dev/mapper/centos-swap swap                    swap    defaults        0 0

systemctl disable dbus-org.freedesktop.NetworkManager.service
systemctl disable dbus-org.freedesktop.nm-dispatcher.service
systemctl disable NetworkManager-dispatcher.service
systemctl disable NetworkManager
systemctl disable postfix.service

3、优化ssh

echo 'UseDNS no'>>/etc/ssh/sshd_config
echo 'PermitRootLogin yes'>>/etc/ssh/sshd_config
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config 

4、修改默认dns

cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
#nameserver 192.168.121.2
nameserver 180.76.76.76

5、优化yum源、安装常用软件

mkdir -p /etc/yum.repos.d/old-repo
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/old-repo/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -LO http://mirrors.aliyun.com/repo/epel-7.repo
sed -i 's/mirrors.aliyuncs.com/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo


yum -y update
yum -y install vim git ntp ntpdate lrzsz lftp wget unzip zip bash-completion tree elinks nmap bind-utils net-tools tcptraceroute tmux sysstat htop 

yum -y install ledctl ipmitool pciutils smartmontools lldpd
systemctl enable --now smartd
systemctl start lldpd.service && systemctl enable lldpd.service

yum clean all

6、调整文件描述符大小

cat /etc/security/limits.conf

* soft nofile 1024000
* hard nofile 1024000

7、调整字符集,使其支持中文

cat /etc/locale.conf 

#LANG="en_US.UTF-8"
LANG="zh_CN.UTF-8"

8、内核参数调优

cp /etc/sysctl.conf /etc/sysctl.conf.bak

cat /etc/sysctl.conf

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_abort_on_overflow = 1
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096        87380  4194304
net.ipv4.tcp_wmem = 4096        66384  4194304
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.core.optmem_max = 81920
net.core.wmem_default = 8388608
net.core.wmem_max = 16777216
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.ipv4.tcp_max_syn_backlog = 1020000
net.core.netdev_max_backlog = 862144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 327680
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024    65535
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_max = 1048576
net.nf_conntrack_max = 1048576
fs.file-max = 655350

使内核参数生效

modprobe nf_conntrack
sysctl -p /etc/sysctl.conf
sysctl -w net.ipv4.route.flush=1

9、优化history

cat /etc/profile
export HISTTIMEFORMAT="%F %T `whoami` "
export HISTFILESIZE=5000
export HISTSIZE=5000

echo "source /etc/profile" >>~/.bashrc
source /etc/profile

10、设置时区、同步时间

timedatectl set-timezone Asia/Shanghai

cat /etc/rc.local
ntpdate -u ntp1.aliyun.com

chmod +x /etc/rc.d/rc.local
chmod a+x /etc/rc.local

11、垃圾清理

yum clean headers
yum clean packages
yum clean metadata

12、历史记录清理

echo > /var/log/wtmp
echo > /var/log/btmp
echo>/var/log/lastlog
echo > /var/log/secure
echo > /var/log/messages
echo>/var/log/syslog
echo>/var/log/yum.log
echo > ~/.bash_history
history -cw

13、静态ip配置

cat /etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
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=eth0
DEVICE=eth0
IPADDR=192.168.121.5
PREFIX=24
GATEWAY=192.168.121.2
#DNS1=192.168.121.2
DNS1=8.8.8.8
ONBOOT=yes
PEERDNS=no
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值