服务器初始化脚本
#!/bin/bash
#关闭防火墙
Version=`cat /proc/version |awk '{print $3}' |cut -d"." -f1`
if [ $Version -eq 2 ];then
sudo service iptables stop
sudo chkconfig iptables off
else
sudo systemctl stop firewalld
sudo systemctl disable firewalld
fi
#修改默认打开句柄数
cd /etc/security/limits.d/
File=`ls`
cat <<EOF>>/etc/security/limits.d/$File
* soft nproc 20480
* hard nproc 20480
* soft nofile 1048576
* hard nofile 1048576
EOF
#修改内核参数
cat <<FOF>>/etc/sysctl.conf
net.core.somaxconn = 4096
net.ipv4.ip_local_port_range = 2048 65535
net.core.netdev_max_backlog = 65000
net.ipv4.tcp_max_syn_backlog = 8196
net.ipv4.ip_forward = 1
FOF
sudo sysctl -p /etc/sysctl.conf
#关闭selinx
setenforce 0
#添加hosts文件
IP=`ifconfig eth0 | grep "inet\s" | awk '{ print $2}'`
Host=`hostname`
echo $IP $Host >>/etc/hosts
* soft nproc 20480
* hard nproc 20480
root soft nproc unlimited
root hard nproc unlimited
* soft nofile 1048576
* hard nofile 1048576