一、安装elasticsearch7.6
1. 华为镜像下载
Index of elasticsearch-localhttps://mirrors.huaweicloud.com/elasticsearch/
2.新建用户
es不能使用root启动,必须创建新用户
#1).创建用户组
[root@localhost ~]# groupadd elasticsearch
#2).创建用户并设置密码
[root@localhost ~]# useradd daliues
[root@localhost ~]# passwd daliues
#3).把用户daliues 添加到 elasticsearch 用户组
[root@localhost ~]# usermod -G elasticsearch daliues
#4).给新用户设置sudo权限
#为了让普通用户有更大的操作权限,我们一般都会给普通用户设置sudo权限,方便普通用户的操作
[root@localhost ~]# visudo
#在root ALL=(ALL) ALL 一行下面 添加 daliues 用户
#如下: daliues ALL=(ALL) ALL
#5).创建es文件夹,下载es安装包,并解压
[root@localhost es]# mkdir /usr/local/es
[root@localhost es]# cd /usr/local/es
3. 下载Elasticsearch
这里直接通过命令下载,也可以通过Elasticsearch官网下载,(本文以Elasticsearch7.6版本示例,请提前配置好java环境)
//下载Elasticsearch安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz
4. 解压安装包
tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz
5. 设置目录所有者
#把es文件夹归属改为daliues
[root@localhost es]# chown daliues elasticsearch-7.6.2 -R
切换用户为daliues
[daliues@localhost es]$ su daliues
#输入密码
密码:
6. 配置
1).新建两个文件夹用来存日志和数据
[daliues@localhost config]$ mkdir -p /usr/local/es/elasticsearch-7.11.2/log
[daliues@localhost config]$ mkdir -p /usr/local/es/elasticsearch-7.11.2/data
2).
修改elasticsearch.yml 配置文件
//1.进去elasticsearch的config目录下
cd elasticsearch-7.6.2/config/
//2.修改elasticsearch.yml文件
vim elasticsearch.yml
//3.在文件末尾处添加如下配置 注意每个配置前的一个空格、每个配置:后的一个空格
network.host: 0.0.0.0 #可远程访问
node.name: es-node01 #节点名称 这个与下面一点一定要配,不然即使启动成功也会操作超时或发生master_not_discovered_exception
cluster.initial_master_nodes: ["es-node01"] #发现当前节点名称
http.port: 9200 #端口号
http.cors.allow-origin: "*" #以下皆是跨域配置
http.cors.enabled: true
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true
7. 系统相关配置
1、 新增内容
vi /etc/security/limits.conf
然后
xxx(你的非root用户名) soft nofile 65536
xxx(你的非root用户名) hard nofile 65536
xxx(你的非root用户名) soft nproc 4096
xxx(你的非root用户名) hard nproc 4096
2、修改limits.d下配置
cd /etc/security/limits.d
然后
##这两行是原本的内容
* soft nproc 4096
root soft nproc unlimited
## 修改
#将*号改成用户名
xxx(你的非root用户名) soft nproc 4096
root soft nproc unlimited
3、添加内容
vi /etc/sysctl.conf
然后在文末添加如下内容
vm.max_map_count = 655360
保存退出以后再在 root用户状态下
执行一下内容:
sysctl -p
二、Ik分词器插件安装
安装前我们先来看一下安装前后的区别
安装前: 用命令行执行以下命令
curl -H "Content-Type: application/json" -XPOST http://localhost:9200/_analyze -d'
{
"text":"中华人民共和国国歌"
}'
返回如下: 可以看到他按照每个字来分割了,这样很明显是不合理的,因为这样做分词搜索,只要有一个字是匹配的就会返回
安装后: 执行以下命令
curl -H "Content-Type: application/json" -XPOST http://localhost:9200/_analyze -d'
{
"analyzer":"ik_smart", //这里是指定使用ik分词器分词
"text":"中华人民共和国国歌"
}'
返回如下: 可以看到按照了词组来分词
ik分词安装
//1.下载ik分词器
https://github.com/medcl/elasticsearch-analysis-ik/releases 进去下载选择与elasticsearch对应的版本
//2.进入elasticsearch安装目录下的plugins下,创建ik文件夹
cd elasticsearch-7.6.2/plugins/
mkdir ik
//3.将下载好的zip包放入ik文件夹下,执行解压
如:unzip elasticsearch-analysis-ik-7.2.0.zip
//4.重启elasticsearch服务
//5.验证
浏览器输入http://xx.xx.xx.xx:9200/_cat/plugins
返回如下: 就成功了
三、 可视化工具kibana安装
//1.下载对应elasticsearch版本的kibana
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.3.2-linux-x86_64.tar.gz
//2.解压
tar -zxvf kibana-6.3.2-linux-x86_64.tar.gz
//3.修改配置文件
cd kibana-7.2.0-linux-x86_64/config/
vim kibana.yml
//4.将下列注释打开
server.port: 5601 #端口号
server.host: "0.0.0.0" #远程访问
elasticsearch.url: "http://xxxx:9200" #elasticsearch地址
kibana.index: ".kibana" #索引规则配置 打开注释即可
//启动
cd kibana-7.2.0-linux-x86_64/bin/
./kibana
浏览器输入:http://xxx:5601 访问即可,至于对elasticsearch的操作这里就不在阐述了
到这里介绍就完啦,以后再给大家介绍使用springboot整合elasticsearch的相关操作以及elasticsearch和mysql的数据同步
参考:
--------------------------------------
1、Elasticsearch 7.6.2 安装方法 及常见错误以及详细配置介绍
2、liunx下安装elasticsearch7.6、ik分词器以及kibana可视化工具
3、ElasticSearch教程 - 安装ElasticSearch-7.11.2,单节点部署,集群部署
4、ES报错Native controller process has stopped - no new native processes can be started