一、用户设置
如果已经是普通用户登录可跳过此步骤。
ElasticSearch默认是不能使用root用户进行启动的,所以需要先添加一个普通用户,并使用普通用户身份安装ElasticSearch。
1.添加一个用户,无任何提示则表示成功添加。
[root@localhost soft]# adduser king
2.设置用户密码,需要输入两次。其中提示无效的密码可以不用管,是因为密码太简单,不符合安全要求。
[root@localhost soft]# passwd king
更改用户 king 的密码 。
新的 密码:
无效的密码: 过于简单化/系统化
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
3.在根目录下创建一个文件夹soft
,并将拥有者更改为king,使用ls -al /soft
命令查看此时/soft文件夹的拥有者。
[root@localhost /]# mkdir /soft
[root@localhost /]# chown king /soft
[root@localhost /]# ls -al /soft
drwxr-xr-x. 2 king root 4096 9月 3 01:58 .
dr-xr-xr-x. 26 root root 4096 9月 3 01:58 ..
一个点代表当前目录,两个点代表上级目录,可以看到当前目录的拥有者已经是king了。
二、安装jdk1.8
如果已经安装jdk1.8可跳过此步骤
ElasticSearch是基于Java开发的,所以要先安装jdk环境。
1.使用yum安装openjdk1.8,使用yum search jdk1.8
搜索安装包
[root@localhost elasticsearch-5.5.2]$ yum search jdk
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
# 会有很多版本的jdk,只展示我们要安装的这个版本
2.安装openjdk1.8
[root@localhost ~]# yum install java-1.8.0-openjdk.x86_64
安装完成后输入java
命令,有相应输出就说明安装成功了。
3.至此之前,我们都是使用root身份来操作的,下面使用如下命令切换到king用户。
[root@localhost /]# su king
[king@localhost /]$ cd /soft
[king@localhost soft]$
这时就以king用户身份登录了,我们使用cd命令进入/soft目录,然后进行接下来的操作。
三、下载ElasticSearch并安装
1.首先到官网下载最新版本的ElasticSearch的zip压缩包,也可以复制下载地址在终端中使用wget命令直接下载到CentOS中。例如在终端中执行以下命令:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.tar.gz
下载过程可能比较慢,可以使用自己电脑下载后使用ftp工具上传到/soft目录。
2.下载完成后,解压elasticsearch-6.3.1.tar.gz
tar -vxf elasticsearch-6.3.1.tar.gz
解压完成后内容如下
[king@localhost soft]$ ls
elasticsearch-6.3.1
3.进入elasticsearch-6.3.1,并启动elasticsearch
[king@localhost soft]$ cd elasticsearch-6.3.1
[king@localhost elasticsearch-6.3.1]$ sh ./bin/elasticsearch
## 会有一堆日志输出,还报了一个异常java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ ...不过这个异常不影响启动,是因为我们的内核版本太低了,新版本系统应该没这个问题。
4.让启动不提示这个异常可以在config/elasticsearch.yml添加如下两行内容,其中:号后面要加上一个空格,因为这是yaml文件的格式要求,yaml是一种新的属性文件的写法,更简洁,不懂的可以自行查查。
[king@localhost elasticsearch-6.3.1]$ vi config/elasticsearch.yml
添加如下两行内容
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
5..这时重新启动,不会提示任何错误了。新打开一个窗口,输入curl localhost:9200
,如果有以下输出则说明启动成功。
[king@localhost ~]$ curl localhost:9200
{
"name" : "q0MSncN",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "6q_V63heQl2hXnR6HKZSug",
"version" : {
"number" : "6.3.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "eb782d0",
"build_date" : "2018-06-29T21:59:26.107521Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
6.在centos6下面启动Elasticsearch的时候提示如下错误:
unable to load JNA native support library, native methods will be disabled.
java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/linux-x86/libjnidispatch.so) not found
详细错误:
flying-bird@flyingbird:~/elk$ ./elasticsearch-5.5.2/bin/elasticsearch -p my_cluster/node1_pid -Epath.conf=./my_cluster/node1/config
[2017-08-28T20:39:04,823][WARN ][o.e.b.Natives ] unable to load JNA native support library, native methods will be disabled.
java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/linux-x86/libjnidispatch.so) not found in resource path (...)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:962) ~[jna-4.4.0.jar:4.4.0 (b0)]
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:922) ~[jna-4.4.0.jar:4.4.0 (b0)]
at com.sun.jna.Native.<clinit>(Native.java:190) ~[jna-4.4.0.jar:4.4.0 (b0)]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_05]
at java.lang.Class.forName(Class.java:259) ~[?:1.8.0_05]
at org.elasticsearch.bootstrap.Natives.<clinit>(Natives.java:45) [elasticsearch-5.5.2.jar:5.5.2]
...
[2017-08-28T20:39:04,829][WARN ][o.e.b.Natives ] cannot check if running as root because JNA is not available
[2017-08-28T20:39:04,829][WARN ][o.e.b.Natives ] cannot install system call filter because JNA is not available
[2017-08-28T20:39:04,830][WARN ][o.e.b.Natives ] cannot register console handler because JNA is not available
[2017-08-28T20:39:04,832][WARN ][o.e.b.Natives ] cannot getrlimit RLIMIT_NPROC because JNA is not available
[2017-08-28T20:39:04,832][WARN ][o.e.b.Natives ] cannot getrlimit RLIMIT_AS beacuse JNA is not available
[2017-08-28T20:39:04,992][INFO ][o.e.n.Node ] [node1] initializing ...
centos6环境
解决办法
- 直接删除或备份Elasticsearch-a.b.c/lib目录下面的jna文件:
mv jna-4.4.0.jar jna-4.4.0.jar.bak
- 在lib目录下:
wget [http://repo1.maven.org/maven2/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar](http://repo1.maven.org/maven2/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar)
附 其他尝试
从https://github.com/java-native-access/jna下载jna-jna-5.0.0.zip,使用jna-jna-5.0.0/dist/linux-x86.jar
和jna-jna-5.0.0/lib/native/linux-x86.jar,均不可用。
最后比较前面wget的文件,和jna-jna-5.0.0中所有的jar,发现这个文件和dist/jna.jar完全一样。
###四、CentOS下RPM安装ElasticSearch
二、下载ElasticSearch
cd /data/software/
wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.2/elasticsearch-2.3.2.rpm
三、安装ElasticSearch
rpm -ivh elasticsearch-2.3.2.rpm
四、设置开机自启动
service elasticsearch start
chkconfig elasticsearch on
五、注意:
rpm安装后,执行错误会放在log文件中,屏幕不输出,一般在/var/log/elasticsearch
##五、外网访问设置
细心的同学也许发现第一章验证是用的“localhost:9200”,如果换成“IP:9200”,则浏览器与curl都无法进行访问,那么如何让外网访问呢?网上查了一下,需要修改config目录下elasticsearch.yml文件,修改network.host为“0.0.0.0”,然后进行启动成功,外网就可以访问啦。但是很遗憾,在我的机器还出现了其他错误,具体如下所示:
通过上面的错误信息,想到需要修改config目录下elasticsearch.yml文件,修改discovery.zen.ping.unicast.hosts为“[“0.0.0.0”]”,然后再次启动,发现没有报错信息(注意防火墙对于端口的限制),同时远程浏览器访问也正常,如下图所示:
1、错误
linux下启动报错BindTransportException[Failed to bind to [9300-9400]解决办法
Exception in thread "main" BindTransportException[Failed to bind to [9300-9400]]; nested: ChannelException[Failed to bind to: /192.168.0.1:9400]; nested: BindException[Cannot assign requested address];
Likely root cause: java.net.BindException: Cannot assign requested address
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 sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.jboss.netty.channel.socket.nio.NioServerBoss$RegisterTask.run(NioServerBoss.java:193)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:391)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:315)
at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:42)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
打开配置文件elasticsearch.yml 将 network.host: 192.168.0.1 修改为本机IP 0.0.0.0
vi /soft/elasticsearch-6.3.1/config/elasticsearch.yml
network.host: 127.0.0.1 #修改为 0.0.0.1
通过root用户启动elasticsearch并且在后台运行
./elasticsearch -Des.insecure.allow.root=true -d
启动elasticsearch 报如下错误:
[2017-05-10T10:04:50,648][WARN ][o.e.b.JNANatives ] unable to install syscall filter:
java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed
at org.elasticsearch.bootstrap.SystemCallFilter.linuxImpl(SystemCallFilter.java:363) ~[elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.SystemCallFilter.init(SystemCallFilter.java:638) ~[elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.JNANatives.tryInstallSystemCallFilter(JNANatives.java:215) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.Natives.tryInstallSystemCallFilter(Natives.java:99) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:204) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:360) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:58) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.cli.Command.main(Command.java:88) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.3.2.jar:5.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.3.2.jar:5.3.2]
解决方法:
vi /soft/elasticsearch-6.3.1/config/elasticsearch.yml
修改elasticsearch.yml 添加一下内容
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
问题一:警告提示
[2016-11-06T16:27:21,712][WARN ][o.e.b.JNANatives ] unable to install syscall filter:
java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in
at org.elasticsearch.bootstrap.Seccomp.linuxImpl(Seccomp.java:349) ~[elasticsearch-5.0.0.jar:5.0.0]
at org.elasticsearch.bootstrap.Seccomp.init(Seccomp.java:630) ~[elasticsearch-5.0.0.jar:5.0.0]
报了一大串错误,其实只是一个警告。
解决:使用心得linux版本,就不会出现此类问题了。
问题二:ERROR: bootstrap checks failed
ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]
**解决:**切换到root用户,编辑limits.conf 添加类似如下内容
vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
问题三:
max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
**解决:**切换到root用户,进入limits.d目录下修改配置文件。
vi /etc/security/limits.d/90-nproc.conf
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048
问题四:
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解决:切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
问题五:`
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]`
解决:修改切换到root用户修改配置limits.conf 添加下面两行
命令:
vi /etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536
切换到king的用户。
然后,重新启动elasticsearch,即可启动成功。
六、后台运行
最后还有一个小问题,如果你在服务器上安装Elasticsearch,而你想在本地机器上进行开发,这时候,你很可能需要在关闭终端的时候,让Elasticsearch继续保持运行。
先按Ctrl + C,停止当前运行的Elasticsearch,改用下面的命令运行Elasticsearch
su king #切换账户
cd /soft/elasticsearch-6.3.1/bin #进入你的elasticsearch目录下的bin目录
./elasticsearch
或者以后台启动
./elasticsearch -d //后台启动
这样,你就可以放心地关闭服务器终端,而不用担心Elasticsearch也跟着关闭了。