Linux(centos)安装es(elasticsearch)

 

前提条件——需要安装jdk环境,不同版本的es所对应的jdk版本要求不同,es6的使用jdk1.8可以

1、下载elasticsearch压缩包 下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-6-0,点击下载

 

 

 

 

 

 

 

2、上传到centos上,我们这里上传到 /usr/web/elasticsearch 文件夹下,并解压文件

tar -zxvf elasticsearch-6.6.0.tar.gz

  

3、进入解压后目录

cd elasticsearch-6.6.0/bin

 启动

./elasticsearch

 

出现以下报错,这是因为elasticsearch为了安全性,是不能用root用户启动的。 切换其他账号,或者新建账号   创建账号可以参考 https://www.cnblogs.com/pxblog/p/13572044.html

[2020-04-04T16:34:31,537][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] 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:163) ~[elasticsearch-6.6.0.jar:6.6.0]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.6.0.jar:6.6.0]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.6.0.jar:6.6.0]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.6.0.jar:6.6.0]
	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.6.0.jar:6.6.0]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.6.0.jar:6.6.0]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.6.0.jar:6.6.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.6.0.jar:6.6.0]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.6.0.jar:6.6.0]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.6.0.jar:6.6.0]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.6.0.jar:6.6.0]
	... 6 more

  

重新使用启动命令,出现以下报错,报这个错是因为用户的权限不足,因此在配置和启动ElasticSearch节点的时候要注意给用户赋予对应的权限

Exception in thread "main" java.nio.file.AccessDeniedException: /usr/web/elasticsearch/elasticsearch-6.6.0/config/jvm.options
	at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
	at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
	at java.nio.file.Files.newByteChannel(Files.java:361)
	at java.nio.file.Files.newByteChannel(Files.java:407)
	at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
	at java.nio.file.Files.newInputStream(Files.java:152)
	at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:60)

   现在切换到root账号,执行以下命令,执行完之后需要在切换到原来的账号    

chown -R elas:elas /usr/web/elasticsearch

 其中,elas是用户名  后面是elasticsearch文件路径

    在开发使用过程中,我们可以限制elasticsearch使用的内存大小

   进入elasticsearch的目录下config文件夹  

vim jvm.options

  注:如果打开是空的,可能是由于没有权限,使用root账号进行修改

 

elasticsearch 要求至少1g启动内存,所以内存不够,我们可以设置的小一点,修改为256m,如图所示

 

修改完成之后,保存退出

 

现在默认我们只能在linux服务器上访问elasticsearch ,如果要使得我们在外网也能访问 elasticsearch ,需要修改配置文件

进入elasticsearch文件目录下的config文件夹中

vim elasticsearch.yml 

  默认是

 

 

 修改成

 

   注:9200是外网访问端口,所以如果启动了防火墙,需要把端口配置下,可以参照:https://www.cnblogs.com/pxblog/p/12222150.html 

  (需要9200和9300两个端口都要开启,9200是web端访问端口,9300是开发程序访问端口)

 修改完成之后,保存退出

然后进入bin目录启动,重新启动

如果出现以下报错

org.elasticsearch.bootstrap.StartupException: BindTransportException[Failed to bind to [9300-9400]]; nested: BindException[无法指定被请求的地址];
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.7.2.jar:6.7.2]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.7.2.jar:6.7.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.7.2.jar:6.7.2]
Caused by: org.elasticsearch.transport.BindTransportException: Failed to bind to [9300-9400]
    at org.elasticsearch.transport.TcpTransport.bindToPort(TcpTransport.java:408) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.transport.TcpTransport.bindServer(TcpTransport.java:375) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.transport.netty4.Netty4Transport.doStart(Netty4Transport.java:136) ~[?:?]
    at org.elasticsearch.xpack.core.security.transport.netty4.SecurityNetty4Transport.doStart(SecurityNetty4Transport.java:127) ~[?:?]
    at org.elasticsearch.xpack.security.transport.netty4.SecurityNetty4ServerTransport.doStart(SecurityNetty4ServerTransport.java:46) ~[?:?]
    at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:72) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.transport.TransportService.doStart(TransportService.java:228) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:72) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.node.Node.start(Node.java:741) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:269) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) ~[elasticsearch-6.7.2.jar:6.7.2]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.7.2.jar:6.7.2]
    ... 6 more
Caused by: java.net.BindException: 无法指定被请求的地址
    at sun.nio.ch.Net.bind0(Native Method) ~[?:?]
    at sun.nio.ch.Net.bind(Net.java:433) ~[?:?]
    at sun.nio.ch.Net.bind(Net.java:425) ~[?:?]
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[?:?]
    at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:130) ~[?:?]
    at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:562) ~[?:?]
    at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1358) ~[?:?]
    at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501) ~[?:?]
    at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486) ~[?:?]
    at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019) ~[?:?]
    at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:258) ~[?:?]
    at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:366) ~[?:?]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[?:?]
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) ~[?:?]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:474) ~[?:?]
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) ~[?:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_161]

将上一步中的elasticsearch.yml 的network.host改成0.0.0.0

 

 

 

 

 

出现以下报错 说明现在的环境不符合elasticsearch的要求

ERROR: [1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2020-04-04T17:47:27,880][INFO ][o.e.n.Node               ] [5GagyKc] stopping ...
[2020-04-04T17:47:27,965][INFO ][o.e.n.Node               ] [5GagyKc] stopped
[2020-04-04T17:47:27,965][INFO ][o.e.n.Node               ] [5GagyKc] closing ...
[2020-04-04T17:47:27,979][INFO ][o.e.n.Node               ] [5GagyKc] closed

 

(1)、修改系统配置文件  (切换到root用户)

vim /etc/security/limits.conf

  增加以下内容,如图所示

* hard nofile 655360
* soft nofile 131072
* hard nproc 4096
* soft nproc 4096

  其中:

             nofile - 打开文件的最大数目

             noproc - 进程的最大数目

             soft 指的是当前系统生效的设置值

             hard 表明系统中所能设定的最大值

 

 

 

 

 然后保存退出

 

(2)修改系统最大内存数,进入

vim /etc/sysctl.conf

  默认是

 

 修改为

 

如果没有上述内容,直接添加以下内容进去即可

 

vm.max_map_count=655360
fs.file-max=655360

  修改好之后,保存退出

使的我们修改的配置文件生效

sysctl -p

  

  

 

重新启动。切换到普通账号启动elasticsearch,启动成功后,我们可以使用 -d 命令进行后台启动,进入elasticsearch文件夹目录的bin文件夹

./elasticsearch -d

  或者

nohup ./elasticsearch &

  

 

打开浏览器输入

http://192.168.0.102:9200/   出现

{
  "name" : "5GagyKc",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "ziiT6TFMSiaTuDqjEwrlfA",
  "version" : {
    "number" : "6.6.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "a9861f4",
    "build_date" : "2019-01-24T11:27:09.439740Z",
    "build_snapshot" : false,
    "lucene_version" : "7.6.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

  

其中 192.168.0.102 是我的虚拟机地址

 

关闭程序

[root@localhost ~]# ps -ef|grep elastic
elas+  47702      1 10 17:19 pts/1    00:00:20 /usr/web/java/jdk1.8/bin/java -Xms256m -Xmx256m -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-4781675233424590824 -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 -Des.path.home=/usr/web/elasticsearch/elasticsearch-6.6.0 -Des.path.conf=/usr/web/elasticsearch/elasticsearch-6.6.0/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /usr/web/elasticsearch/elasticsearch-6.6.0/lib/* org.elasticsearch.bootstrap.Elasticsearch -d

 然后杀掉对应的进程

kill 47702

  

  

 es(elasticsearch)安装IK中文分词器参考:https://www.cnblogs.com/pxblog/p/12633189.html

  centos7使用docker安装es(elasticsearch):参考:https://www.cnblogs.com/pxblog/p/12234561.html

  

 

 

 

  

 

posted @ 2020-04-04 17:27  yvioo  阅读(7526)  评论(3编辑  收藏  举报