命令记不住

登陆

CentOS 系统和优化

CentOS系统和优化

1.操作系统

1.网卡配置

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

BOOTPROTO=static   #启用静态IP地址
ONBOOT=yes  #开启自动启用网络连接
IPADDR=192.168.0.54  #设置IP地址
NETMASK=255.255.255.0  #设置子网掩码
GATEWAY=192.168.0.1   #设置网关
DNS1=8.8.8.8 #设置主DNS
DNS2=8.8.4.4 #设置备DN

2.关闭防火墙

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl disable firewalld

3.关闭网络管理工具

systemctl disable NetworkManager --now
systemctl disable firewalld --now

4.设置dns

cat > /etc/resolv.conf <<EOF
options timeout:1 attempts:1 rotate single-request-reopen
nameserver 114.114.114.114
nameserver 223.5.5.5
nameserver 119.29.29.29
EOF

5.同步时间

systemctl disable ntpd --now
echo "1 * * * * /usr/sbin/ntpdate ntp1.aliyun.com && /sbin/hwclock -w > /dev/null 2>&1" >> /var/spool/cron/root

6.设置环境变量

cat >> /etc/profile <<EOF
HISTFILESIZE=900000
HISTSIZE=900000
export HISTTIMEFORMAT='%F %T '
export HISTCONTROL=ignoredups
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export PS1='\[\033[01;33m\]\u\[\033[00m\]@\[\033[01;32m\]\h\[\033[00m\]: \[\033[01;34m\]\W\[\033[00m\]\$'
export TMOUT=3600
EOF

7.常用软件安装

[root@CentOS7 ~]# yum install -y automake bc bridge-utils curl dmidecode ethtool gcc gcc-c++ glibc make net-tools ntp ntpdate openssl openssh-clients sysstat wget vim ipmitool OpenIPMI pciutils smartmontools iptables-services tree htop iftop iotop lrzsz unzip telnet nmap nc psmisc dos2unix bash-completion  bash-completion-extras

8.sh连接速度慢优化

cat > /etc/ssh/sshd_config <<EOF
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
SyslogFacility AUTHPRIV
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication no
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
UseDNS no
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem sftp /usr/libexec/openssh/sftp-server
DenyGroups public
EOF

9.优化sysctl.conf

cat >> /etc/sysctl.conf <<EOF
net.ipv4.ip_local_port_range = 1024  65535
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_keepalive_time = 1
net.ipv4.tcp_fin_timeout = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_mem = 78643200 104857600 157286400
net.core.netdev_max_backlog = 8192
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.netfilter.nf_conntrack_max = 6553600
net.netfilter.nf_conntrack_tcp_timeout_established = 1200
net.ipv4.tcp_sack=0
EOF
modprobe bridge
modprobe ip_conntrack
sysctl -p

10.加大文件描述

echo "root soft nofile 100001" >> /etc/security/limits.conf
echo "root hard nofile 100002" >> /etc/security/limits.conf
echo "root   -    nproc      unlimited" >> /etc/security/limits.conf

11.关闭邮件发送服务

systemctl stop postfix
systemctl disable postfix

done

2.终端显示优化

终端显示优化

PS1=‘[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\]\[\e[31;1m\] \w\[\e[0m\]]\\$’

PS1='\[\033[01;33m\]\u\[\033[00m\]@\[\033[01;32m\]\h\[\033[00m\]: \[\033[01;34m\]\W\[\033[00m\]\$'

PS1='\n\e[1;37m[\e[m\e[1;32m\u\e[m\e[1;33m@\e[m\e[1;35m\H\e[m \e[4m`pwd`\e[m\e[1;37m]\e[m\e[1;36m\e[m WuQun \n\$'

ntp和dns

/sbin/ntpdate ntp1.aliyun.com
*/1 * * * * /sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1

nameserver 119.29.29.29
nameserver 180.76.76.76
nameserver 223.5.5.5

Done

3.克隆虚拟机之前的操作

1清2删:
1清:

echo "" > /etc/udev/rules.d/70-persistent-net.rules

2删:

删除网卡配置文件中的:UUID和HWADDR这两行

推荐阅读