Elasticsearch集群部署

        服务器配置:

  • 10.8.8.95
  • 10.8.8.96
  • 10.8.8.97

        硬盘挂载 /home/hifo

一、安装JDK

        首先下载JDK,官网

        下载后解压

1
2
tar zxvf jdk-8u111-linux-x64.tar.gz
mv jdk1.8,0_111/ /usr/local/

        编译文件

1
vim /etc/profile.d/java.sh

        加入配置

1
2
3
4
5
6
JAVA_HOME=/usr/local/jdk1.8.0_111/
JAVA_BIN=/usr/local/jdk1.8.0_111/bin
JRE_HOME=/usr/local/jdk1.8.0_111/jre
PATH=$PATH:/usr/local/jdk1.8.0_111/bin:/usr/local/jdk1.8.0_111/jre/bin
CLASSPATH=/usr/local/jdk1.8.0_111/jre/lib:/usr/local/jdk1.8.0_111/lib:/usr/local/jdk1.8.0_111/jre/lib/charsets.jar
export JAVA_HOME JAVA_BIN JRE_HOME PATH CLASSPATH

        然后初始化环境

1
source /etc/profile.d/java.sh

        如果配置成功,就可以看到java的版本

1
2
3
4
java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

二、安装elasticsearch

        官网

1、下载安装

1
2
3
4
5
cd /usr/local/src/
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-2.4.0.tar.gz
tar -xvf elasticsearch-2.4.0.tar.gz
mv elasticsearch-2.4.0 /usr/local/
cd /usr/local/elasticsearch-2.4.0/

2、系统调优

        配置系统最大打开文件描述符数

1
vim /etc/sysctl.conf
1
vm.max_map_count=262144

        执行以下命令生效

1
sysctl –p

        配置进程最大打开文件描述符

1
2
* soft nofile 65536
* hard nofile 65536

3、编写elasticsearch master节点配置文件

1
vim config/elasticsearch.yml
1
2
3
4
5
6
7
8
9
10
cluster.name: hifo-es
node.name: node-1
network.host: 10.8.8.95
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["10.8.8.95","10.8.8.96","10.8.8.97"]
discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"

4、启动elasticsearch

        用root帐号启动会报错:

1
java.lang.RuntimeException: can not runelasticsearch as root

        因为elasticsearch不能使用root账户启动,所以先创建一个elasticearch组和账户

1
2
3
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
chown -R elsearch.elsearch /usr/local/elasticsearch-2.4.0/

        后台启动

1
su - elsearch -c "/usr/local/elasticsearch-2.4.0/bin/elasticsearch -d"

01