配置/etc/hosts,ntp服务,免密码登录,关闭防火墙这里不做详细说明。
安装java环境
[root@manager ~]# mkdir /usr/java
[root@manager ~]# cd /opt/
[root@manager hadoop]# tar xvf jdk-8u91-linux-x64.tar.gz -C /usr/java
编辑"/etc/profile"或者“.bash_profile”文件,在后面添加Java的"JAVA_HOME"、"CLASSPATH"以及"PATH"内容如下:
vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_91
export PATH=$PATH:$JAVA_HOME/bin
rm -rf /etc/alternatives/java ; ln -s /usr/java/jdk1.8.0_91/bin/java /etc/alternatives/java
1. Java安装包和环境变量拷贝到其他机器上
[root@manager opt]# for i in {31,32,33,34}; do scp -r /usr/java/ [email protected]$i:/usr/java/; done
for i in {31,32,33,34}; do scp -r /etc/profile [email protected]$i:/etc/ ; done
所有机器都执行
source /etc/profile
2. 添加用户useradd elasticsearch
[root@namenode01 opt]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.0.2.zip
[root@namenode01 opt]# unzip elasticsearch-5.0.2.zip
ln -sv /opt/elasticsearch-5.0.2 /usr/local/elasticsearch
3. 配置环境变量
[root@es01 opt]# cat /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_91
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:/opt/elasticsearch-5.0.2/bin
export ES_HOME=/opt/elasticsearch-5.0.2
[root@es01 ~]# source /etc/profile
4. 创建相应的目录及修改相应的权限
[root@es01 opt]# mkdir -pv /data1/es5/{data,logs}
[root@es01 opt]# chmod 777 -R /data1/es5/
[root@es01 opt]# chown -R elasticsearch.elasticsearch /opt/elasticsearch-5.0.2
[root@es01 opt]#chown -R elasticsearch.elasticsearch /usr/local/elasticsearch
5. 修改配置文件,其他节点只需修改黄色的部分
[root@es01 opt]# vi /opt/elasticsearch-5.0.2/config/elasticsearch.yml
cluster.name: es5-cluster
node.name:
es01
path.data: /data1/es5/data
path.logs: /data1/es5/logs
network.host:
10.10.1.137
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["10.10.1.137","10.10.1.138","10.88.4.139"]
discovery.zen.minimum_master_nodes: 3
5. 修改系统参数(ES集群节点都要操作)
vi /etc/security/limits.conf
elasticsearch soft nproc 32000
elasticsearch hard nproc 32000
elasticsearch soft nofile 65536
elasticsearch hard nofile 65536
[root@es01 ~]# vi /etc/sysctl.conf
fs.file-max=65536
vm.max_map_count=262144
[root@es01 ~]# sysctl -p
6. 启动ES服务
[root@es01 ~]#su - elasticsearch -c "/opt/elasticsearch-5.0.2/bin/elasticsearch >/dev/null 2>&1 &"
或者如下命令启动
[root@es01 ~]# su - elasticsearch
[elasticsearch@es01 ~]$ source /etc/profile
[elasticsearch@es01 ~]$ cd /opt/elasticsearch-5.0.2/bin/
[elasticsearch@es01 bin]$ ./elasticsearch
页面展现如下图http://10.10.1.137:9200/说明已安装成功
[root@es01 ~]# curl 10.88.4.137:9200
{
"name" : "es01",
"cluster_name" : "es5-cluster",
"cluster_uuid" : "I4xvX-yPS4Oi2ADloZTf4w",
"version" : {
"number" : "5.0.2",
"build_hash" : "f6b4951",
"build_date" : "2016-11-24T10:07:18.101Z",
"build_snapshot" : false,
"lucene_version" : "6.2.1"
},
"tagline" : "You Know, for Search"
}
安装部署head
1. 安装git,需要从github上面下载代码,因此先要安装git
[root@es02 ~]#yum -y install git
安装完成后,就可以直接下载代码了:
[root@es02 ~]#cd /usr/local/
[root@es02 local]#git clone git://github.com/mobz/elasticsearch-head.git
[root@es02 local]# chown -R elasticsearch.elasticsearch /usr/local/elasticsearch-head
[root@es02 local]#cp -r /usr/local/elasticsearch-head /opt/elasticsearch-5.0.2/plugins/head
2. 安装node
由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。(npm可以理解为maven)
去官网下载nodejs,https://nodejs.org/en/download/
wget https://nodejs.org/dist/v6.9.3/node-v6.9.3-linux-x64.tar.xz
[root@es02 opt]# yum -y install xz
[root@es02 opt]# xz -d node-v6.9.3-linux-x64.tar.xz
[root@es02 opt]# tar xf node-v6.9.3-linux-x64.tar
[root@es02 opt]#vi /etc/profile
set node environment
export NODE_HOME=/opt/node-v6.9.3-linux-x64
export PATH=$PATH:$NODE_HOME/bin
[root@es02 ~]# source /etc/profile
[root@es02 node-v6.9.3-linux-x64]# echo $NODE_HOME
/opt/node-v6.9.3-linux-x64
[root@es02 node-v6.9.3-linux-x64]# node -v
v6.9.3
[root@es02 node-v6.9.3-linux-x64]# npm -v
3.10.10
[root@es02 node-v6.9.3-linux-x64]# npm install -g grunt-cli
执行npm install安装下载依赖包
[root@es02 local]#cd elasticsearch-head
[root@es02 elasticsearch-head]# npm install
3. 安装grunt
grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.0里的head插件就是通过grunt启动的。因此需要安装一下grunt:
在elasticsearch-head目录下node_modules/grunt下如果没有grunt二进制程序,需要执行
[root@es02 ~]#cd /usr/local/elasticsearch-head/node_modules/grunt
[root@es02 grunt]#npm install grunt --save
4. 安装完成后检查一下:
[root@es02 elasticsearch-head]# grunt --version
grunt-cli v1.2.0
grunt v1.0.1
5. 修改head源码
由于head的代码还是2.6版本的,直接执行有很多限制,比如无法跨机器访问。因此需要用户修改两个地方:
1) 修改服务器监听地址
目录: vi /opt/elasticsearch-5.0.2/plugins/head/Gruntfile.js
connect: {
server: {
options: {
port: 9100,
hostname: '*',
base: '.',
keepalive: true
}
}
}
增加hostname属性,设置为*
2) 修改连接地址:
目录: vi /opt/elasticsearch-5.0.2/plugins/head/_site/app.js
修改head的连接地址:
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://
10.10.1.138:9200";
6. 运行head
1) 首先开启5.0 ES(三台机器都执行,若前面执行过这部就不用操作了)
[root@es02 opt]# su - elasticsearch -c "/opt/elasticsearch-5.0.2/bin/elasticsearch &"
2) 启动nodejs
[root@es02 elasticsearch-head]# /usr/local/elasticsearch-head/node_modules/grunt/bin/grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
访问:http://10.10.1.138:9100/
启动报错安装这些组件:
npm install grunt-contrib-clean grunt-contrib-concat grunt-contrib-watch grunt-contrib-connect grunt-contrib-copy grunt-contrib-jasmine --save