获取内存信息
echo -e “\033[36m —-Start getting memory information… \033[0m”
mem_info=$(free -m | awk ‘/Mem/ {printf “%.0f\n”,$2/1024/2 }’)
if [ -z “$mem_info” ];then
echo “ Did not get the memory info,aborting”
exit 1
else
if [ “$mem_info” -ge 31 ];then
$mem_info = 31
fi
echo “ Memory information acquistion completed!”
fi
#检查资源限制配置文件
echo -e “\033[36m —-Modify the resource limit profile:/etc/security/limits.conf… \033[0m”
limits_conf=$(grep nofile /etc/security/limits.conf | grep -v “^#”)
if [ -z “$limits_conf” ];then
echo “ soft nofile 65536
hard nofile 131072
soft nproc 4096
hard nproc 4096” >> /etc/security/limits.conf
echo “ resource limit profile:/etc/security/limits.conf modified!”
#else
#资源配置文件之前修改过
# echo “资源限制配置文件/etc/security/limits.conf之前已经修改完成,本次退出修改。”
fi

检查系统控制文件
echo -e “\033[36m —-Modify system control file:/etc/sysctl.conf… \033[0m”
sysctl_conf1=$(grep “vm.max_map_count” /etc/sysctl.conf)
sysctl_conf2=$(grep “vm.rmem_default” /etc/sysctl.conf)
if [ -z “$sysctl_conf1” ];then
echo “vm.max_map_count=655360” >> /etc/sysctl.conf
sysctl -p >> /dev/null
echo “ System control file:/etc/sysctl.conf modified!”
fi
if [ -z “$sysctl_conf2” ];then
echo “net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216” >> /etc/sysctl.conf
sysctl -p >> /dev/null
echo “ System control file:/etc/sysctl.conf modified!”
fi

修改elasticsearch配置文件
echo -e “\033[36m —-Modify elasticsearch configuration file… \033[0m”
jvm_info=$(grep “^-Xms” $log_path/elasticsearch/config/jvm.options)
jvm_mem=$(echo ${jvm_info:4:1})
if [ “$jvm_mem” != “$mem_info” ];then
sed -i ‘s/-Xms1g/-Xms’”$mem_info”‘g/‘ $log_path/elasticsearch/config/jvm.options
sed -i ‘s/-Xmx1g/-Xmx’”$mem_info”‘g/‘ $log_path/elasticsearch/config/jvm.options
echo “ jvm.options configuration file modified!”
fi

检查是否有esuser普通用户
echo -e “\033[36m —-Useradd: esuser \033[0m”
es_proc=$(ps -aux | grep elasticsearch | grep -v grep | wc -l)
if [ $es_proc == 0 ];then
user=$(grep -w esuser /etc/passwd | awk -F”:” ‘{print $1}’)
if [ “$user” == “” ];then
groupadd esuser
useradd -g esuser esuser
fi
fi

添加elasticsearch到开机自启动
echo -e “\033[36m —-Add es boot—- \033[0m”
chkconfig esstart
if [ $? -ne 0 ] || [ -z “$(grep -e $log_path /etc/init.d/esstart)” ];then
echo “#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
su - esuser<<!
cd ${log_path}/elasticsearch/bin
./elasticsearch -d
exit
!” > /etc/init.d/esstart
chmod +x /etc/init.d/esstart
chkconfig —add /etc/init.d/esstart
echo “ Es boot compeleted!”
fi

安装jdk
path=$(dirname pwd)”/tools”
cd $path
#rpm_array=find . -name “.rpm”|sed ‘1d’
rpm_array=$(find . -name “
.rpm”)
for i in $rpm_array
do
#rpm -ivh $i
rpm -ivh jre-8u211-linux-x64.rpm
done
echo -e “\033[31m in:” $path “ All rpm has benn installed! \033[0m”