代码拉取完成,页面将自动刷新
#!/bin/bash
# 每个es节点的最大内存,单位m
es_max_mem=128
# es 节点数量
es_node_amount=3
# http client port 前缀,实际端口:es_http_port + es_node_idx,例如,配置 921,es_node_amount=3,实际为 9211,9212,9213
es_http_port_prefix=921
# 与 es_http_port 同理
es_transport_port_prefix=931
# kibana 端口
kibana_service_port=5601
# cerebro 端口
cerebro_service_port=9800
function install_ES()
{
echo -e "现在安装ES .....\n"
if [ -f ../elasticsearch-7.13.0-linux-x86_64.tar.gz ]
then
echo "elasticsearch 安装包已存在"
cp ../elasticsearch-7.13.0-linux-x86_64.tar.gz .
else
echo "elasticsearch 安装包不存在"
echo -e "现在下载ES .....\n"
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.0-linux-x86_64.tar.gz
fi
initial_master_nodes=""
for ((i=1; i<=$1; i++))
do
initial_master_nodes=$initial_master_nodes'"my_node_'$i'"'
if [ $i != $1 ] ; then
initial_master_nodes=$initial_master_nodes', '
fi
done
for ((i=1; i<=$1; i++))
do
node_dir=es_node$i
tar xvf elasticsearch-7.13.0-linux-x86_64.tar.gz
mv elasticsearch-7.13.0 $node_dir
cd $node_dir
echo -e '\n' >> config/elasticsearch.yml
echo 'cluster.name: my_app' >> config/elasticsearch.yml
echo "node.name: my_node_$i" >> config/elasticsearch.yml
echo 'path.data: ./data' >> config/elasticsearch.yml
echo 'path.logs: ./logs' >> config/elasticsearch.yml
echo "http.port: $es_http_port_prefix$i" >> config/elasticsearch.yml
echo "transport.port: $es_transport_port_prefix$i" >> config/elasticsearch.yml
echo 'network.host: 0.0.0.0' >> config/elasticsearch.yml
# 所有节点都连接到9031这个节点上去
seed_hosts_port=$es_transport_port_prefix"1"
echo 'discovery.seed_hosts: ["localhost:'$seed_hosts_port'"]' >> config/elasticsearch.yml
echo 'cluster.initial_master_nodes: ['$initial_master_nodes']' >> config/elasticsearch.yml
echo -e '\n' >> config/jvm.options
echo "-Xms${es_max_mem}m" >> config/jvm.options
echo "-Xmx${es_max_mem}m" >> config/jvm.options
touch start.sh
echo 'echo "现在启动ES'$i'....."' >> start.sh
echo "./bin/elasticsearch -d" >> start.sh
cd ..
done
}
function install_kibana()
{
echo -e "现在安装Kibana ......\n"
if [ -f ../kibana-7.13.0-linux-x86_64.tar.gz ]
then
echo "kibana 安装包已存在"
cp ../kibana-7.13.0-linux-x86_64.tar.gz .
else
echo "kibana 安装包不存在"
echo -e "现在下载 Kibana .....\n"
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.13.0-linux-x86_64.tar.gz
fi
tar xvf kibana-7.13.0-linux-x86_64.tar.gz
mv kibana-7.13.0-linux-x86_64 kibana
cd kibana
echo -e '\nserver.host: "0.0.0.0"' >> config/kibana.yml
echo -e '\nserver.port: '$kibana_service_port'' >> config/kibana.yml
es_port=$es_http_port_prefix"1"
echo -e '\nelasticsearch.hosts: ["http://localhost:'$es_port'"]' >> config/kibana.yml
touch start.sh
echo 'echo "现在启动Kabana....."' >> start.sh
echo "./bin/kibana >> run.log 2>&1 &" >> start.sh
cd ..
}
function install_cerebro()
{
echo -e "现在安装cerebro ......"
# 如果你无法从github下载文件,那么可以访问下面的链接手动(备份地址无法用wget下载)下载,然后再进行解压。
# 备份地址:https://gitee.com/dgl/es-booklet/raw/master/resources/cerebro-0.9.4.tgz
# 如果已经从备份地址下载到本地了,请将安装包放到 ES 目录的父目录中,即脚本运行的目录,
if [ -f ../cerebro-0.9.4.tgz ]
then
echo "cerebro 安装包已存在"
cp ../cerebro-0.9.4.tgz .
else
echo "cerebro 安装包不存在"
wget https://github.com/lmenezes/cerebro/releases/download/v0.9.4/cerebro-0.9.4.tgz
fi
tar xvf cerebro-0.9.4.tgz
mv cerebro-0.9.4 cerebro
cd cerebro
es_port=$es_http_port_prefix"1"
sed -i 's/server.http.port = ${?CEREBRO_PORT}/server.http.port = '$cerebro_service_port'/g' conf/application.conf
echo -e '\nhosts = [
{
host = "http://localhost:'$es_port'"
name = "my_app"
}
]' >> conf/application.conf
touch start.sh
echo 'echo "现在启动cerebro....."' >> start.sh
echo "./bin/cerebro >> run.log 2>&1 &" >> start.sh
cd ..
}
function create_start_shell()
{
touch start_es.sh
app_name="'"'{print $2}'"'"
echo 'function kill_all_app_by_name()
{
pid=`ps -ef | grep $1 | grep -v "grep" | awk -F" " '${app_name}'`
for i in $pid; do
kill -9 $i
done
}
kill_all_app_by_name "kibana"
kill_all_app_by_name "cerebro"
kill_all_app_by_name "Elasticsearch"' >> start_es.sh
for ((i=1; i<=$1; i++))
do
echo "cd es_node$i" >> start_es.sh
echo "bash start.sh" >> start_es.sh
echo "cd .." >> start_es.sh
done
echo "cd kibana" >> start_es.sh
echo "bash start.sh" >> start_es.sh
echo "cd .." >> start_es.sh
echo "cd cerebro" >> start_es.sh
echo "bash start.sh" >> start_es.sh
echo "cd .." >> start_es.sh
}
function clean_all()
{
rm elasticsearch-7.13.0-linux-x86_64.tar.gz
rm kibana-7.13.0-linux-x86_64.tar.gz
rm cerebro-0.9.4.tgz
rm add_sysctl.sh
}
function set_system_config()
{
echo 'echo -e "\nvm.max_map_count=262144" >> /etc/sysctl.conf' >> add_sysctl.sh
echo 'sysctl -p' >> add_sysctl.sh
chmod a+x add_sysctl.sh
echo 'echo -e "\n* - nofile 65535" >> /etc/security/limits.conf' >> add_limit.sh
echo 'echo -e "\n* - nproc 4096" >> /etc/security/limits.conf' >> add_limit.sh
chmod a+x add_limit.sh
echo "现在进行操作系统层面的配置, 将执行sudo su 需要你输入密码....."
sudo bash ./add_sysctl.sh
sudo bash ./add_limit.sh
}
function kill_all_app_by_name()
{
pid=`ps -ef | grep $1 | grep -v "grep" | awk -F" " '{print $2}'`
for i in $pid; do
kill -9 $i
done
}
function check_before_install() {
rm ES -rf
mkdir ES
cd ES
}
kill_all_app_by_name 'kibana'
kill_all_app_by_name 'cerebro'
kill_all_app_by_name 'Elasticsearch'
# 如果手动安装 cerebro,请将下载的文件放到 ES 目录的父目录,即脚本运行的目录
check_before_install
install_ES $es_node_amount
install_kibana
install_cerebro
set_system_config
create_start_shell $es_node_amount
clean_all
echo "安装已完成!请执行 bash start_es.sh 命令启动服务!"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。