ElasticSearch官网: https://www.elastic.co/cn/downloads/elasticsearch
Elasticsearch相关软件各版本下载:https://elasticsearch.cn/download
2.Elasticsearch安装 2.1 配置linux系统环境
切换到root用户,编辑limits.conf 添加类似如下内容
vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
切换到root用户,进入limits.d目录下修改配置文件(CentOS7.x不用改)
vi /etc/security/limits.d/90-nproc.conf
修改如下内容:
* soft nproc 1024 修改为 * soft nproc 4096
切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
集群分发
xsync /etc/security/limits.conf xsync /etc/security/limits.d/90-nproc.conf #(Centos7.X不需要) xsync /etc/sysctl.conf
重启Linux
注意JDK版本问题,6.x可以使用JDK8版本,7.x需要JDK11
安装7.11.2时,不支持jdk8,需要jdk11
但是可以使用ES自带的jdk,修改bin/elasticsearch配置文件,添加一下内容
#配置自己的jdk11
export JAVA_HOME=/opt/module/elasticsearch/jdk
export PATH=$JAVA_HOME/bin:$PATH
#添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/opt/module/elasticsearch/jdk/bin/java"
else
JAVA=`which java`
fi
注意:这段代码必须放在脚本的最开始的位置,否则仍会报错
切换为非root用户,ES的启动不可以用root启动
解压elasticsearch-7.11.2.tar.gz到/opt/module目录下
tar -zxvf elasticsearch-7.11.2.tar.gz -C /opt/module/
修改文件名
mv elasticsearch-7.11.2 elasticsearch
在/opt/module/elasticsearch路径下创建data文件夹
mkdir data
修改配置文件/opt/module/elasticsearch/config/elasticsearch.yml
pwd /opt/module/elasticsearch/config vim elasticsearch.yml #-----------------------Cluster----------------------- cluster.name: my-application #-----------------------Node----------------------- node.name: node-01 #-----------------------Paths----------------------- path.data: /opt/module/elasticsearch/data path.logs: /opt/module/elasticsearch/logs #-----------------------Memory----------------------- bootstrap.memory_lock: false bootstrap.system_call_filter: false #-----------------------Network----------------------- network.host: 192.168.6.102 #-----------------------Discovery----------------------- discovery.zen.ping.unicast.hosts: ["192.168.1.102"] discovery.seed_hosts: ["10.10.14.91", "10.10.14.92","10.10.14.93"] # Bootstrap the cluster using an initial set of master-eligible nodes: cluster.initial_master_nodes: ["10.10.14.92"] http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-headers: Authorization xpack.security.enabled: false
参数说明:
cluster.name 如果要配置集群需要两个节点上的elasticsearch配置的cluster.name相同,都启动可以自动组成集群,这里如果不改cluster.name则默认是cluster.name=my-applicationnodename随意取但是集群内的各节点不能相同修改后的每行前面不能有空格,修改后的“:”后面必须有一个空格
修改配置文件 /opt/module/elasticsearch/config/jvm.options
修改 -Xms4g -Xmx4g 为 -Xms256m -Xmx256m
分发集群
xsync elasticsearch/ 配置中修改以下内容 node.name: node-02 network.host: 192.168.6.103 node.name: node-03 network.host: 192.168.6.1042.2.1 启动ES
ES的启动不能用root启动,需要更改elasticsearch的用户和用户组
非后台启动
bin/elasticsearch后台启动
bin/elasticsearch >/dev/null 2>&1 &测试
curl http://peng01:9200
{
"name" : "node-01",
"cluster_name" : "my-application",
"cluster_uuid" : "w9UFspEFR4-F5gLrTYMHIw",
"version" : {
"number" : "7.11.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "a9861f4",
"build_date" : "2019-01-24T11:27:09.439740Z",
"build_snapshot" : false,
"lucene_version" : "7.6.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
或者在浏览器中访问http://peng01:9200
2.2.2 停止
kill -9 进程号
ps -ef|grep elasticsearch|grep -v grep|awk '{print $2}'|xargs kill >/dev/null 2>&1
2.3 Elasticsearch操作
2.3.1 浏览器
http://peng01:9200
查看集群节点
http://peng01:9200/_cat/nodes2.3.2 Linux命令
curl -XPOST 'http://peng01:9200/SHG/_doc' -i -H "Content-Type:application/json" -d '{"name":"haha","age":"10"}'
响应:
HTTP/1.1 201 Created
Location: /test/_doc/7oozj3wBeCTltEbdYSF0
Warning: 299 Elasticsearch-6.6.0-a9861f4 "the default number of shards will change from [5] to [1] in 7.0.0; if you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template" "Sun, 17 Oct 2021 17:01:21 GMT"
content-type: application/json; charset=UTF-8
content-length: 171
{"_index":"test","_type":"_doc","_id":"7oozj3wBeCTltEbdYSF0","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":0,"_primary_term":1}
3.Kibana安装
注意kibanna的版本与ES的相同,否则kibanna可能不可用
将kibana压缩包上传到虚拟机指定目录
tar -zxvf kibana-7.11.2-linux-x86_64.tar.gz -C /opt/module/ mv kibana-7.11.2-linux-x86_64/ kibana/
修改相关配置,连接ES
vi config/kibana.yml
# Kibana is served by a back end server. This setting specifies the port to use. server.port: 5601 # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values. # The default is 'localhost', which usually means remote machines will not be able to connect. # To allow connections from remote users, set this parameter to a non-loopback address. server.host: "192.168.6.102" ... ... ... ... # The URL of the Elasticsearch instance to use for all your queries. elasticsearch.hosts: "http://192.168.6.102:9200"
启动
bin/kibana
后台启动
nohup bin/kibana > kibana.log 2>&1 &
浏览器访问
http://peng01:5601
停止Kibana
ps -ef | grep kibana | grep -v grep | awk '{print $2}'| xargs kill
Kibana的Dev_Tools
在操作窗口输入 GET _cat/nodes
各版本下载地址:https://github.com/lmenezes/cerebro/tags
4.1 将cerebo解压至指定目录 4.2 修改conf下的application.conf配置填写hosts中的IP和ES的name
启动,默认端口是9000
bin/cerebro
后台启动,默认端口是9000
nohup bin/cerebro &
后台启动修改默认端口为指定端口,如:9001
nohup bin/cerebro -Dhttp.port=9001 -Dhttp.address=0.0.0.0 &4.4 页面访问
http://cerebode的ip:9001
连接ES,http://ES的ip:9200
页面简介
5.装问题 5.1 jdk版本问题
安装7.11.2时,不支持jdk8,需要jdk11
解决方案:使用ES自带的jdk,修改bin/elasticsearch配置文件,添加一下内容
#配置自己的jdk11
export JAVA_HOME=/opt/software/elasticsearch/jdk
export PATH=$JAVA_HOME/bin:$PATH
#添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/opt/software/elasticsearch/jdk/bin/java"
else
JAVA=`which java`
fi
注意:这段代码必须放在脚本的最开始的位置,否则仍会报错
ES不能使用root启动,需要切换用户,因为之前不小心用root启动了,启动后产生的文件是root权限
解决方案:给elasticsearch.keystore赋用户
chown aiops:aiops elasticsearch.keystore
logs目录下的文件权限问题
解决方案:
sudo chown aiops:aiops logs -R6.IK分词器安装
下载对应版本的安装包
下载路径:https://github.com/medcl/elasticsearch-analysis-ik/releases
6.1 解压在/opt/module/elasticsearch/plugins下创建ik目录,将zip文件解压至该目录
mkdir ik6.2 集群分发
xsync ik/6.3 重启集群 6.4 测试
GET _analyze
{
"analyzer": "ik_max_word",
"text":"我是程序员"
}



