一、
创建文件夹
#切换到文件夹
[root@localhost /]# cd /usr/local/
#创建文件夹
[root@localhost local]# mkdir elasticsearch
#显示文件
[root@localhost local]# ls
#进入文件夹
[root@localhost local]# cd elasticsearch/
#下载文件
[root@localhost elasticsearch]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.1-linux-x86_64.tar.gz
#解压文件
[root@localhost elasticsearch]# tar -zxvf elasticsearch-8.3.1-linux-x86_64.tar.gz
#显示文件
[root@localhost elasticsearch]# ls
elasticsearch-8.3.1 elasticsearch-8.3.1-linux-x86_64.tar.gz
[root@localhost elasticsearch]# cd elasticsearch-8.3.1/
[root@localhost elasticsearch-8.3.1]# ls
bin config jdk lib LICENSE.txt logs modules NOTICE.txt plugins README.asciidoc
[root@localhost elasticsearch-8.3.1]# cd bin /
#启动
[root@localhost bin]# ./elasticsearch -d
elaticsearch默认不能用root用户启动,所以会报java.lang.RuntimeException: can not run elasticsearch as root异常。
解决方法有两类:
1、修改elaticsearch配置,使其可以允许root用户启动(不建议)
#在执行elasticSearch时加上参数-Des.insecure.allow.root=true,完整命令如下
./elasticsearch -Des.insecure.allow.root=true
#或者 用vi打开elasicsearch执行文件,在变量ES_JAVA_OPTS使用前添加以下命令 ES_JAVA_OPTS="-Des.insecure.allow.root=true"
2、为elaticsearch创建用户并赋予相应权限
adduser es passwd es chown -R es:es elasticsearch-8.3.1/ chmod 770 elasticsearch-8.3.1/
二、Elasticsearch 默认使用 mmapfs 目录存储其索引。 默认的操作系统对 mmap 计数的限制可能太低,这可能会导致内存不足异常。
在 Linux 上,你可以通过以 root 用户身份运行以下命令来增加限制:
sysctl -w vm.max_map_count=262144
要永久设置此值,请更新 /etc/sysctl.conf 中的 vm.max_map_count 设置。配置完毕后,我们可以使用如下的命令来使之起作用:
sysctl -p
要在重新引导后进行验证,请运行
sysctl vm.max_map_count
RPM 和 Debian 软件包将自动配置此设置。 不需要进一步的配置。
你也可以直接使用 DEB 及 RPM 包来直接进行安装。
三、重新远程登录
进行切换用户
切换用户
# su es 进入目录
# cd /usr/local/elasticsearch/elasticsearch-8.3.1/bin/
启动elastic
# ./elasticsearch
启动elastic 并后台
# ./elasticsearch -d
正常启动后显示安全配置
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.
ℹ️ Password for the elastic user (reset with bin/elasticsearch-reset-password -u elastic):
nY2CFqiSEjnbiNiYSseY
ℹ️ HTTP CA certificate SHA-256 fingerprint:
472de7a85eb49dbcfbdae3d567b4d08f5d48440774d75e6b17084f66e35e3fc9
ℹ️ Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjMuMSIsImFkciI6WyIxOTIuMTY4LjIuMjAzOjkyMDAiXSwiZmdyIjoiNDcyZGU3YTg1ZWI0OWRiY2ZiZGFlM2Q1NjdiNGQwOGY1ZDQ4NDQwNzc0ZDc1ZTZiMTcwODRmNjZlMzVlM2ZjOSIsImtleSI6IkpYN0N6WUVCTnEwbUJhNUJ3dzJQOlB2a3Aya24yVDdXSkFTTURWdEI2RVEifQ==
ℹ️ Configure other nodes to join this cluster:
• On this node:
⁃ Create an enrollment token with bin/elasticsearch-create-enrollment-token -s
⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
⁃ Restart Elasticsearch.
• On other nodes:
⁃ Start Elasticsearch with bin/elasticsearch --enrollment-token , using the enrollment token that you generated.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
访问elasticsearch
访问 https://192.168.2.203:9200/
账号和密码是上面的
elastic
nY2CFqiSEjnbiNiYSseY
登录后显示