前提:安装jdk环境
下载elasticsearch对应版本的安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.tar.gz
https://download.csdn.net/download/qq_29914837/11834996
进入home目录下
cd /home
创建文件夹elastic
mkdir elastic
上传linux版本的es6.2.2的安装包
解压
tar -zxvf elasticsearch-6.2.3.tar.gz
删除压缩包
rm -f elasticsearch-6.2.3.tar.gz
启动es服务器
cd elasticsearch-6.2.3/
#按ctrl+c后es服务自动关闭
./bin/elasticsearch
#后台启动
./bin/elasticsearch -d
启动报错:不能使用root用户启动服务
2019-10-07T20:21:35,823][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] 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:125) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.3.jar:6.2.3]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.2.3.jar:6.2.3]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.3.jar:6.2.3]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.3.jar:6.2.3]
... 6 more
添加用户
useradd esuser
passwd esuser
我这里设置密码为123456
切换到esuser用户下启动
su esuser
./bin/elasticsearch -d
tail -f logs/elasticsearch.log
启动报错:没有jvm文件的权限,改一下所属的用户
Exception in thread "main" java.nio.file.AccessDeniedException: /home/elastic/el asticsearch-6.2.3/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(UnixFileSystemProvid er.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(FileSystemProvide r.java:384)
at java.nio.file.Files.newInputStream(Files.java:152)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsPar ser.java:58)
切换到root用户下,给esuser用户赋权限
su root
chown esuser /home/elastic/elasticsearch-6.2.3/ -R
启动打印出现warn提示
[2019-10-07T20:33:08,148][WARN ][o.e.b.BootstrapChecks ] [tsVOtDK] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2019-10-07T20:33:08,148][WARN ][o.e.b.BootstrapChecks ] [tsVOtDK] max number of threads [3795] for user [esuser] is too low, increase to at least [4096]
[2019-10-07T20:33:08,148][WARN ][o.e.b.BootstrapChecks ] [tsVOtDK] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
原因:进程不够用了
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
切换到root用户
vi /etc/security/limits.conf
#在文件末尾添加下面的参数值
* soft nofile 65536
* hard nofile 131072
#最大线程个数太低
max number of threads [3795] for user [esuser] is too low, increase to at least [4096]
切换到root用户
vi /etc/security/limits.conf
#在文件末尾添加下面的参数值
* soft nproc 5000
* hard nproc 5000
root soft nproc 5000
root hard nproc 5000
#esuser用户拥有的内存权限太小
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
su root
vi /etc/sysctl.conf
#末尾添加
vm.max_map_count=655360
#保存退出
#执行命令查看sysctl.conf文件是否生效
sysctl -p
重启es
安装完毕,验证是否安装成功
ps -ef|grep elasticsearch
curl localhost:9200
#0.0.0.0 表示不限制访问,或者指定本台服务器ip
network.host: 0.0.0.0
su root
#创建elasticsearch文件
vi /etc/init.d/elasticsearch
内容如下:其中jdk路径和elasticsearch安装目录路径安装安装自己的更改即可!esuser为创建的用户
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
export JAVA_HOME=/usr/local/java/jdk1.8.0_191
export JAVA_BIN=/usr/local/java/jdk1.8.0_191/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
case "$1" in
start)
su esuser<
保存退出,赋予该脚本执行权限
chmod +x /etc/init.d/elasticsearch
将elasticsearch添加到开机启动任务
chkconfig --add /etc/init.d/elasticsearch
elasticsearch集群安装步骤与单机安装基本一致。
首先建议准备最少三台es服务器,避免脑裂。
如何防止elasticsearch的脑裂问题
节点名称 | IP地址 |
---|---|
node1 | 192.168.68.133 |
node2 | 192.168.68.134 |
node3 | 192.168.68.135 |
1、三台es服务器安装单机安装,如果单独启动没有问题的话,再修改为ES集群配置
2、修改elasticsearch.yml 文件
vi elasticsearch.yml
#该3个es节点的集群名称必须相同
cluster.name: my-application
#每个节点名称不能相同,另外两台分别为node2 ,node3
node.name:node1
#将所有节点里面的地址修改为所有节点的IP,","除了逗号不要有空格
discovery.zen.ping.unicast.hosts: ["192.168.68.133", "192.168.68.134","192.168.68.135"]
#默认是1,3台节点建议修改为2,防止ES脑裂
discovery.zen.minimum_master_nodes: 2
3、查看集群效果
http://192.168.68.133:9200/_cat/nodes?pretty
效果:会显示三台es服务器ip地址
如果你觉得本篇文章对你有所帮助的话,麻烦请点击头像右边的关注按钮,谢谢!
技术在交流中进步,知识在分享中传播