转载:Centos7.4安装elasticsearch6.3+kibana6.3集群
Centos7.4安装elasticsearch+kibana集群
主机环境
配置:
节点数 | 4 |
---|---|
操作系统 | CentOS Linux release 7.4.1708 (Core) |
内存 | 16GB |
软件环境
软件 | 版本 | 下载地址 |
---|---|---|
jdk | jdk-8u172-linux-x64 | 点击下载 |
elasticsearch | elasticsearch-6.3.1 | 点击下载 |
kibana | kibana-6.3.1-linux-x86_64 | 点击下载 |
主机规划
4个节点角色规划如下:
主机名 | pycdhnode1 | pycdhnode2 | pycdhnode3 | pycdhnode4 |
---|---|---|---|---|
IP | 192.168.0.158 | 192.168.0.159 | 192.168.0.160 | 192.168.0.161 |
master节点 | yes | yes | yes | yes |
data节点 | yes | yes | yes | yes |
kibana | yes | no | no | no |
注: 在实际生产中,还是建议master节点和data节点分离
主机安装前准备
- 关闭所有节点的
SELinux
sed -i 's/^SELINUX=.*$/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
- 关闭所有节点防火墙
firewalld
oriptables
systemctl disable firewalld;
systemctl stop firewalld;
systemctl disable iptables;
systemctl stop iptables;
- 开启所有节点时间同步
ntpdate
echo "*/5 * * * * /usr/sbin/ntpdate asia.pool.ntp.org | logger -t NTP" >> /var/spool/cron/root
- 设置所有节点语言编码以及时区
echo 'export TZ=Asia/Shanghai' >> /etc/profile
echo 'export LANG=en_US.UTF-8' >> /etc/profile
. /etc/profile
- 所有节点添加elasticsearch用户
useradd -m elasticsearch
echo 'elasticsearch' | passwd --stdin elasticsearch
修改家目录
mv /home/elasticsearch /application
chown -R elasticsearch. /application/elasticsearch
vi /etc/passwd
,修改elasticsearch用户家目录:
elasticsearch:x:1001:1001::/application/elasticsearch:/bin/bash
设置PS1
su - elasticsearch
echo 'export PS1="\u@\h:\$PWD>"' >> ~/.bash_profile
echo "alias mv='mv -i'
alias rm='rm -i'" >> ~/.bash_profile
. ~/.bash_profile
- 设置elasticsearch用户之间免密登录 首先在pycdhnode1主机生成秘钥
su - elasticsearch
ssh-keygen -t rsa # 一直回车即可生成elasticsearch用户的公钥和私钥
cd .ssh
vi id_rsa.pub # 去掉私钥末尾的主机名 elasticsearch@pycdhnode1
cat id_rsa.pub > authorized_keys
chmod 600 authorized_keys
压缩.ssh文件夹
su - elasticsearch
zip -r ssh.zip .ssh
随后分发ssh.zip到pycdhnode2-4主机elasticsearch用户家目录解压即完成免密登录
- 主机内核参数优化以及最大文件打开数、最大进程数等参数优化 不同主机优化参数有可能不一样,故这里不作出具体优化方法,但如果elasticsearch环境用于正式生产,必须优化,linux默认参数可能会导致elasticsearch无法启动或者集群性能低下。
注: 以上操作需要使用 root
用户,到目前为止操作系统环境已经准备完成,以下开始正式安装,后面的操作如果不做特殊说明均使用 elasticsearch
用户
安装jdk1.8
所有节点都需要安装,安装方式都一样 解压 jdk-8u172-linux-x64.tar.gz
tar zxvf jdk-8u172-linux-x64.tar.gz
mkdir -p /application/elasticsearch/app
mv jdk-8u172-linux-x64 /application/elasticsearch/app/jdk
rm -f jdk-8u172-linux-x64.tar.gz
配置环境变量 vi ~/.bash_profile
添加以下内容:
#java
export JAVA_HOME=/application/elasticsearch/app/jdk
export CLASSPATH=.:$JAVA_HOME/lib:$CLASSPATH
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
加载环境变量
. ~/.bash_profile
查看是否安装成功 java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
如果出现以上结果证明安装成功。
安装elasticsearch
首先在pycdhnode1上安装 解压 elasticsearch-6.3.1.tar.gz
tar zxvf elasticsearch-6.3.1.tar.gz
mv elasticsearch-6.3.1 /application/elasticsearch/app/elasticsearch
rm -f elasticsearch-6.3.1.tar.gz
设置环境变量 vi ~/.bash_profile
添加以下内容:
#elasticsearch
export ELASTICSEARCH_HOME=/application/elasticsearch/app/elasticsearch
export PATH=$PATH:$ELASTICSEARCH_HOME/bin
加载环境变量
. ~/.bash_profile
添加配置文件 vi /application/elasticsearch/app/elasticsearch/config/elasticsearch.yml
:
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: py_es_6.3
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: pyesnode-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# For more information, consult the zen discovery module documentation.
#