1.elasticsearch相关链接
ELK官网:https://www.elastic.co/
ELK官网文档:https://www.elastic.co/guide/index.html
ELK中文手册:https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html
ELK中文社区:https://elasticsearch.cn/
ELK-API : https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html
2.确定好安装路径
我装在/usr/local/
3.下载
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-linux-x86_64.tar.gz
4.解压
tar -xvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C
5.修改配置
cd /usr/local/elasticsearch-7.8.0/
vim config/elasticsearch.yml
6.yml配置文件内容
#设置ip地址,任意网络均可访问
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
node.name: "node-1"
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
cluster.initial_master_nodes: ["node-1"]
# # 开启跨域访问支持,默认为false
http.cors.enabled: true
# 跨域访问允许的域名地址,(允许所有域名)以上使用正则
http.cors.allow-origin: "*"
http.max_content_length: 200mb
bootstrap.system_call_filter: false
7.修改jvm启动参数
vim /usr/local/elasticsearch-7.8.0/config/jvm.options
#根据自己机器内存情况将jvm.options这两个配置修改了
-Xms256m
-Xmx256m
8.修改sysctl.conf
vim /etc/sysctl.conf
#修改一个进程在VMAS(虚拟内存区域)创建内存映射最大数量
vm.max_map_count=655360
9.配置生效
sysctl -p
10.创建新用户
#因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户elsearch
useradd es
#为用户赋elasticsearch-7.8.0这个文件的操作权限
chown -R es:es /usr/local/elasticsearch-7.8.0/
su - es
cd /usr/local/elasticsearch-7.8.0/bin
./elasticsearch
#后台运行
./elasticsearch -d
#启动成功后通过ip加上端口号9200就可以访问了,记得开启9200端口
如果遇到报错,参考
https://www.cnblogs.com/socketqiang/p/11363024.html
https://blog.youkuaiyun.com/qq_43655835/article/details/104637625
其他问题自行百度
11.设置开机自启
cd /etc/init.d
vim /etc/init.d/elasticsearch
复制以下内容
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
#jdk相关路径,这些配置我不需要
#export JAVA_HOME=/usr/java/jdk1.8
#export JAVA_BIN=/usr/java/jdk1.8/bin
#export PATH=$PATH:$JAVA_HOME/bin
#export CLASSPATH=.:$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
#export JAVA_HOME JAVA_BIN PATH CLASSPATH
case "$1" in
start)
#es的启动账号名
su 你的启动用户名<<!
#es的安装路径
cd /usr/local/elasticsearch-7.8.0
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
stop)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped"
;;
restart)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped"
su 你的启动用户名<<!
cd /usr/local/elasticsearch-7.8.0
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
退出保存即可
#为脚本增加执行权限
chmod +x elasticsearch
#开机启动
chkconfig --add elasticsearch
#重启服务器
reboot
访问http://IP:9200查看是否成功开机启动
12.安装分词器elasticsearch-analysis-ik
如果没有安装分词器,后期使用可能报错
{“error”:{“root_cause”:[{“type”:“mapper_parsing_exception”,“reason”:“analyzer [ik_max_word] not found for field [campaignTarget]”}],“type”:“mapper_parsing_exception”,“reason”:“Failed to parse mapping [_doc]: analyzer [ik_max_word] not found for field [campaignTarget]”,“caused_by”:{“type”:“mapper_parsing_exception”,“reason”:“analyzer [ik_max_word] not found for field [campaignTarget]”}},“status”:400}
-
根据elasticsearch版本下载对应版本分词器
#各个版本分词器 https://github.com/medcl/elasticsearch-analysis-ik/releases
-
进入plugin目录
#plugins前面的路径是我的安装目录 cd /usr/local/elasticsearch-7.8.0/plugins #创建ik目录 mkdir ik # 上传或直接下载elasticsearch-analysis-ik-7.8.0.zip后,解压 # https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.8.0/elasticsearch-analysis-ik-7.8.0.zip unzip elasticsearch-analysis-ik-7.8.0.zip #重启elasticsearch就可以