Linux安装elasticsearch-7.x

Linux服务器是CentOS 7.x

Elasticsearch下载地址:
https://www.elastic.co/downloa

解压   tar -avxf elasticsearch-7.6.2-linux-x86_64.tar.gz  -C /usr/local/


进入解压后的elasticsearch目录:
(1)新建data目录:

mkdir data
1

(2)修改config/elasticsearch.yml:

vim config/elasticsearch.yml
1
取消下列项注释并修改:

cluster.name: my-application #集群名称
node.name: node-1 #节点名称
#数据和日志的存储目录
path.data: /usr/local/elasticsearch-7.1.1/data
path.logs: /usr/local/elasticsearch-7.1.1/logs
#设置绑定的ip,设置为0.0.0.0以后就可以让任何计算机节点访问到了
network.host: 0.0.0.0
http.port: 9200 #端口
#设置在集群中的所有节点名称,这个节点名称就是之前所修改的,当然你也可以采用默认的也行,目前是单机,放入一个节点即可
cluster.initial_master_nodes: ["node-1"]



修改完毕后,:wq 保存退出vim

准备启动es
进入/bin目录执行命令:

./elasticsearch
1
我这里出现如下错误:

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid22863.log
[root@VM_0_2_centos bin]# 



看来是我这1G的内存太小了啊,elasticsearch使用java的jvm默认是使用1G的内存的,这里我们修改一下内存,直接把内存改到200m
cd 到es目录修改 ./config/jvm.options:

vim ./config/jvm.options 

修改该内容:

-Xms200m
-Xmx200m

:wq 保存并退出vim,再次启动es

再次启动出现如下错误:

[root@localhost bin]# ./elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_231/jre] does not meet this requirement
[2020-04-19T20:41:50,510][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] 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:174) ~[elasticsearch-7.6.2.jar:7.6.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161) ~[elasticsearch-7.6.2.jar:7.6.2]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.6.2.jar:7.6.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) ~[elasticsearch-cli-7.6.2.jar:7.6.2]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.6.2.jar:7.6.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126) ~[elasticsearch-7.6.2.jar:7.6.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.6.2.jar:7.6.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.6.2.jar:7.6.2]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.6.2.jar:7.6.2]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.6.2.jar:7.6.2]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.6.2.jar:7.6.2]
        ... 6 more
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349)
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)
        at org.elasticsearch.cli.Command.main(Command.java:90)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
For complete error details, refer to the log at /usr/local/elasticsearch-7.6.2/logs/my-application.log



这是不能使用root用户操作,添加一个其他的用户再试试:

创建一个esroot用户并设置初始密码
useradd -c 'ES user' -d /home/esroot esroot
passwd esroot

将es安装目录属主权限改为esroot用户
chown -R esroot /usr/local/elasticsearch-7.6.2/

切换用户到esroot
su esroot



改一下es目录所属用户:

chown esroot /usr/local/elasticsearch-7.6.2/ -R

vim 编辑 /etc/security/limits.conf,在末尾加上:

esroot nofile 65536
esroot hard nofile 65536
esroot soft nproc 4096
esroot hard nproc 4096

vim 编辑 vim /etc/security/limits.d/esroot-nproc.conf,将* 改为用户名(esroot):

# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

es          soft    nproc     4096
root       soft    nproc     unlimited

vim 编辑 /etc/sysctl.conf,在末尾加上:

vm.max_map_count = 655360

执行:

[root@VM_0_2_centos ~]# sysctl -p
kernel.printk = 5
vm.max_map_count = 655360
[root@VM_0_2_centos ~]# 

登录刚才新建的es用户,并启动elasticsearch,OK

[root@VM_0_2_centos elasticsearch-7.1.1]# su es
[es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch
 


后台启动:

[es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch -d
[es@VM_0_2_centos elasticsearch-7.1.1]$ 
1
2
查看进程:

[es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch -d
[es@VM_0_2_centos elasticsearch-7.1.1]$ ps -ef|grep elasticsearch
es       18652     1 19 17:48 pts/2    00:00:00 /usr/local/java/jdk1.8.0_211/bin/java -Xms200m -Xmx200m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -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 -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-182563007296674551 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Dio.netty.allocator.type=unpooled -Des.path.home=/usr/local/elasticsearch-7.1.1 -Des.path.conf=/usr/local/elasticsearch-7.1.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /usr/local/elasticsearch-7.1.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es       18728  8399  0 17:48 pts/2    00:00:00 grep --color=auto elasticsearch
[es@VM_0_2_centos elasticsearch-7.1.1]$ 

执行命令ss -taln

[root@localhost ~]# ss -taln
State       Recv-Q Send-Q              Local Address:Port                Peer Address:Port 
LISTEN      0      128                     127.0.0.1:9000                           *:*     
LISTEN      0      128                             *:80                             *:*     
LISTEN      0      128                             *:22                             *:*     
LISTEN      0      128                             *:88                             *:*     
LISTEN      0      100                     127.0.0.1:25                             *:*     
LISTEN      0      80                             :::3306                          :::*     
LISTEN      0      128                            :::9200                          :::*     
LISTEN      0      128                            :::9300                          :::*     
LISTEN      0      128                            :::22                            :::*     
LISTEN      0      100                           ::1:25        

设置防火墙 开启 9200端口号访问

firewall-cmd --zone=public --add-port=9200/tcp --permanent

systemctl restart firewalld

firewall-cmd --query-port=9200/tcp


· 可在浏览器中输入如下地址:http://192.168.1.54:9200/
在这里插入图片描述
· 如果显示如上信息,则代表Linux下ES已经搭建完毕(单机)

停止

· 若是es的前台运行,则用ctrl + c 来停止。

· 若是es的后台运行,则用kill -9 进程号 来停止。(可通过jps命令,查看es进程号)

linux设置elasticsearch开机启动

vim /etc/rc.local 

添加

#elasticsearch开机自启动
su esroot
/usr/local/elasticsearch-7.6.2/bin/elasticsearch -d

重启,查看进程

jps

或者ss -taln

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Elasticsearch 7.17.4的安装步骤如下: 1. 下载Elasticsearch 在官网 https://www.elastic.co/cn/downloads/elasticsearch 下载Elasticsearch的压缩包,选择适合自己操作系统的版本。下载完成后解压到任意目录。 2. 修改配置文件 进入Elasticsearch的config目录,修改elasticsearch.yml文件。比如: ``` # 设置集群名称 cluster.name: my-cluster # 设置节点名称 node.name: my-node # 设置数据存储路径 path.data: /path/to/data # 设置日志文件路径 path.logs: /path/to/logs ``` 3. 启动Elasticsearch 在终端中进入Elasticsearch的bin目录,执行以下命令启动Elasticsearch: ``` ./elasticsearch ``` 如果一切顺利,你应该能看到类似以下的输出: ``` [2022-02-24T11:23:10,394][INFO ][o.e.n.Node ] [my-node] version[7.17.4], pid[12345], build[default/tar/123abc/2022-01-25T17:34:29.218660Z], OS[Linux/4.14.143-89.123.amzn1.x86_64/amd64], JVM[AdoptOpenJDK/OpenJDK 64-Bit Server VM/16.0.2/16.0.2+7] [2022-02-24T11:23:10,396][INFO ][o.e.n.Node ] [my-node] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseG1GC, -XX:G1ReservePercent=25, -XX:InitiatingHeapOccupancyPercent=30, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.locale.providers=SPI,COMPAT, -Xms512m, -Xmx512m, -Des.path.home=/path/to/elasticsearch-7.17.4, -Des.path.conf=/path/to/elasticsearch-7.17.4/config, -Des.distribution.flavor=default, -Des.distribution.type=tar, -Des.bundled_jdk=true] [2022-02-24T11:23:19,999][INFO ][o.e.p.PluginsService ] [my-node] loaded module [aggs-matrix-stats] [2022-02-24T11:23:19,999][INFO ][o.e.p.PluginsService ] [my-node] loaded module [analysis-common] [2022-02-24T11:23:19,999][INFO ][o.e.p.PluginsService ] [my-node] loaded module [geo] [2022-02-24T11:23:19,999][INFO ][o.e.p.PluginsService ] [my-node] loaded module [ingest-common] ... [2022-02-24T11:23:20,000][INFO ][o.e.p.PluginsService ] [my-node] loaded module [transport-netty4] [2022-02-24T11:23:20,000][INFO ][o.e.p.PluginsService ] [my-node] no plugins loaded [2022-02-24T11:23:23,123][INFO ][o.e.x.s.a.s.FileRolesStore] [my-node] parsed [0] roles from file [/path/to/elasticsearch-7.17.4/config/roles.yml] [2022-02-24T11:23:24,456][INFO ][o.e.i.g.GatewayService ] [my-node] recovered [0] indices into cluster_state [2022-02-24T11:23:27,521][INFO ][o.e.c.r.a.AllocationService] [my-node] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[my-index][0]]]). ``` 这表示Elasticsearch已经成功启动。你可以通过访问`http://localhost:9200`来验证Elasticsearch是否运行正常。 4. 安装插件 Elasticsearch提供了很多插件,可以根据自己的需求进行安装。比如,安装kopf插件: ``` ./bin/elasticsearch-plugin install lmenezes/elasticsearch-kopf/2.1.2 ``` 5. 配置Elasticsearch作为服务 如果你想将Elasticsearch作为服务在后台运行,可以参考官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/starting-elasticsearch.html。 希望这个安装教程能够帮助到你。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值