Linux部署Elasticsearch(一):下載和部署Elasticsearch

Linux安裝好jdk1.8

下載elasticsearch

可以進入https://www.elastic.co/downloads/elasticsearch

下載到本地再上傳到Linux服務器,解壓到當前目錄命令

tar  -zxvf 文件名

或者直接在Linux上下載

wget https://artifacts.elastic.co/downloads/elasticserch/elasticsearch-5.0.0.tar.gz

我下載到了opt文件夾下

解壓到當前目錄後

編輯elasticsearch.yml文件

vim  /opt/elasticsearch-5.0.0/config/elasticsearch.yml

cluster.name: my-application //集羣名稱

node.name: node-1  //es節點id

path.data: /opt/elasticsearch-5.0.0/data //指定es的數據存儲目錄

path.logs: /opt/elasticsearch-5.0.0/logs //指定es的日誌存儲目錄

bootstrap.memory_lock: true //鎖定物理內存地址,防止elasticsearch內存被交換出去,也就是避免es使用swap交換分區

network.host: 0.0.0.0 //爲es設置ip綁定,默認是127.0.0.1,也就是默認只能通過127.0.0.1 或者localhost才能訪問, es1.x版本默認綁定的是0.0.0.0 所以不需要配置,但是es2.x版本默認綁定的是127.0.0.1,需要配置,如果要外網訪問就配置成0.0.0.0


http.port: 9200 //爲es設置自定義端口,默認是9200
 注意:在同一個服務器中啓動多個es節點的話,默認監聽的端口號會自動加1:例如:9200,9201,9202...


discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx.xxx"] //如果是虛擬機就寫127.0.0.1或者本機ip,如果是服務器就寫服務器地址

discovery.zen.minimum_master_nodes: 1 //通過配置這個參數來防止集羣腦裂現象 (集羣總節點數量/2)+1

更多關於elasticsearch.yml的知識可以參考博文https://blog.csdn.net/zmx729618/article/details/80363875

 配置系統內存鎖定(由於es 配置文件中配置了內存鎖定,如果系統不鎖定會報:memory locking requested for elasticsearch process but memory is not locked)

打開limits.conf配置文件

vim /etc/security/limits.conf

添加如下代碼:

* soft memlock unlimited

* hard memlock unlimited

配置可創建最大文件(解決:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536])

打開limits.conf配置文件

vim /etc/security/limits.conf

添加如下代碼:

* soft nofile 65536

* hard nofile 65536

這裏我剛開始沒有配置爲65536,配置成了65535,啓動的時候報錯了 max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

配置可創建線程數(解決:max number of threads [1024] for user [elastic] is too low, increase to at least [2048])

文件是在/etc/security/limits.d文件夾下的,我的文件名是20-nproc.conf,有的鵬友的文件名是90-nproc.conf

打開文件20-nproc.conf,添加如下代碼:

修改最大虛擬內存大小(解決max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] )

打開sysctl.conf文件,添加如下代碼:

vm.max_map_count=262144

保存退出後,輸入如下命令使sysctl.conf 配置生效

sysctl -p

解決centos6.x 不支持SecComp,ES5.2 後的版本默認使用 bootstrap.system_call_filter 檢測,如果不通過則終止ES 進程,所以將該項改爲false

編輯/elasticsearch.yml

vim  /opt/elasticsearch-5.0.0/config/elasticsearch.yml

添加

bootstrap.system_call_filter: false

但是我的centos7.x,添加了這行代碼後啓動失敗,註釋後啓動成功。

添加啓動elasticsearch 用戶(es 默認不能使用root 用戶啓動)

groupadd elastic

useradd elastic -g elastic

啓動elasticsearch

su elasticsearch

進入elasticsearch的bin目錄

./elasticsearch(這樣啓動會看到啓動過程,但你做不了其他操作了,可以先用此操作看是否成功啓動再用後臺啓動的方法啓動)

後臺啓動elasticsearch

./elasticsearch -d

到此就部署完成了,如果啓動時出現問題可以參考我的博文Linux部署Elasticsearch(二):啓動Elasticsearch不成功的幾種原因

 

我是初學者,如有不對之處,還望各位大佬多多指教。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章