作者:倒带灬樱花巷_317 | 来源:互联网 | 2023-05-18 10:03
安装环境系统:centos7软件信息:lasticsearch-6.6.2.rpmjdk-8u131-linux-x64_.rpmkibana-6.6.2-x86_64.rpmlo
安装环境
系统 :centos7
软件信息:
lasticsearch-6.6.2.rpm
jdk-8u131-linux-x64_.rpm
kibana-6.6.2-x86_64.rpm
logstash-6.6.0.rpm
提醒信息
请提前写配置文件,并保证配置文件与脚本处于同一目录内
以及四个安装包
脚本代码
#!/bin/bash
echo "请将脚本与配置文件和安装包放在同一路径下"
# 关闭防火墙与selinux
systemctl stop firewalld.service
setenforce 0
ip=`ifconfig ens33 |grep netmask |awk -F "[ ]" ‘{print $10}‘`
while :
do
echo "请选择E,L,K安装项目"
read -p "是否已经安装:(J/E/L/K/0)" ELK
case $ELK in
j)
echo "------------------------------------------"
echo -e "\033[43;1m检测java安装包\033[37m"
ls jdk-8u131-linux-x64_.rpm &>/dev/null
if [ $? -eq 0 ];then
echo "安装java"
rpm -ivh jdk-8u131-linux-x64_.rpm &>/dev/null
echo -e "\033[43;1m安装完毕\033[0m"
else
echo -e "\033[1;5;31m 没有安装包,自动安装退出\033[0m"
fi
echo "------------------------------------------"
;;
e)
echo -e "警告信息:\033[1;5;31m请先安装jdk后安装本项目\033[0m"
echo "------------------------------------------"
echo -e "\033[44;30m检测elasticsearch安装包\033[37m"
ls elasticsearch-6.6.2.rpm &>/dev/null
if [ $? -eq 0 ];then
echo "安装elasticsearch"
yum -y install elasticsearch-6.6.2.rpm &>/dev/null
echo "修改配置文件"
echo "cluster.name: wg007" >>/etc/elasticsearch/elasticsearch.yml
echo "node.name: node-1" >>/etc/elasticsearch/elasticsearch.yml
echo "network.host: $ip" >>/etc/elasticsearch/elasticsearch.yml
echo "http.port: 9200" >>/etc/elasticsearch/elasticsearch.yml
echo "修改结束"
echo "启动elasticsearch"
systemctl restart elasticsearch.service
# 双次执行启动
systemctl restart elasticsearch.service
echo "检测成功性"
ll /var/log/elasticsearch/wg007.log
if [ $? -eq 0 ];then
echo -e "\033[44;30m安装完毕\033[0m"
else
echo -e "\033[44;30m安装失败,退出\033[0m"
fi
else
echo -e "\033[1;5;31m 没有安装包,自动安装退出\033[0m"
fi
echo "------------------------------------------"
;;
l)
echo -e "警告信息:\033[1;5;31m请先安装jdk后安装本项目\033[0m"
echo "------------------------------------------"
echo -e "\033[46;30m检测安装包\033[37m"
ls logstash-6.6.0.rpm &>/dev/null
if [ $? -eq 0 ];then
echo "安装logstash"
yum -y install logstash-6.6.0.rpm &>/dev/null
echo "修改配置文件"
cp -f messages.conf /etc/logstash/conf.d/
sed -i "s/ip/$ip/g" /etc/logstash/conf.d/messages.conf
echo "双启动logstash"
systemctl start logstash.service
systemctl restart logstash.service
echo "赋予权限"
chmod -R 777 /var/log/
ls /var/log/logstash/logstash-plain.log &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[46;30m安装完毕\033[0m"
else
echo -e "\033[46;30m安装失败,退出\033[0m"
fi
else
echo -e "\033[1;5;31m 没有安装包,自动安装退出\033[0m"
fi
echo "------------------------------------------"
;;
k)
echo -e "警告信息:\033[1;5;31m不得与elasticsearch安装在一台机器\033[0m"
rpm -q elasticsearch &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[1;5;31m已经安装elasticsearch,无法安装kibana\033[0m"
else
echo "------------------------------------------"
echo -e "\033[45;30m开始安装kibana\033[37m"
ls logstash-6.6.0.rpm &>/dev/null
if [ $? -eq 0 ];then
echo "开始安装"
yum -y install kibana-6.6.2-x86_64.rpm &>/dev/null
echo "修改配置文件"
echo "server.port: 5601" >>/etc/kibana/kibana.yml
echo "server.host: "$ip"" >>/etc/kibana/kibana.yml
read -p "请输入elasticsearch的ip:" IP
echo "elasticsearch.hosts: ["http://$IP:9200"]" >>/etc/kibana/kibana.yml
echo "启动服务"
echo "验证"
netstat -anlp |grep 5601 &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[45;30m安装完毕,可以去浏览器查看\033[0m"
else
echo -e "\033[45;30m安装失败,退出\033[0m"
fi
else
echo -e "\033[1;5;31m没有安装包,自动安装退出\033[0m"
fi
fi
echo "--------------------------------------------------"
;;
0)
exit 0
;;
*)
echo "输入错误"
esac
done
配置文件
vim messages.conf
input {
file {
path = varlogmessages
type = system-log
start_position = beginning
}
}
output {
elasticsearch {
hosts = ip:9200
index = system_log-%{+YYYY.MM.dd}
}
}
shell-一键安装ELK脚本