安装jdk
- 安装es前需要先安装jdk8
下载jdk:jdk-8u121-linux-x64.tar.gz 放在目录/usr/lcoal/
下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html - 进入/usr/lcoal/解压
cd /usr/local
tar -zxvf jdk-8u121-linux-x64.tar.gz
- 修改 jdk1.8.0_121文件名为jdk8
mv jdk1.8.0_121 jdk8
- 修改/etc/profile,添加java变量
vim /etc/profile
#添加变量
JAVA_HOME=/usr/local/jdk8
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
- 重启配置文件
source /etc/profile
- 测试是否生效
[root@cn2 local]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
elasticsearch安装
添加用户
注意:5.0开始,ElasticSearch 安全级别提高了,不允许采用root帐号启动,所以我们要添加一个用户
- 创建elasticsearch用户组
[root@cn2 local]# groupadd elasticsearch
- 创建用户es并设置密码es
[root@cn2 local]# useradd es
[root@cn2 local]# passwd es
Changing password for user es.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
- 用户es添加到elasticsearch用户组
[root@cn2 local]# usermod -G elasticsearch es
- 设置sudo权限
[root@cn2 local]# visudo
在root ALL=(ALL) ALL 一行下面
添加es用户 如下:
es ALL=(ALL) ALL
- 切换到es用户操作
su es
安装es
- 下载安装包elasticsearch-6.2.4.tar.gz放入目录/usr/local
下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-2-4 - 解压安装包
cd /usr/local
tar -zxvf elasticsearch-6.2.4.tar.gz
- 修改用户权限
chown -R es:elasticsearch elasticsearch-6.2.4
- 切换es用户
su es
- 修改config/elasticsearch.yml
cluster.name: es-cluster
node.name: ali2
node.master: true
node.data: true
path.data: /workspace/db-data/elasticsearch-6.2.4/data
path.logs: /workspace/db-data/elasticsearch-6.2.4/logs
network.host: 0.0.0.0
network.publish_host: 39.100.113.101
http.port: 9500
http.cors.enabled: true
http.cors.allow-origin: "*"
transport.tcp.port: 9300
- 修改/workspace/db-data/elasticsearch-6.2.4/权限
cd /workspace/db-data/
chown -R es:elasticsearch elasticsearch-6.2.4
- 启动
cd /usr/local/elasticsearch-6.2.4
./bin/elasticsearch
- 在浏览器中输入http://39.100.113.101:9500/查看结果
{
"name": "ali2",
"cluster_name": "es-cluster",
"cluster_uuid": "Y_pDP3IBQ2iNGlyuInfNzQ",
"version": {
"number": "6.2.4",
"build_hash": "ccec39f",
"build_date": "2018-04-12T20:37:28.497551Z",
"build_snapshot": false,
"lucene_version": "7.2.1",
"minimum_wire_compatibility_version": "5.6.0",
"minimum_index_compatibility_version": "5.0.0"
},
"tagline": "You Know, for Search"
}
启动过程中可能会报错,我遇到的报错如下:
bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: bootstrap checks failed
max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方法
- 修改/etc/sysctl.conf
切换回root 用户 执行
su root
vim /etc/sysctl.conf
在文件最后面添加内容:
vm.max_map_count=262144
保存退出后,使用sysctl -p 刷新生效
- 修改/etc/security/limits.conf
vim /etc/security/limits.conf
添加以下内容:
es为上面创建的用户名
es hard nofile 65536
es soft nofile 65536
es soft nproc 4096
es hard nproc 4096
退出es用户重新登录后启动
安装elasticsearch-analysis-ik分词插件
- 下载分词插件 https://github.com/medcl/elasticsearch-analysis-ik/releases
- 解压到文件夹为ik 上传至 elasticsearch-6.2.4/plugins 中
- 进入plugin/analysis-ik/config,修改IKAnalyzer.cfg.xml指向自定义词库
- 重启elasticsearch即可