1、修改網絡配置
vi /etc/sysconfig/network-scripts/ifcfg-eth0 #編輯network配置文件修改以下兩項 (eth1同理) ONBOOT=yes BOOTPROTO=static
#同時刪除UUID MAC
2、安裝基礎包
[root@localhost ~]# yum -y install gcc glibc gcc-c++ make net-tools screen vim lrzsz tree dos2unix lsof tcpdump bash-completion wget ntp
3、更改yum源地址
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
查看修改后的信息。
ls /etc/yum.repos.d/
4、關閉防火牆和selinux
#關閉防火牆
systemctl disable firewalld
systemctl stop firewalld
#關閉selinux
sed -i 's#SELINUX=disabled#SELINUX=enforcing#g' /etc/sysconfig/selinux
5、提權george用戶可以使用sudo
useradd xxxx echo "123456"|passwd --stdin niwei \cp /etc/sudoers /etc/sudoers.ori echo "xxxx ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers tail -1 /etc/sudoers visudo -c
6、刪除兩塊網卡中的信息UUID和MAC地址信息,為了后續的克隆虛擬機不出現網絡問題,需要調整兩塊網卡eth0和eth1的配置文件。
vim /etc/sysconfig/network-scripts/ifcfg-eth0
vim /etc/sysconfig/network-scripts/ifcfg-eth1
將其中的UUID和MAC地址的信息刪除。
或者使用下面的命令一次執行完。
sed -ri '/UUID|HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth[01]
7、清空網絡規則配置文件
將網絡規則配置文件中的信息全部清零,目的也是為了能夠在后續克隆模板機時不出現錯誤。
/etc/udev/rules.d/70-persistent-net.rules echo '>/etc/udev/rules.d/70-persistent-net.rules' >> /etc/rc.local
8、服務器規划目錄
腳本存放目錄設定為:mkdir -p /server/scripts
應用程序目錄設定為:mkdir -p /application
工具目錄設定為:mkdir -p /tools
mkdir -p /server/scripts mkdir -p /application mkdir -p /tools
9、設置英文字符集
cp /etc/locale.conf /etc/locale.conf.ori echo 'LANG="en_US.UTF-8"' >/etc/locale.conf source /etc/locale.conf echo $LANG
10、系統時間Internet同步,個人傾向使用阿里雲的服務器。
crontab -e
0 1 * * * ntpdate time1.aliyun.com > /dev/null
crontab -l
11、加大文件描述符
永久加大修改打開的文件數量。
echo '* - nofile 65535 ' >>/etc/security/limits.conf tail -1 /etc/security/limits.conf
臨時修改打開文件數量。
ulimit -n 65535
檢查默認打開文件數。
ulimit -a
查看其中的信息 。
open files (-n) 1024
文件描述符是一個服務默認可以打開的文件數量。
12、內核文件優化
cat >>/etc/sysctl.conf<<EOF net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_keepalive_time = 600 net.ipv4.ip_local_port_range = 4000 65000 net.ipv4.tcp_max_syn_backlog = 16384 net.ipv4.tcp_max_tw_buckets = 36000 net.ipv4.route.gc_timeout = 100 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_synack_retries = 1 net.core.somaxconn = 16384 net.core.netdev_max_backlog = 16384 net.ipv4.tcp_max_orphans = 16384 EOF
以下參數是對iptables防火牆的優化,如果防火牆不開會出現提示,可以忽略不理。
net.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_tcp_timeout_established = 180 net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60 net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
生效上面的配置信息。
sysctl -p
13、修改默認端口ssh連接
[root@jiazhigang ~]# cp /etc/ssh/sshd_config{,.ori} sed -ir '13 iPort 52113\nPermitRootLogin no\nPermitEmptyPasswords no\nUseDNS no\nGSSAPIAuthentication no' sshd_config [root@jiazhigang ~]# systemctl restart sshd