CentOS 7 & Ubuntu系统初始化

该脚本主要功能模块包括:常用软件 and jdk 1.8 、防火墙等等

#!/usr/bin/env sh
#apt-get install libpcre3 libpcre3-dev openssl libssl-dev
IP=`ip addr | grep eth1|grep inet| cut -d / -f 1|awk -F"." '{print $3"-"$4}'`
INT=`ip addr | grep eth0|grep inet cut -d / -f 1| awk '{print $2}'`
#HOSTNAME=Aliyun-$IP
JDK='/usr/local/jdk1.8.0_112'
#echo $HOSTNAME > /etc/hostname
yum install -y lrzsz git vim wget psmisc
yum groupinstall -y Development Tools
#install nginx
#cd NGINX
#sh install.sh
#cd ..
#install jdk
if [ ! -d "$JDK" ];then
wget http://dev.esongbai.xyz/down/data/jdk-8u112-linux-x64.tar.gz
tar xfvz jdk-8u112-linux-x64.tar.gz
mv jdk1.8.0_112 /usr/local/
cat <<EOF >> /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/jdk1.8.0_112
export CLASS_PATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar
export PATH=\$PATH:\$JAVA_HOME/bin/
EOF
source /etc/profile
fi
#Parameter optimization
cp /etc/sysctl.d/99-sysctl.conf /etc/sysctl.d/99-sysctl.conf_$(date +"%F")
cat /dev/null > /etc/sysctl.d/99-sysctl.conf
echo " 
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
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        16384   4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
#net.core.somaxconn = 262144
net.core.somaxconn = 65535
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024    65000
vm.swappiness = 1
vm.overcommit_memory = 1
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1 " >> /etc/sysctl.d/99-sysctl.conf
sysctl -p
LIM=`ulimit -n`
if [ $LIM -lt 65535 ];then
	echo "* soft nofile 65535" >> /etc/security/limits.conf
	echo "* hard nofile 65536" >> /etc/security/limits.conf
fi
#Login configuration
#groupadd tomcat
#useradd -g tomcat tomcat -m
# chpasswd -e < chpasswd.txt
#mkdir /home/tomcat/.ssh && touch /home/tomcat/.ssh/authorized_keys && chown tomcat.tomcat /home/tomcat/.ssh -R && chmod 700 /home/tomcat/.ssh
#rm -rf chpasswd.txt
! test -d /root/.ssh && mkdir /root/.ssh && chmod 700 /root/.ssh
echo "public keys" > /root/.ssh/authorized_keys
#gre
! test -x /etc/rc.d/rc.local && chmod +x /etc/rc.d/rc.local
#/bin/sh create_gre.sh
#iptables
RUNF=`systemctl status firewalld | grep Active | cut -d':' -f 2 | awk '{print $1}'`
if [ $RUNF = active ];then
systemctl stop firewalld
systemctl disable firewalld
fi
yum install iptables-services -y
systemctl start iptables
systemctl enable iptables

发表评论