1. 下载Elasticsearch、Kibana、IK分词器
注意:es、kibana、ik的版本要保持一致。并且es版本与Java的jdk版本也需匹配。
1.1 es与jdk版本匹配一览表
参考网址:支持一览表 | Elastic
1.2 下载地址
注:我这里版本都是选择7.8.0,根据自己环境下载
(1)Elasticsearch:Download Elasticsearch | Elastic
(2)Kibana:Download Kibana Free | Get Started Now | Elastic
打包好的网址:Index of: (infinilabs.com)
2. 上传文件并解压
2.1 使用xftp将文件上传到指定目录下
2.2 解压elasticsearch、kibana、ik分词器
(1)解压elasticsearch
tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz elasticsearch-7.8.0
(2)解压kibana
tar -zxvf kibana-7.8.0-linux-x86_64.tar.gz
修改文件名:
mv kibana-7.8.0-linux-x86_64 kibana-7.8.0
(3)解压ik分词器
注:ik分词器要解压到elasticsearch-7.8.0的plugins目录中。解压后,重启es没问题,表示安装成功,验证可以看第7条(安装和验证ik分词器)
首先进入elasticsearch-7.8.0的plugins目录,创建ik目录
将elasticsearch-analysis-ik-7.8.0.zip移动到ik目录下:
mv /opt/bigmw/es/elasticsearch-analysis-ik-7.8.0.zip /opt/bigmw/es/elasticsearch-7.8.0/plugins/ik/
直接解压即可:
unzip elasticsearch-analysis-ik-7.8.0.zip
3. 创建普通用户,供es使用
注:出于安全考虑,elasticsearch默认不允许以root账号运⾏,, 所以要创建一个ES专属的普通用户es
3.1 创建elastic用户
创建用户名:sudo useradd elastic
设置密码:sudo passwd elastic
输入命令验证切换用户:su elastic
3.2 给创建的elastic用户赋权
(1)切换回root用户:su root
(2)输入命令赋权:
chown -R elastic:elastic /opt/bigmw/es/elasticsearch-7.8.0/
(3)给elastic用户赋予sudo权限
vim /etc/sudoers
在文件中的root ALL=(ALL) ALL新增elastic ALL=(ALL) ALL
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
elastic ALL=(ALL) ALL
4. 运行的前置配置操作
4.1 vim /etc/security/limits.conf
(1)编辑文件
vim /etc/security/limits.conf
(2)添加配置
每个进程可以打开的文件数的限制
elastic soft nofile 65536
elastic hard nofile 65536
4.2 vim /etc/security/limits.d/20-nproc.conf
(1)编辑文件
vim /etc/security/limits.d/20-nproc.conf
(2)添加配置
每个进程可以打开的文件数的限制;操作系统级别对每个用户创建的进程数的限制
注:* 带表 Linux 所有用户名称
elastic soft nofile 65536
elastic hard nofile 65536* hard nproc 4096
4.3 修改jvm.options,配置内存大小
注:结合服务器环境的内存,进行更改(默认1g)
(1)编辑文件
jvm.options在es的config目录下
vim /opt/bigmw/es/elasticsearch-7.8.0/config/jvm.options
(2)修改配置
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space-Xms1g
-Xmx1g
4.4 配置远程连接,则设置elasticsearch.yml 文件
编辑文件,elasticsearch.yml在es的config目录下
vim /opt/bigmw/es/elasticsearch-7.8.0/config/elasticsearch.yml
elasticsearch.yml文件参考:
# ======================== Elasticsearch Configuration =========================
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: elastic-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /opt/bigmw/es/elasticsearch-7.8.0/data
#
# Path to log files:
#
path.logs: /opt/bigmw/es/elasticsearch-7.8.0/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 39200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["elastic-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#
#以下皆是跨域配置
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
#开启xpack验证(开启用户名、密码验证)
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.license.self_generated.type: basic
4.4.1 修改数据和日志目录
这里可以不用修改,如果不修改,默认放在elasticsearch根目录下
在elasticsearch-7.8.0中创建data目录,并赋予权限
mkdir data
chmod 777 data
vim编辑elasticsearch.yml
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /opt/bigmw/es/elasticsearch-7.8.0/data
#
# Path to log files:
#
path.logs: /opt/bigmw/es/elasticsearch-7.8.0/logs
4.4.2 修改绑定的ip允许远程访问
#默认只允许本机访问,修改为0.0.0.0后则可以远程访问
# 绑定到0.0.0.0,允许任何ip来访问
network.host: 0.0.0.0
4.4.3 初始化节点名称
# Use a descriptive name for the node:
#
node.name: elastic-1# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["elastic-1"]
4.4.4 修改端口号(非必须)
# Set a custom port for HTTP:
#
http.port: 39200
4.4.5 添加跨域配置
#以下皆是跨域配置
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
4.4.6 es设置密码,开启开启x-pack验证(非必须,生产建议)
需要在配置文件中开启x-pack验证, 修改config目录下面的elasticsearch.yml文件,在里面添加如下内容,并重启es.
#开启xpack验证(开启用户名、密码验证)
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.license.self_generated.type: basic
具体步骤可参考:http://t.csdnimg.cn/YlKOq
5. 切换用户elastic,运行es
(1)切换用户:su elastic
(2)先在前台运行,看看是否有异常,Ctrl + C 则程序终止
cd /opt/bigmw/es/elasticsearch-7.8.0/bin
./elasticsearch
访问:http://x.x.x.x:39200/ 出现页面,表示运行成功
(3)后台运行
#出现started时启动完成
./elasticsearch -d
(4)设置用户名与密码
进入es的安装根目录bin下,执行设置用户名和密码的命令,这里需要为4个用户分别设置密码,elastic, kibana, logstash_system,beats_system
./elasticsearch-setup-passwords interactive
访问:http://x.x.x.x:39200/ 出现页面,输入用户名密码表示运行成功(默认用户名是:elastic)
(5)关闭ES服务
#先搜索elastic,确认进程id然后kill即可
ps -ef |grep elastic
kill pid
6. 安装kibana(版本需与ES一致)
注:解压后需要先启动es再启动kibana,默认端口为5601
6.1 修改kibana.yml配置文件
6.1.1 设置中文
# Supported languages are the following: English - en , by default , Chinese - zh-CN .
#i18n.locale: "en"
i18n.locale: "zh-CN"
6.1.2 设置端口号
Kibana is served by a back end server. This setting specifies the port to use.
#server.port: 5601
server.port: 35601
6.1.3 修改绑定的ip,允许远程访问
# To allow connections from remote users, set this parameter to a non-loopback address.
#server.host: "localhost"
server.host: "0.0.0.0"
6.1.4 设置es的主机地址
# The URLs of the Elasticsearch instances to use for all your queries.
elasticsearch.hosts: ["http://localhost:39200"]
6.1.5 设置es的用户名密码
# is proxied through the Kibana server.
elasticsearch.username: "kibana_system"
elasticsearch.password: "pass"
6.2 启动kibana(切换到elastic用户)
(1)进入kibana安装 bin目录
cd ./bin/
(2)前台启动 (关闭服务 关闭窗口 或者ctrl+c)
./kibana
(3)后台启动
nohup ./bin/kibana &
(4)关闭服务
根据端口查进行查找:lsof -i:35601 , 然后 kill掉
7、安装和验证ik分词器
注:ik分词器要解压到elasticsearch-7.8.0的plugins目录中。解压后,重启es。重启成功即可。
验证:进入kibana,进行验证分词
POST _analyze
{
"analyzer": "ik_smart",
"text": "我是中国人"
}
POST _analyze
{
"analyzer": "ik_max_word",
"text": "我是中国人"
}