下载elasticsearch以及spring-data-elasticsearch
elasticsearch | spring-data-elasticsearch |
---|---|
6.2.4 | 3.1.10.RELEASE |
elasticsearch 下载地址
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/zip-targz.html
LINUX下执行如下命令
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz.sha512
shasum -a 512 -c elasticsearch-6.2.4.tar.gz.sha512
tar -xzf elasticsearch-6.2.4.tar.gz
cd elasticsearch-6.2.4/
shasum安装方式为:
yum install perl-Digest-SHA
spring-data-elasticsearch源码下载以及生成jar包
https://github.com/spring-projects/spring-data-elasticsearch/releases
mvn package
启动elasticsearch
配置elasticsearch.yml文件
打开config文件夹下的elasticsearch.yml文件,配置相关信息如下:
cluster.name: panG-es #es集群名称
node.name: es-node1 #es节点名称,每个节点的名称不能相同
node.master: true #指定该节点是否有资格被选举成为master,默认是true
node.data: true #指定该节点是否存储索引数据,默认为true。
network.host:172.20.4.69 #节点的ip地址
#设置节点间交互的tcp端口,默认是9300。
transport.tcp.port: 9300
#设置是否压缩tcp传输时的数据,默认为false,不压缩。
transport.tcp.compress: true
设置对外服务的http端口,默认为9200。
http.port: 9200
#设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点
discovery.zen.ping.unicast.hosts: ["ip1:port1","ip2:port2"]
#设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(N/2+1)
discovery.zen.minimum_master_nodes: 1
#设置集群中自动发现其它节点时ping连接超时时间,默认为3秒,对于比较差的网络环境可以高点的值来防止自动发现时出错。
discovery.zen.ping.timeout: 3s
#设置是否打开多播发现节点,默认是true。
discovery.zen.ping.multicast.enabled: true
#如果要使用head,那么需要设置下面2个参数,使head插件可以访问es
http.cors.enabled: true
http.cors.allow-origin: "*"
#这是Centos6不支持SecComp,而ES默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
添加用户组以及用户以及启动
[root@localhost home]# groupadd es
[root@localhost home]# useradd es -g es -p 1
[root@localhost home]# cd /data
[root@localhost home]# chown -R es:es elasticsearch-6.2.4/
[root@localhost home]# su es
[es@localhost bin]# ./elasticsearch -d
可能需要开放端口
iptables -I INPUT -p tcp --dport 9200 -j ACCEPT
可能需要设置宽限策略
# vim /etc/security/limits.conf
追加
* soft nofile 65536
* hard nofile 65536
# vim /etc/sysctl.conf
追加
vm.max_map_count=655360
# sysctl -p
可能需要安装JDK1.8
[root@localhost jvm]# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
[root@localhost jvm]# tar -zxvf jdk-8u131-linux-x64.tar.gz
添加环境变量
[root@localhost jvm]# vim /etc/profile
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_131
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
[root@localhost jvm]# source /etc/profile
验证是否启动成功
浏览器访问ip:port
安装head插件
前置条件:安装node.js npm
# wget https://nodejs.org/dist/v10.9.0/node-v10.9.0-linux-x64.tar.xz // 下载
# tar xf node-v10.9.0-linux-x64.tar.xz // 解压
# cd node-v10.9.0-linux-x64/ // 进入解压目录
# ./bin/node -v // 执行node命令 查看版本
# vim /etc/profile //修改profile文件,配置nodejs环境变量
# source /etc/profile
前置条件:安装grunt
npm install -g grunt-cli
npm install phantomjs-prebuilt@2.1.16 --ignore-scripts
下载head插件
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
unzip master.zip
cd elasticsearch-head-master
npm install
npm太慢建议使用淘宝镜像:
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install
可能需要安装unzip子命令
yum -y install bzip2
修改配置文件
1.修改Gruntfile.js
cd /usr/elasticsearch/elasticsearch-head
vim Gruntfile.js
添加访问端口
server: {
options: {
hostname: '*',
port: 9100,
base: '.',
keepalive: true
}
}
2.修改app.js以设置es默认连接地址
cd /usr/elasticsearch/elasticsearch-head/_site
vi app.js
#this.base_uri = this.config.base_uri;
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://ip:port";
3.修改es配置文件elasticsearch.yml以允许跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
4.启动head插件
grunt server
netstat -tunlp |grep 9100
搭建集群
跨机器拷贝elasticsearch压缩包
scp root@ip:/data/elasticsearch.tar.gz /data/elasticsearch