试试安装运行一下Elasticsearch

2021-12-13  本文已影响0人  黄刚刚

系统信息

查看系统版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

参考文献

https://www.cnblogs.com/sunsky303/p/9438737.html

操作记录

安装并启动elasticsearch

# linux 查看jdk版本
[root@localhost ~]# java -version
-bash: java : 未找到命令

## 安装java-jdk
[root@localhost ~]# yum install java-1.8.0-openjdk* -y

# linux 查看jdk版本
[root@localhost ~]# java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

# 安装sz命令,方便上传文件
[root@localhost ~]# yum -y install lrzsz

# elasticsearch的安装文件是从https://www.elastic.co/cn/downloads/elasticsearch页面下载的,已经上传上来了,
# 这里解压就行了,elasticsearch的安装就是这么简单
[root@localhost ~]# ll
总用量 334776
-rw-------. 1 root root      1255 12月 10 16:39 anaconda-ks.cfg
-rw-r--r--. 1 root root 342805188 12月 10 18:20 elasticsearch-7.16.0-linux-x86_64.tar.gz

[root@localhost ~]# tar -zxvf elasticsearch-7.16.0-linux-x86_64.tar.gz
[root@localhost ~]# ll
总用量 334776
-rw-------. 1 root root      1255 12月 10 16:39 anaconda-ks.cfg
drwxr-xr-x. 9 root root       155 12月  2 23:52 elasticsearch-7.16.0
-rw-r--r--. 1 root root 342805188 12月 10 18:20 elasticsearch-7.16.0-linux-x86_64.tar.gz

# 使用默认配置,启动elasticsearch(报错了,原因是不能使用root用户运行elasticsearch)
[root@localhost ~]# cd elasticsearch-7.16.0
[root@localhost elasticsearch-7.16.0]# bin/elasticsearch
[2021-12-10T18:50:35,969][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [localhost.localdomain] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.16.0.jar:7.16.0]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:157) ~[elasticsearch-7.16.0.jar:7.16.0]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77) ~[elasticsearch-7.16.0.jar:7.16.0]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112) ~[elasticsearch-cli-7.16.0.jar:7.16.0]
    at org.elasticsearch.cli.Command.main(Command.java:77) ~[elasticsearch-cli-7.16.0.jar:7.16.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:122) ~[elasticsearch-7.16.0.jar:7.16.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) ~[elasticsearch-7.16.0.jar:7.16.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:107) ~[elasticsearch-7.16.0.jar:7.16.0]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:183) ~[elasticsearch-7.16.0.jar:7.16.0]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434) ~[elasticsearch-7.16.0.jar:7.16.0]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166) ~[elasticsearch-7.16.0.jar:7.16.0]
    ... 6 more
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:107)
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:183)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434)
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166)
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:157)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112)
    at org.elasticsearch.cli.Command.main(Command.java:77)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:122)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80)
For complete error details, refer to the log at /root/elasticsearch-7.16.0/logs/elasticsearch.log

# 添加用户
[root@localhost elasticsearch-7.16.0]# adduser elasticsearch
# 密码输入的 zheshiyigemima
[root@localhost elasticsearch-7.16.0]# passwd elasticsearch
[root@localhost elasticsearch-7.16.0]# chown -R elasticsearch:elasticsearch ../elasticsearch-7.16.0
[root@localhost elasticsearch-7.16.0]# su elasticsearch
# 启动elasticsearch又报错了,原因是我们把文件解压在root用户的家目录了,其实按照linux的目录规范,我们应该把程序安装在/opt/目录下
[elasticsearch@localhost elasticsearch-7.16.0]$ bin/elasticsearch
could not find java in bundled JDK at /root/elasticsearch-7.16.0/jdk/bin/java
[root@localhost ~]# pwd
/root
# 到这里,启动成功,并且查看日志文件中也没有任何错误信息(一般启动的错误都是权限不足)
[root@localhost ~]# mv elasticsearch-7.16.0 /opt/elasticsearch-7.16.0
[elasticsearch@localhost ~]$ cd /opt
[elasticsearch@localhost opt]$ ./elasticsearch-7.16.0/bin/elasticsearch  -d
[elasticsearch@localhost opt]$ cat /opt/elasticsearch-7.16.0/logs/elasticsearch.log | grep "ERROR"
[elasticsearch@localhost opt]$ 

启动后测试

[elasticsearch@localhost opt]$ curl 127.0.0.1:9200
{
  "name" : "localhost.localdomain",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "MUiAPfr5RTy9w1Oxs7hcUA",
  "version" : {
    "number" : "7.16.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "6fc81662312141fe7691d7c1c91b8658ac17aa0d",
    "build_date" : "2021-12-02T15:46:35.697268109Z",
    "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"
}

关闭防火墙

[elasticsearch@localhost opt]$ systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 五 2021-12-10 17:28:16 CST; 2 days ago
     Docs: man:firewalld(1)
 Main PID: 674 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─674 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
# 因为当前用户是elasticsearch,所以操作时需要输入root用户的密码
[elasticsearch@localhost opt]$ systemctl stop firewalld
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
[elasticsearch@localhost opt]$  systemctl disable firewalld
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ===
Authentication is required to manage system service or unit files.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ===
Authentication is required to reload the systemd state.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
[elasticsearch@localhost opt]$ systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[elasticsearch@localhost opt]$ 

修改配置文件,使支持宿主机访问

# 修改配置文件的network.host:192.168.100.110
[elasticsearch@localhost opt]$ vi elasticsearch-7.16.0/config/elasticsearch.yml
[elasticsearch@localhost opt]$ ps -ef | grep elasticsearch
root      12611   1601  0 09:32 pts/1    00:00:00 su elasticsearch
elastic+  13003      1  3 09:40 pts/1    00:01:00 /opt/elasticsearch-7.16.0/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -XX:+ShowCodeDetailsInExceptionMessages -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=SPI,COMPAT --add-opens=java.base/java.io=ALL-UNNAMED -XX:+UseG1GC -Djava.io.tmpdir=/tmp/elasticsearch-4500726354810111410 -XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -Xms388m -Xmx388m -XX:MaxDirectMemorySize=203423744 -XX:G1HeapRegionSize=4m -XX:InitiatingHeapOccupancyPercent=30 -XX:G1ReservePercent=15 -Des.path.home=/opt/elasticsearch-7.16.0 -Des.path.conf=/opt/elasticsearch-7.16.0/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /opt/elasticsearch-7.16.0/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
elastic+  13023  13003  0 09:41 pts/1    00:00:00 /opt/elasticsearch-7.16.0/modules/x-pack-ml/platform/linux-x86_64/bin/controller
elastic+  13192  12612  0 10:06 pts/1    00:00:00 grep --color=auto elasticsearch
[elasticsearch@localhost opt]$ kill -9 13003
[elasticsearch@localhost opt]$ kill -9 13023
bash: kill: (13023) - 没有那个进程
[elasticsearch@localhost opt]$ ps -ef | grep elasticsearch
root      12611   1601  0 09:32 pts/1    00:00:00 su elasticsearch
elastic+  13194  12612  0 10:08 pts/1    00:00:00 grep --color=auto elasticsearch
[elasticsearch@localhost opt]$ ./elasticsearch-7.16.0/bin/elasticsearch -d
[elasticsearch@localhost opt]$ curl 192.100.110:9200
curl: (7) Failed connect to 192.100.110:9200; 拒绝连接
[elasticsearch@localhost opt]$ 
ERROR: [4] bootstrap checks failed. You must address the points described in the following [4] lines before starting Elasticsearch.
bootstrap check failure [1] of [4]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
bootstrap check failure [2] of [4]: max number of threads [3795] for user [elasticsearch] is too low, increase to at least [4096]
bootstrap check failure [3] of [4]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
bootstrap check failure [4] of [4]: 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
ERROR: Elasticsearch did not exit normally - check the logs at /opt/elasticsearch-7.16.0/logs/elasticsearch.log
[root@localhost opt]# vi /etc/security/limits.d/20-nproc.conf 
[root@localhost opt]# ^C
[root@localhost opt]# ^C
[root@localhost opt]# cat /etc/security/limits.d/20-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     4096
root       soft    nproc     unlimited
# HCG添加(解决elasticsearch进程运行报错)
## 解决报错: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
elasticsearch    soft    nofile    65535
elasticsearch    hard    nofile    65535
## 解决报错:max number of threads [3795] for user [elasticsearch] is too low, increase to at least [4096]
elasticsearch    soft    nproc     4096
elasticsearch    hard    nproc     4096

[root@localhost opt]# 
[root@localhost opt]# ulimit -Hn
65535
[root@localhost opt]# 

[elasticsearch@localhost opt]$ cat  /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

# HCG添加(解决elasticsearch进程运行报错)  
## 解决报错:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
vm.max_map_count=262144
[root@localhost opt]# sysctl -p
# 修改elasticsearch配置文件的对应配置:cluster.initial_master_nodes: ["192.168.100.110"]
# 解决报错: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
[elasticsearch@localhost opt]$ vi ./elasticsearch-7.16.0/config/elasticsearch.yml
# 终于解决完所有的错误信息并成功访问了
[elasticsearch@localhost opt]$ curl 192.168.100.110:9200
{
  "name" : "localhost.localdomain",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "MUiAPfr5RTy9w1Oxs7hcUA",
  "version" : {
    "number" : "7.16.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "6fc81662312141fe7691d7c1c91b8658ac17aa0d",
    "build_date" : "2021-12-02T15:46:35.697268109Z",
    "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"
}
[elasticsearch@localhost opt]$ 


上一篇下一篇

猜你喜欢

热点阅读