环境:
centos7
jdk1.8
elasticsearch5.5.0
安装jdk1.8
由于elasticsearch是用Java写的,所以需要先安装好java环境,此处省略
安装elasticsearch
假设安装到/usr/local/software
下载解压
cd /usr/local/software
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.tar.gz
tar -zxvf elasticsearch-5.5.0.tar.gz
mv elasticsearch-5.5.0 elasticsearch
编辑配置文件config/elasticsearch.yml
cd elasticsearch
vim config/elasticsearch.yml
设置
network.host: 你自己的服务器ip
http.port: 9200
这里需要注意的是,es 规定 root 用户不能启动 es,所以需要创建一个用户来启动 es
创建用户名为 elastic 的用户
useradd elastic
设置 elastic 用户的密码
passwd 12345678
创建 es 的 data 和 logs 目录
cd elasticsearch
mkdir data
mkdir logs
将 /usr/local/software/elasticsearch 的拥有者设置为 elastic
chown -R elastic:elastic /usr/local/software/elasticsearch
切换到 elastic 用户,启动 es
su elastic
加了-d是后台启动 不加是前台启动,第一次不建议后台启动,前台启动可以直观的看到日志信息
bin/elasticsearch
可能遇到的错误
问题:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决方法:
切换到root用户修改
su root
vim /etc/security/limits.conf
在最后面追加下面内容 其中elastic表示刚刚创建的用户名
elastic hard nofile 65536
elastic soft nofile 65536
修改后切换到es用户,使用如下命令查看是否修改成功
ulimit -Hn
65536
问题:max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
解决方法:
切换到root用户,进入limits.d目录下修改配置文件
vim /etc/security/limits.d/90-nproc.conf
soft nproc 1024修改成2048
问题:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方法:
提高vm.max_map_count 的大小
切换到root用户
su root
vim /etc/sysctl.conf
在最后面追加下面内容
vm.max_map_count=300000
使用 sysctl -p 查看修改后的结果
sysctl -p
问题:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
解决方法:
由于elasticsearch5.x默认分配jvm空间大小为2g,修改jvm空间分配
如果使用虚拟机安装,内存最好不小于2G
vim config/jvm.options
-Xms2g
-Xmx2g
改成
-Xms256m
-Xmx256m
在阿里云上可能会出现的问题:
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
解决方法:在es配置文件中加入下面命令即可
vim config/elasticsearch.yml
bootstrap.system_call_filter: false
最后再重启服务器再启动es!!!
打开防火墙端口
systemctl start firewalld
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --zone=public --add-port=9300/tcp --permanent
firewall-cmd --reload
在确定服务器端口(9200)开启,elasticsearch启动的情况下查看运行情况
ps -ef | grep elasticsearch
也可以在浏览器中访问测试 http://你的服务器ip:9200 能打开则表示成功
关闭elasticSearch
elasticsearch的进程号
ps -ef | grep elastic
用kill -9
tar.gz方式安装es实现开机自启动
增加一个elasticsearch.service文件
vim /usr/lib/systemd/system/elasticsearch.service
内容如下:
#!/bin/shexport JAVA_HOME=/usr/local/software/jdkexport PATH=$JAVA_HOME/bin:$PATH[Unit] Description=elasticsearch After=network.target [Service]User=elastic Type=forking ExecStart=/usr/local/software/elasticsearch/bin/elasticsearch -d PrivateTmp=true # Specifies the maximum file descriptor number that can be opened by this processLimitNOFILE=65536 # Specifies the maximum number of processesLimitNPROC=2048 # Specifies the maximum number of bytes of memory that may be locked into RAM# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/sysconfig/elasticsearch#LimitMEMLOCK=infinity # Disable timeout logic and wait until process is stoppedTimeoutStopSec=0 # SIGTERM signal is used to stop the Java processKillSignal=SIGTERM # Send the signal only to the JVM rather than its control groupKillMode=process # Java process is never killedSendSIGKILL=no # When a JVM receives a SIGTERM signal it exits with code 143SuccessExitStatus=143 [Install] WantedBy=multi-user.target
设置文件权限
chmod +x elasticsearch.service
设置开机启动
systemctl enable elasticsearch
启动服务
systemctl start elasticsearch
可能会提示
which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
增加一个软连接
ln -s /usr/local/software/jdk/bin/java /usr/bin/java
再次执行systemctl start elasticsearch
可重启服务器 测试是否开机启动es服务
注:以上相关软件路径 根据自己实际情况填写