安裝elasticsearch遇到的幾個問題


首先我已經安裝好了jdk1.8的環境並成功解壓,並打算用./bin/elasticsearch這個命令把elasticsearch跑起來,然后我遇到了第一個問題。


第一個問題的提示是:

Java HotSpot(TM) 64-Bit Server VM warning: INFO: 
os::commit_memory(0x0000000085330000, 2060255232, 0) failed;
error='Cannot allocate memory' (errno=12)

由於elasticsearch6.7.0默認分配jvm空間大小為2g,修改jvm空間分配為512m

#vim config/jvm.options
-Xms2g
-Xmx2g

修改為

-Xms512m
-Xmx512m


第二個問題的提示是:

[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] 
uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException
: can not run elasticsearch as root

提示我不能以root身份啟動,所以創建一個新用戶wys

[root@localhost ~]# adduser wys

個人用戶只可以在本home下有完整權限,其他目錄要看別人授權。而我們經常需要root用戶的權限,這時候可以用sodo化身root來操作。我記得我曾經sudo創建了文件,然后發現自己並沒有讀寫權限,因為查看權限是root創建的。

新創建的用戶並不能使用sudo命令,需要給他添加授權。
sudo命令的授權管理在sudoers文件中的。

[root@localhost ~]# sudoers
bash: sudoers: 未找到命令...
[root@localhost ~]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz

找到這個文件位置之后再查看權限:

[root@localhost ~]# ls -l /etc/sudoers
-r--r----- 1 root root 4251 9月  25 15:08 /etc/sudoers

是的,只有只讀的權限,如果想要修改的話,需要先添加w權限:

[root@localhost ~]# chmod -v u+w /etc/sudoers
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)

然后就可以添加內容了,在下面的一行下追加新增的用戶:

[root@localhost ~]# vim /etc/sudoers
 
 
## Allow root to run any commands anywher  
root    ALL=(ALL)       ALL  
wys  ALL=(ALL)       ALL  #這個是新增的用戶

wq保存退出,這時候要記得將寫權限收回:

[root@localhost ~]# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)

第一次使用會提示你,你已經化身超人,身負責任。而且需要輸入密碼才可以下一步。如果不想需要輸入密碼怎么辦,將最后一個ALL修改成NOPASSWD: ALL。



好了,我終於以新建用戶wys的身份把elasticsearch終於運行起來了,但我用外網的ip訪問時(即用我的筆記本上的瀏覽器訪問部署在阿里雲上的elasticsearch),卻沒能成功。
解決方法:修改綁定的IP地址

在默認情況下,ES只允許本地訪問api接口,如果我們希望在另外一台機器上訪問ES的接口的話,需要配置主機地址:

[wys@localhost bin]$ vim elasticsearch-6.7.0/config/elasticsearch.yml

找到如下行:

# Set the bind address to a specific IP (IPv4 or IPv6):
#
# network.host: 192.168.1.1

去掉network.host的注釋,改成0.0.0.0

# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0

之后看到又報錯了:

max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

這個是linux下常見的錯誤,主要是因為linux會限制進程的最大打開文件數,只需要簡單配置一下即可解決,在ES的官方文檔中提供了兩種解決方案。

這里我們只看系統基本的配置這種方式。

打開/etc/security/limits.conf
添加如下配置

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
wys             -       nofile          65536 # add this line
# End of file

保存即可。

這里的wys是用戶名,表明這個配置只對wys用戶生效,如果你用來啟動elasticsearch的用戶名不是這個,那么你需要按你實際的用戶名修改。

第二處修改:

max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

這個是ES使用的虛擬內存,官方文檔給出了解決方案:

[wys@localhost bin]$ sudo sysctl -w vm.max_map_count=262144

調大虛擬內存即可。

重新啟動,就可以正常訪問了,現在我們可以在任何機器上訪問ES了。

也可以用后台進程的方式啟動:

[wys@localhost bin]$ ./elasticsearch -d -p pid


參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM