试试安装运行一下Elasticsearch

系统信息

查看系统版本
[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]$ 

启动后测试

  • 输入curl ip:9200,如果返回一个json数据说明启动成功
[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]$ 


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,204评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,091评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,548评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,657评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,689评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,554评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,302评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,216评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,661评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,851评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,977评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,697评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,306评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,898评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,019评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,138评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,927评论 2 355

推荐阅读更多精彩内容