文章目录
1. ES安装
1.1 下载
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.9.1-linux-x86_64.tar.gz
1.2 安装
# 解压到/opt/local目录
tar -zxvf elasticsearch-8.9.1-linux-x86_64.tar.gz
mv elasticsearch-8.9.1 elasticsearch
1.3 配置
1.3.1 修改es的配置
把原来的elasticsearch.yml备份下,然后重新建立文件。
mv /opt/local/elasticsearch/elasticsearch.yml /opt/local/elasticsearch/elasticsearch.yml_bak
vim /opt/local/elasticsearch/elasticsearch.yml
新的elasticsearch.yml文件中只填写以下内容:
node.name: es_node1
network.host: 192.168.80.250
path.data: /opt/local/elasticsearch/data
path.logs: /opt/local/elasticsearch/logs
http.port: 9200
cluster.initial_master_nodes: ["es_node1"]
xpack.security.enabled: false
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
enabled: false
keystore.path: certs/http.p12
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
1.3.2 修改jvm.options
-Xms512m
-Xmx512m
1.3.3 修改/etc/security/limits.conf
# End of file
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
linux执行下列命令:
vim /etc/sysctl.conf
增加以下内容,这样重启后仍然生效:
vm.max_map_count=655360
执行以下命令,是临时修改的,重启后会失效的。
sysctl -w vm.max_map_count=262144
sysctl -a|grep vm.max_map_count
1.3.4 新增账户
es禁止从root账号启动,这里创建es账号
useradd es
passwd es
chown es:es -R /opt/local/elasticsearch
1.4. 启动
-d表示后台启动
su es
./bin/elasticsearch -d
首次启动时,显示如下:
在浏览器打开 http://192.168.80.250:9200/
2. 安装Kibana
2.1 kibana下载
https://artifacts.elastic.co/downloads/kibana/kibana-8.9.1-linux-x86_64.tar.gz
2.2 解压安装
tar -zxvf kibana-8.9.1-linux-x86_64.tar.gz
# 重命名
mv kibana-8.9.1 kibana
2.3 配置
cd /config
mv kibana.yml kibana.yml_bak
新建kibana.yml文件,输入以下内容项(注意冒号后面都需要有空格):
server.port: 5601
#0.0.0.0支持外网所有主机访问
server.host: 0.0.0.0
#配置elasticsearch服务器地址,开启Xpack时用https
elasticsearch.hosts: ["http://192.168.80.250:9200"]
i18n.locale: "zh-CN"
2.4 启动
同样kibana不能用root启动,所以修改权限和所有者为es
#修改用户和权限
chown -R es:es /opt/local/kibana/
#启动
./bin/kibana
在浏览器打开 http://192.168.80.250:5601/
3. 安装IK分词器
分词器是es中一个组件,它会将一段文本按照一定的逻辑,分析成多个词语,同时对这些词语进行常规化的一种工具;
ES会将text格式的字段按照分词器进行分词,并编排成倒排索引,这样es的查询就非常快
3.1 下载
https://github.com/medcl/elasticsearch-analysis-ik/releases
3.2 安装
在/opt/local/elasticsearch/plugins/目录下创建ik目录。
将解压后的文件放到这个ik目录
3.3 配置
修改文件:
/opt/local/elasticsearch/plugins/ik/plugin-descriptor.properties
将以下2个配置,修改为自己安装的elasticsearch对应的版本号,不然会报错。
version=8.9.1
elasticsearch.version=8.9.1
然后修改权限和所有者为es。
chown es:es -R ik
最后重启es和kibana
4. 测试
找到开发工具:
测试中文分词
5. IK分词器的扩展
编辑config目录下的IkAnalyzer.cfg.xml文件:
<?xml version="1.0" encoding="UTF-8"?> IK Analyzer 扩展配置6.docker版本安装
6.1 安装es
# 拉取镜像
docker pull elasticsearch:7.17.7
# 创建映射目录
mkdir -p /docker/elasticsearch
# 修改映射目录权限
chmod 777 -R /docker/elasticsearch
# 创建docker网络
docker network create es-net
# 启动
docker run -d \
--name es \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-e "discovery.type=single-node" \
-v /docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /docker/elasticsearch/data:/usr/share/elasticsearch/data \
-v /docker/elasticsearch/logs:/usr/share/elasticsearch/logs \
--privileged \
--network es-net \
-p 9200:9200 -p 9300:9300 \
elasticsearch:7.17.7
# 查看状态
docker ps -a
# 查看日志
docker logs [es_container_name]
6.2 安装kibana
#拉取镜像
docker pull kibana:7.17.7
#启动
docker run -d --name kibana \
-e ELASTICSEARCH_HOSTS=http://es:9200 \
--network=es-net \
-p 5601:5601 kibana:7.17.7
6.3 安装IK分词插件
#下载
https://github.com/medcl/elasticsearch-analysis-ik/tree/v7.17.7
将插件解压后,保存到/docker/elasticsearch/plugins/ik/ 目录