1. 分布环境:
192.168.66.217
192.168.66.218
192.168.66.219
安装路径:/opt/soft/elasticsearch/elasticsearch-5.3.3
1.1、新建用户设置密码
由于elasticsearch不可以用root用户操作,所以需要新建一个用户
useradd zgg //新建用户
echo zgg | passwd --stdin zgg //设置密码
1.2、创建es目录
mkdir -p /opt/soft/elasticsearch/ (注意:此时的目录权限属于root,无法使用普通用户创建)
1.3、更改目录持有者
chown -R zgg:zgg elasticsearch/
1.4、上传并解压
切换zgg用户将elasticsearch5.3.3.zip上传到共享目录,并解压到上一步的新建目录。
unzip elasticsearch-5.3.3.zip -d /opt/soft/elasticsearch/
2、修改es配置项
进入目录
cd /opt/soft/elasticsearch/elasticsearch-5.3.3/config
2.1、cluster
---------------------------------- Cluster -----------------------------------
Use a descriptive name for your cluster:
cluster.name: zgg-es
2.2、Node
------------------------------------ Node ------------------------------------
Use a descriptive name for the node:
node.name: es-node1
2.3、path&
----------------------------------- Paths ------------------------------------
Path to directory where to store the data (separate multiple locations by comma):
path.data: /home/elasticsearch/data
Path to log files:
path.logs: /home/elasticsearch/log
需要在home路径下新建文件夹,存放elasticsearch数据和日志
2.4、network
---------------------------------- Network -----------------------------------
Set the bind address to a specific IP (IPv4 or IPv6):
network.host: 192.168.66.217
Set a custom port for HTTP:
http.port: 9200
2.5、末尾增加防脑裂
discovery.zen.ping.unicast.hosts: [“192.168.66.217”,“192.168.66.218”, “192.168.66.219”]
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s
增加新的参数,这样head插件可以访问es
http.cors.enabled: true
http.cors.allow-origin: “*”
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
3、修改系统配置项
使用root用户,设置内核参数和资源参数
3.1设置内核参数
vi /etc/sysctl.conf
vi /usr/lib/sysctl.d/00-system.conf
增加下面的内容
fs.file-max=65536 //系统级别能够打开文件句柄的数量
vm.max_map_count=655360
(centos7改下面这个值)
vm.max_map_count=262144
3.2设置资源参数
vi /etc/security/limits.conf
增加配置
- soft nofile 65536
- hard nofile 65536
- soft nproc 65536
- hard nproc 65536
//解释说明:
soft nproc: 可打开的文件描述符的最大数(软限制)
hard nproc: 可打开的文件描述符的最大数(硬限制)
soft nofile:单个用户可用的最大进程数量(软限制)
hard nofile:单个用户可用的最大进程数量(硬限制)
3.3修改进程
#ulimit -u 2048 //进程级别能够打开文件句柄的数量
3.4修改90-nproc.conf配置文件
vi /etc/security/limits.d/90-nproc.conf (centos6.x)
vi /etc/security/limits.d/20-nproc.conf(centos7.x)
#修改如下内容:
- soft nproc 1024
#修改为 - soft nproc 2048 //可打开文件描述符的数量
Centos7命令:(不用做修改)
vi /etc/security/limits.d/20-nproc.conf
3.5 加载环境变量
sysctl -p //使上述配置生效,类似加载环境变量
3.6 设置存储目录读写权限
chmod -R 777 elasticsearch/
elasticsearch下面有data和logs
3.7 设置存储目录读写权限
cd /opt/soft/elasticsearch-5.3.3/bin
vim elasticsearch.in.sh
ES_MIN_MEM=16g
ES_MAX_MEM=16g
ES_CLASSPATH=“
E
S
H
O
M
E
/
l
i
b
/
e
l
a
s
t
i
c
s
e
a
r
c
h
−
5.3.3.
j
a
r
:
ES_HOME/lib/elasticsearch-5.3.3.jar:
ESHOME/lib/elasticsearch−5.3.3.jar:ES_HOME/lib/*”
JAVA_OPTS=“
J
A
V
A
O
P
T
S
−
X
X
:
+
U
s
e
G
1
G
C
"
J
A
V
A
O
P
T
S
=
"
JAVA_OPTS -XX:+UseG1GC" JAVA_OPTS="
JAVAOPTS−XX:+UseG1GC"JAVAOPTS="JAVA_OPTS -XX:MaxGCPauseMillis=200”
4、分发
其他机器准备环境步骤做好后,将es分发给其他节点,重复上述2,3步骤,修改对应配置即可。
5、启动elasticsearch
./bin/elasticsearch -d
(执行此命令需要用zgg用户,不可以用root用户,否则会报错)
启动时指定内存16g
验证:http://ip:9200
6、安装es的head插件
6.1下载并配置nodejs
wget和xz需要提前使用yum安装
wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz
xz -d node-v6.9.5-linux-x64.tar.xz
6.2解压nodejs
tar -xvf node-v6.9.5-linux-x64.tar
6.3配置nodejs环境变量
这个步骤不能忘记,否则下一步没办法执行
6.4执行命令
npm install -g grunt-cli
npm install grunt
npm install grunt-contrib-clean grunt-contrib-concat grunt-contrib-watch grunt-contrib-connect grunt-contrib-copy grunt-contrib-jasmine
6.5修改配置文件
路径:/elasticsearch-head/_site/app.js
this.base_uri = this.config.uri || this.prefs.get(“app-base_uri”) || “修改你的es地址:http://localhost:9200”
/elasticsearch-head/Gruntfile.js
connector:{
server:{
options:{
port:9100,
//新加hosts属性:注意单引号、要结尾要加逗号
hosts:'*',
base:'.'
}
}
}
localhost
6.6启动命令:
grunt server &
6.7访问
http://localhost:9100
7、安装ik分词器
7.1下载预处理
去github上下载
https://github.com/medcl/elasticsearch-analysis-ik
使用maven编译,执行下面命令:
mvn package
7.2上传并解压
下图中,将编译后的releases包中的压缩包,上传到如下目录,ik目录需要新建。然后解压
/opt/soft/elasticsearch/elasticsearch-5.3.3/plugins/ik
7.3重启es
解压完成后,需要重启es
https://blog.csdn.net/gcc_java/article/details/79235642
elasticsearch5.0启动失败,出现如下提示:
ava HotSpot™ 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error=‘Cannot allocate memory’ (errno=12)
由于elasticsearch5.0默认分配jvm空间大小为2g,修改jvm空间分配
vim config/jvm.options
-Xms2g
-Xmx2g
修改为
-Xms512m
-Xmx512m