3.安装elasticsearch
1. 安装elasticsearch¶
dpkg -i elasticsearch-7.16.2-amd64.deb
root@4c16g:/home/ubuntu# dpkg -i elasticsearch-7.16.2-amd64.deb
Selecting previously unselected package elasticsearch.
(Reading database ... 128317 files and directories currently installed.)
Preparing to unpack elasticsearch-7.16.2-amd64.deb ...
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Unpacking elasticsearch (7.16.2) ...
Setting up elasticsearch (7.16.2) ...
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
sudo systemctl start elasticsearch.service
Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore
Processing triggers for systemd (245.4-4ubuntu3.13) ...
2. 修改elasticsearch配置文件¶
1. 备份¶
#1.备份
cd /etc/elasticsearch
ls
cp elasticsearch.yml elasticsearch.yml.bak
root@4c16g:/home/ubuntu# cd /etc/elasticsearch
root@4c16g:/etc/elasticsearch# ls
elasticsearch.keystore elasticsearch-plugins.example.yml elasticsearch.yml jvm.options jvm.options.d log4j2.properties role_mapping.yml roles.yml users users_roles
root@4c16g:/etc/elasticsearch# cp elasticsearch.yml elasticsearch.yml.bak
2. 修改¶
#2.修改 # 需要修改3处!
vim elasticsearch.yml
1. 添加可访问的IP¶
#1)将56行注释打开,并修改为所有IP可访问!因为使用内网,没有开启端口,所以没事!
56 network.host: 0.0.0.0
2. 打开端口¶
#2)将61行的端口打开!
51 # ---------------------------------- Network -----------------------------------
52 #
53 # By default Elasticsearch is only accessible on localhost. Set a different
54 # address here to expose this node on the network:
55 #
56 network.host: 0.0.0.0
57 #
58 # By default Elasticsearch listens for HTTP traffic on the first free port it
59 # finds starting at 9200. Set a specific HTTP port here:
60 #
61 http.port: 9200
3. 起集群中的名(防止启动报错)¶
#3)启动报错的话,打开23行和74行的注释!
23 node.name: node-1
#4)修改为与23行一致!如果安装了2个elasticsearch的话,可以开启后,组成集群???
74 cluster.initial_master_nodes: ["node-1"]
4. 启动失败演示¶
#1. 启动失败!
root@4c16g:/etc/elasticsearch# systemctl start elasticsearch
Job for elasticsearch.service failed because the control process exited with error code.
See "systemctl status elasticsearch.service" and "journalctl -xe" for details.
#2. 查看状态
root@4c16g:/etc/elasticsearch# systemctl status elasticsearch.service
● elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2021-12-31 06:27:36 CST; 13s ago
Docs: https://www.elastic.co
Process: 1962782 ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=78)
Main PID: 1962782 (code=exited, status=78)
Dec 31 06:27:16 4c16g systemd[1]: Starting Elasticsearch...
Dec 31 06:27:35 4c16g systemd-entrypoint[1962782]: ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
Dec 31 06:27:35 4c16g systemd-entrypoint[1962782]: bootstrap check failure [1] of [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.see>
Dec 31 06:27:35 4c16g systemd-entrypoint[1962782]: ERROR: Elasticsearch did not exit normally - check the logs at /var/log/elasticsearch/elasticsearch.log
Dec 31 06:27:36 4c16g systemd[1]: elasticsearch.service: Main process exited, code=exited, status=78/CONFIG
Dec 31 06:27:36 4c16g systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
Dec 31 06:27:36 4c16g systemd[1]: Failed to start Elasticsearch.
lines 1-14/14 (END)...skipping...
● elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2021-12-31 06:27:36 CST; 13s ago
Docs: https://www.elastic.co
Process: 1962782 ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=78)
Main PID: 1962782 (code=exited, status=78)
Dec 31 06:27:16 4c16g systemd[1]: Starting Elasticsearch...
Dec 31 06:27:35 4c16g systemd-entrypoint[1962782]: ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
Dec 31 06:27:35 4c16g systemd-entrypoint[1962782]: bootstrap check failure [1] of [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.see>
Dec 31 06:27:35 4c16g systemd-entrypoint[1962782]: ERROR: Elasticsearch did not exit normally - check the logs at /var/log/elasticsearch/elasticsearch.log
Dec 31 06:27:36 4c16g systemd[1]: elasticsearch.service: Main process exited, code=exited, status=78/CONFIG
Dec 31 06:27:36 4c16g systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
Dec 31 06:27:36 4c16g systemd[1]: Failed to start Elasticsearch.
#3. 根据提示查看日志!
root@4c16g:/etc/elasticsearch# tail -f /var/log/elasticsearch/elasticsearch.log
[2021-12-31T06:27:35,709][INFO ][o.e.t.TransportService ] [4c16g] publish_address {10.0.8.5:9300}, bound_addresses {[::]:9300}
[2021-12-31T06:27:35,828][INFO ][o.e.b.BootstrapChecks ] [4c16g] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2021-12-31T06:27:35,830][ERROR][o.e.b.Bootstrap ] [4c16g] node validation exception
[1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2021-12-31T06:27:35,833][INFO ][o.e.n.Node ] [4c16g] stopping ...
[2021-12-31T06:27:35,850][INFO ][o.e.n.Node ] [4c16g] stopped
[2021-12-31T06:27:35,851][INFO ][o.e.n.Node ] [4c16g] closing ...
[2021-12-31T06:27:35,868][INFO ][o.e.n.Node ] [4c16g] closed
[2021-12-31T06:27:35,870][INFO ][o.e.x.m.p.NativeController] [4c16g] Native controller process has stopped - no new native processes can be started
#4. 可以从日志中看到这行内容:bootstrap check failure [1] of [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
#5. 结论:必须要开启集群名!
3. 启动elastecsearch服务¶
#1.启动前的内存:3.98G
#2.启动服务
systemctl start elasticsearch
#3.查看端口9200
netstat -tunlp
# 启动比较慢,如果没起来,查看日志
tailf /var/log/elasticsearch/elasticsearch.log
# 启动后的内存:12.07G!!!这™占用了8个G内存!!!
4. 修改elasticsearch的使用内存为4G¶
1. 修改配置文件¶
vim jvm.options
# 开启31和32行,设置内存使用大小为4G
19 ################################################################
20 ## IMPORTANT: JVM heap size
21 ################################################################
22 ##
23 ## The heap size is automatically configured by Elasticsearch
24 ## based on the available memory in your system and the roles
25 ## each node is configured to fulfill. If specifying heap is
26 ## required, it should be done through a file in jvm.options.d,
27 ## and the min and max should be set to the same value. For
28 ## example, to set the heap to 4 GB, create a new file in the
29 ## jvm.options.d directory containing these lines:
30 ##
31 -Xms4g
32 -Xmx4g
33 ##
34 ## See https://www.elastic.co/guide/en/elasticsearch/reference/7.16/heap-size.html
35 ## for more information
2. 重启elasticsearch¶
systemctl restart elasticsearch
# 启动后,内存 12.2G -> 8.20G !!!
5. 浏览器访问¶
# 10.0.8.5:9200
# 拿到数据的话,说明成功了!
{
"name" : "node-1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "qhoG_SBoRUStb5AEEfpeCg",
"version" : {
"number" : "7.16.2",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "2b937c44140b6559905130a8650c64dbd0879cfb",
"build_date" : "2021-12-18T19:42:46.604893745Z",
"build_snapshot" : false,
"lucene_version" : "8.10.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

最后更新:
2022-02-19 13:05:46