阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu 14.04 中 安装elasticsearch2.*+logstash2.*+kibana

231次阅读
没有评论

共计 4336 个字符,预计需要花费 11 分钟才能阅读完成。

在 Ubuntu 14.04 上安装单机版 ELK 2.*(脚本化)

1. 判断是否为 root 权限

if ["${UID}" -ne 0 ];
then
    echo "You must be root to run this program." >&2
    exit 3
fi

2. 记录脚本运行日志(可以在 ubuntu 日志中找到对应的运行信息)

log()
{echo "$1"
    logger "$1"
}

3. 设置脚本运行参数

# Set the VM name for the elasticsearch network.host 
# Set the host name instead of internal ip
while getopts n:e: optname; do
    log "Option $optname set with value ${OPTARG}"
  case $optname in
    n)  #set the encoded configuration string
      log "Setting the VM Name"
      VMNAME=${OPTARG}
      ;;
    e)  #set the encoded configuration string
      log "Setting the encoded configuration string"
      CONF_FILE_ENCODED_STRING=${OPTARG}
      ;;
    \?) #unrecognized option - show help
      echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed."
      help
      exit 2
      ;;
  esac
done

4. 安装 Java 8

#install java8
install_java()
{log "begin install java8"
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get -y update  > /dev/null
echo debconf shared/accepted-Oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get -y install oracle-java8-installer > /dev/null
log "java8 has been installed"
}

5. 安装 Elasticsearch,配置 Elasticsearch 的主要参数

install_config_elasticsearch()
{log "begin install elasticsearch"
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
sudo apt-get update
sudo apt-get -y install elasticsearch
# configure the elasticsearch
sudo echo "bootstrap.mlockall: true" >> /etc/elasticsearch/elasticsearch.yml
sudo echo "network.host: $VMNAME" >> /etc/elasticsearch/elasticsearch.yml
sudo echo "http.port: 9200" >> /etc/elasticsearch/elasticsearch.yml
# configure elasticsearch heap
log "elasticsearch.yml has been configured . The elasticsearch heap begin to configure"
es_heap_size=$(free -m |grep Mem | awk '{if ($2/2 >31744)  print 31744;else print $2/2;}')
sudo printf "\nES_HEAP_SIZE=%sm\n" $es_heap_size >> /etc/default/elasticsearch
sudo printf "MAX_LOCKED_MEMORY=unlimited\n" >> /etc/default/elasticsearch
sudo echo "elasticsearch - nofile 65536" >> /etc/security/limits.conf
sudo echo "elasticsearch - memlock unlimited" >> /etc/security/limits.conf
log "es heap has been set"
sudo service elasticsearch restart
sudo update-rc.d elasticsearch defaults 95 10
log "elasticsearch has been installed"
}

6. 安装主要插件,可选。

install_plugin()
{
cd /usr/share/elasticsearch/
sudo bin/plugin install lmenezes/elasticsearch-kopf
sudo bin/plugin install mobz/elasticsearch-head
sudo bin/plugin install license
sudo bin/plugin install watcher
#install marvel part0
sudo bin/plugin install marvel-agent
cd
}

7. 安装配置 kibana

install_config_kibana()
{#install kibana
log "begin to install kibana"
echo "deb http://packages.elastic.co/kibana/4.4/debian stable main" | sudo tee -a /etc/apt/sources.list.d/kibana-4.4.x.list
sudo apt-get update
sudo apt-get -y install kibana
#configure kibana
# take care of the server.host name  
sudo echo "server.host:'$VMNAME'" >> /opt/kibana/config/kibana.yml
sudo echo "elasticsearch.url:'http://$VMNAME:9200'" >> /opt/kibana/config/kibana.yml
sudo update-rc.d kibana defaults 96 9
sudo service kibana start
#install marvel part1 . marvel need to be installed after kibana was done.
sudo bin/kibana plugin --install elasticsearch/marvel/2.1.0
log "kibana has been installed"
}

8. 安装配置 logstash

install_logstash()
{# Install Logstash
# The Logstash package is available from the same repository as Elasticsearch . Install the public  key.
# Create the logstash source list
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
log "begin to install logstash"
echo 'deb http://packages.elastic.co/logstash/2.2/debian stable main' | sudo tee /etc/apt/sources.list.d/logstash-2.2.x.list
sudo apt-get update
sudo apt-get install logstash
#configure
log "Decoding configuration string"
log "$CONF_FILE_ENCODED_STRING"
echo $CONF_FILE_ENCODED_STRING > logstash.conf.encoded
DECODED_STRING=$(base64 -d logstash.conf.encoded)
log "$DECODED_STRING"
echo $DECODED_STRING > ~/logstash.conf
#log "Installing user configuration file"
log "Installing user configuration named logstash.conf"
sudo \cp -f ~/logstash.conf /etc/logstash/conf.d/
# Configure Start
log "Configure start up service"
sudo update-rc.d logstash defaults 96 9
sudo service logstash start
}

9. 运行方式

  • 如果你不太熟悉,可以分段或分句复制,type 到命令行然后运行。
  • 如果你较为熟悉,可以复制整理所有的函数到一个 elk.sh 脚本中并调用,如下:
sudo bash elk.sh -n {parameter1} -e {parameter2}
#parameter1 是 hostname
#parameter2 是 logstash 的配置文件,此处你可以简单带入如下:
"aW5wdXQgIHsgICBzdGRpbiB7fSB9IG91dHB1dCB7ICAgc3Rkb3V0IHsgY29kZWMgPT4gcnVieWRlYnVnIH0gfQ=="
# 该字符串解码后为 input {stdin {} } output {stdout { codec => rubydebug} }
#logstash 无默认的配置文件,无法启动服务。因此需要导入一个简单的配置。然后根据后续进行修改

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-12/138570.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4336字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中