Centos7.4 安装elasticsearch6.1.3集群部署
安装elasticsearch
1.依赖环境安装
这里使用的java 是1.8.0_77的版本.使用的是rpm 安装包的形式进行部署安装 。
配置环境变量
[root@node1 ~]# cat .bash_profile
export JAVA_HOME=/usr/java/jdk1.8.0_77/ # JAVA_HOME变两个路径
export JAVA_BIN=/usr/java/jdk1.8.0_77/bin
export PATH=${JAVA_HOME}bin:$PATH
检测java环境安装是否正常
[root@node1 ~]# java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
2.elasticsearch使用的是6.1.3版本。elasticsearch-6.1.3.tar.gz
[root@node1 local]# tar -zxvf elasticsearch-6.1.3.tar.gz
[root@node1 local]# ls
bin elasticsearch-6.1.3 elasticsearch-6.1.3.tar.gz etc games include lib lib64 libexec sbin share src
修改配置文件
node1
[root@node1 local]# cd node1/config/
[root@node1 config]# cat elasticsearch.yml | grep -v "^#"
cluster.name: elasticsearch #集群的名称
node.name: node1 #节点的名称
bootstrap.memory_lock: false #另一种选择是在Linux / Unix系统上使用mlockall或在Windows上使用 VirtualLock,以尝试将进程地址空间锁定到RAM中,防止任何Elasticsearch 内存被换出。
bootstrap.system_call_filter: false #为禁用系统调用过滤器false
network.host: 133.1.11.39 #绑定到回送地址
http.port: 9200 #设置对外服务的http端口,默认为9200
discovery.zen.ping.unicast.hosts: ["133.1.11.39","133.1.11.39:9202","133.1.11.39:9203"]
discovery.zen.minimum_master_nodes: 2
node2
cluster.name: elasticsearch
node.name: node2
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 133.1.11.39
http.port: 9202
discovery.zen.ping.unicast.hosts: ["133.1.11.39","133.1.11.39:9202","133.1.11.39:9203"]
discovery.zen.minimum_master_nodes: 2
node3
cluster.name: elasticsearch
node.name: node3
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 133.1.11.39
http.port: 9203
discovery.zen.ping.unicast.hosts: ["133.1.11.39","133.1.11.39:9202","133.1.11.39:9203"]
discovery.zen.minimum_master_nodes: 2
[root@node1 config]# vim jvm.options
-Xms512m
-Xmx512m
3.需要修改的配置参数
vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
vim /etc/security/limits.d/90-nproc.conf
* soft nproc 2048
vim /etc/sysctl.conf
vm.max_map_count=655360
sysctl -p
4.启动elasticsearch 不能使用root 用户需要进行创建用户
[root@node1 ~]# groupadd es
[root@node1 ~]# useradd es -g es -p es
[root@node1 ~]# chown -R es:es /usr/local/node1
启动elasticsearch
[root@node1 bin]# ./elasticsearch -d
5.进行访问测试
[root@node1 bin]# curl http://133.1.11.39:9200
{
"name" : "node1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "dJo2cKFfSO-M-qwMF9upjg",
"version" : {
"number" : "6.1.3",
"build_hash" : "af51318",
"build_date" : "2018-01-26T18:22:55.523Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
安装head 插件
1.安装NodeJS
[root@node1 ~]# wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.5.0-linux-x64.tar.gz
[root@node1 ~]#tar -zxvf node-v4.5.0-linux-x64.tar.gz -C /usr/local
配置环境变量
export NODE_HOME=/usr/local/node-v4.5.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin/
export NODE_PATH=$NODE_HOME/lib/node_modules
[root@node1 ~]#source /etc/profile
2.安装npm
[root@node1 ~]# npm install -g cnpm --registry=https://registry.npm.taobao.org
3.使用npm安装grunt
/usr/local/node-v4.5.0-linux-x64/bin/grunt -> /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt/bin/grunt
[email protected] /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected])
[root@node1 ~]# npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy
/usr/local/node-v4.5.0-linux-x64/bin/grunt -> /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt-cli/bin/grunt
[email protected] /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt-cli
├── [email protected]
├── [email protected] ([email protected])
├── [email protected]
└── [email protected] ([email protected]
4.版本确认
[root@node1 ~]# node -v
v4.5.0
[root@node1 ~]# npm -v
2.15.9
[root@node1 ~]# grunt -version
grunt-cli v1.2.0
5.下载head插件源码
[root@node1 ~]# wget https://github.com/mobz/elasticsearch-head/archive/master.zip
[root@node1 ~]# unzip master.zip -d /usr/local/
6.下载依赖
[root@node1 elasticsearch-head-master]# npm install -g grunt-cli
/usr/local/node-v4.5.0-linux-x64/bin/grunt -> /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt-cli/bin/grunt
[email protected] /usr/local/node-v4.5.0-linux-x64/lib/node_modules/grunt-cli
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected])
[root@node1 elasticsearch-head-master]# grunt -version
grunt-cli v1.2.0
[root@node1 elasticsearch-head-master]# npm install
二. 配置ElasticSearch
停止ElasticSearch
[root@node1 local]# jps
28516 Jps
12072 Elasticsearch
1.配置 ElasticSearch,使得HTTP对外提供服务
node1 上面配置
[root@node1 ]# vim config/elasticsearch.yml
# 增加新的参数,这样head插件可以访问es。设置参数的时候:后面要有空格
http.cors.enabled: true
http.cors.allow-origin: "*"
2.修改head插件配置文件
[root@node1 elasticsearch-head-master]# vim Gruntfile.js
connect: {
server: {
options: {
hostname: '0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}
修改修改连接地址:_site/app.js
[root@node1 elasticsearch-head-master]# vim _site/app.js
_node_handler: function(data) {
if(data) {
// this.prefs.set("app-base_uri", this.cluster.base_uri);
this.prefs.set("app-base_uri" )|| "http://133.1.11.39:9200";
if(data.version && data.version.number)
this.cluster.setVersion(data.version.number);
3.启动elasticsearch,head
[root@node1 bin]# ./elasticsearch -d #分别启动3个节点
[root@node1 elasticsearch-head-master]# nohup grunt server &
4.注意坑
如果出现集群无法链接
请注意删除node1 下面/usr/local/node1/data 下面的目录,不然造成数据不统一 不能呢链接head 插件