我确实有脚本(该脚本是天蓝色的手臂脚本的修改),可以在Azure Linux上安装elasticsearch群集,但是在最新更新之后,我的elasticsearch几乎每天都会失败。
我找不到它的问题以及我的Elasticsearch节点崩溃的原因。
#!/bin/bash
help()
{
echo "This script installs Elasticsearch on Ubuntu"
echo "Parameters:"
echo " -n elasticsearch cluster name"
echo " -m configure as master node (default: off)"
echo " -h view this help content"
}
# Log method to control/redirect log output
log()
{
echo "$1"
}
log "Begin execution of Elasticsearch script extension on ${HOSTNAME}"
if [ "${UID}" -ne 0 ];
then
log "Script executed without root permissions"
echo "You must be root to run this program." >&2
exit 3
fi
# TEMP FIX - Re-evaluate and remove when possible
# This is an interim fix for hostname resolution in current VM
grep -q "${HOSTNAME}" /etc/hosts
if [ $? == 0 ]
then
echo "${HOSTNAME} found in /etc/hosts"
else
echo "${HOSTNAME} not found in /etc/hosts"
# Append it to the hosts file if not there
echo "127.0.0.1 ${HOSTNAME}" >> /etc/hosts
log "hostname ${HOSTNAME} added to /etc/hosts"
fi
#Script Parameters
CLUSTER_NAME="es-azure"
JAVA_HOME="/usr/lib/jvm/java-12-oracle"
# Install Oracle Java
install_java()
{
log "Installing Java"
add-apt-repository ppa:linuxuprising/java -y
apt-get update -y
apt-get upgrade -y
echo debconf shared/accepted-oracle-license-v1-2 select true | debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-2 seen true | debconf-set-selections
apt-get update && apt-get install -y oracle-java12-installer
apt install oracle-java12-set-default
}
install_es()
{
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
apt-get install -y apt-transport-https
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-6.x.list
apt-get update -y
apt-get install -y elasticsearch
}
configure_es()
{
log "Update configuration"
mv /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.bak
echo "cluster.name: $CLUSTER_NAME" >> /etc/elasticsearch/elasticsearch.yml
echo "node.name: ${HOSTNAME}" >> /etc/elasticsearch/elasticsearch.yml
echo "discovery.zen.minimum_master_nodes: 2" >> /etc/elasticsearch/elasticsearch.yml
echo 'discovery.zen.ping.unicast.hosts: ["10.0.0.10", "10.0.0.11", "10.0.0.12"]' >> /etc/elasticsearch/elasticsearch.yml
echo "network.host: _site_" >> /etc/elasticsearch/elasticsearch.yml
echo "bootstrap.memory_lock: true" >> /etc/elasticsearch/elasticsearch.yml
echo "node.data: true" >> /etc/elasticsearch/elasticsearch.yml
echo "node.master: true" >> /etc/elasticsearch/elasticsearch.yml
}
configure_system()
{
echo "options timeout:1 attempts:5" >> /etc/resolvconf/resolv.conf.d/head
resolvconf -u
ES_HEAP=`free -m |grep Mem | awk '{if ($2/2 >31744) print 31744;else printf "%.0f", $2/2;}'`
echo "ES_JAVA_OPTS=\"-Xms${ES_HEAP}m -Xmx${ES_HEAP}m\"" >> /etc/default/elasticsearch
echo "JAVA_HOME=$JAVA_HOME" >> /etc/default/elasticsearch
echo 'MAX_OPEN_FILES=65536' >> /etc/default/elasticsearch
echo 'MAX_LOCKED_MEMORY=unlimited' >> /etc/default/elasticsearch
#https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html#systemd
mkdir -p /etc/systemd/system/elasticsearch.service.d
touch /etc/systemd/system/elasticsearch.service.d/override.conf
echo '[Service]' >> /etc/systemd/system/elasticsearch.service.d/override.conf
echo 'LimitMEMLOCK=infinity' >> /etc/systemd/system/elasticsearch.service.d/override.conf
sudo systemctl daemon-reload
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch
}
start_service()
{
log "Starting Elasticsearch on ${HOSTNAME}"
systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl start elasticsearch.service
sleep 60
if [ `systemctl is-failed elasticsearch.service` == 'failed' ] || [ `systemctl is-failed elasticsearch.service` == 'inactive' ];
then
log "Elasticsearch unit failed to start"
exit 1
fi
}
log "starting elasticsearch setup"
apt-get update -y
apt-get upgrade -y
install_java
install_es
configure_es
configure_system
start_service
log "completed elasticsearch setup"
exit 0
Elasticsearch版本:6.8.1
Electing master似乎有问题:
[2019-07-09T03:34:26,311][INFO ][o.e.c.s.MasterService ] [master-vm2] zen-disco-node-failed({master-vm1}{0pN6r3YTQeO8-O5HVEww7g}{VzXCoYtBQsexnz5ervFHQA}{10.0.0.11}{10.0.0.11:93$
[2019-07-09T03:34:27,841][INFO ][o.e.c.s.ClusterApplierService] [master-vm2] removed {{master-vm1}{0pN6r3YTQeO8-O5HVEww7g}{VzXCoYtBQsexnz5ervFHQA}{10.0.0.11}{10.0.0.11:9300}{ml.ma$
[2019-07-09T03:34:28,092][INFO ][o.e.i.s.IndexShard ] [master-vm2] [.elastichq][3] primary-replica resync completed with 0 operations
[2019-07-09T03:34:28,094][INFO ][o.e.i.s.IndexShard ] [master-vm2] [.elastichq][1] primary-replica resync completed with 0 operations
[2019-07-09T03:34:28,201][INFO ][o.e.i.s.IndexShard ] [master-vm2] [production_results][1] primary-replica resync completed with 0 operations
[2019-07-09T03:34:28,253][INFO ][o.e.i.s.IndexShard ] [master-vm2] [dev_results][3] primary-replica resync completed with 0 operations
[2019-07-09T03:34:28,467][INFO ][o.e.c.r.DelayedAllocationService] [master-vm2] scheduling reroute for delayed shards in [57.7s] (24 delayed shards)
[2019-07-09T03:35:57,178][INFO ][o.e.c.r.a.AllocationService] [master-vm2] Cluster health status changed from [YELLOW] to [GREEN] (reason: [shards started [[production_results][3]$
[2019-07-09T09:39:01,221][INFO ][o.e.x.m.p.NativeController] [master-vm2] Native controller process has stopped - no new native processes can be started