ElasticSearch之Centos7下安装
環境:
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/jdk export 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 process LimitNOFILE=65536# Specifies the maximum number of processes LimitNPROC=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 stopped TimeoutStopSec=0# SIGTERM signal is used to stop the Java process KillSignal=SIGTERM# Send the signal only to the JVM rather than its control group KillMode=process# Java process is never killed SendSIGKILL=no# When a JVM receives a SIGTERM signal it exits with code 143 SuccessExitStatus=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服務
?
注:以上相關軟件路徑 根據自己實際情況填寫
轉載于:https://www.cnblogs.com/zengnansheng/p/10404699.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的ElasticSearch之Centos7下安装的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何评估AI在医学影像识别中的应用效果?
- 下一篇: Centos7 ocsp功能验证