0%

elasticsearch安装

elasticsearch安装

导入秘钥

1
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

下载rpm包

1
wget  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.1.1-x86_64.rpm

安装

1
rpm -ivh elasticsearch-7.1.1-x86_64.rpm

这里会自动在/usr/lib/systemd/system中生成一个开机自动启动的elasticsearch.service

1
2
3
4
5
6
7
8
# 启动
systemctl start elasticsearch.service

# 开机自启
systemctl enable elasticsearch.service

# 查看状态
systemctl status elasticsearch.service

tips

在使用systemctl启动的时候可能会出现错误,可以使用journalctl来查看错误信息

1
2
3
4
5
6
7
8
9
10
#查看昨天的日志
journalctl --since yesterday
#查看今天的日志
journalctl --since today
#查看指定时间的日志
journalctl --since="2023-07-23 17:50:20"
#查看指定服务的日志
journalctl -u elasticsearch
#查看多少行日志
journalctl -n 50

单机安装

错误

启动报错: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决方法:

在/etc/sysctl.conf文件最后添加一行 vm.max_map_count=655360 添加完毕之后,执行命令:

1
sysctl -p

配置调整

1
2
3
# 默认只能本地访问,改成0.0.0.0可远程访问
network.host: 0.0.0.0
discovery.seed_hosts: ["0.0.0.0"]

验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
curl --location --request GET '192.168.1.220:9200?pretty'

{
"name": "oeTRcb8",
"cluster_name": "elasticsearch",
"cluster_uuid": "HWMo_L0QQBC2I6SKt3FWNQ",
"version": {
"number": "6.8.23",
"build_flavor": "default",
"build_type": "rpm",
"build_hash": "4f67856",
"build_date": "2022-01-06T21:30:50.087716Z",
"build_snapshot": false,
"lucene_version": "7.7.3",
"minimum_wire_compatibility_version": "5.6.0",
"minimum_index_compatibility_version": "5.0.0"
},
"tagline": "You Know, for Search"
}

分布式安装

使用一主二从模式

主配置

1
2
node.master: true
network.host: 0.0.0.0

从配置

salve01

1
2
3
4
5
6
7
# 集群名称必须保持一致
cluster.name: es-cluster
node.name: slave01
network.host: 0.0.0.0
http.port: 9201
# 由于我是本地搭的伪分布式,所以这里就写127.0.0.1
discovery.zen.ping.unicast.hosts: ["127.0.0.1"]

slave02

1
2
3
4
5
6
7
# 集群名称必须保持一致
cluster.name: es-cluster
node.name: slave02
network.host: 0.0.0.0
http.port: 9202
# 由于我是本地搭的伪分布式,所以这里就写127.0.0.1
discovery.zen.ping.unicast.hosts: ["127.0.0.1"]

欢迎关注我的其它发布渠道