ES搜索引擎學習之環境搭建
1.下載ElasticSearch6.2.4
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz
2.解壓文件
tar -zxvf elasticsearch-6.2.4.tar.gz
3.重新命名
mv elasticsearch-6.2.4 /usr/local/elastic/elasticsearch
4.創建數據存放路徑
mkdir /usr/local/elastic/elasticsearch/data
5.創建日志存放路徑(如已存在不用創建)
mkdir /usr/local/elastic/elasticsearch/logs
6.創建用戶並授權(因為es不能root用戶運行)
useradd es
chown -R es:es /usr/local/elastic/elasticsearch
7. 修改es配置
#集群的名稱
cluster.name: es6.2.4
#節點名稱,其余兩個節點分別為node-2 和node-3
node.name: node-1
#指定該節點是否有資格被選舉成為master節點,默認是true,es是默認集群中的 第一台機器為master,如果這台機掛了就會重新選舉master
node.master: true
#允許該節點存儲數據(默認開啟)
node.data: true
#索引數據的存儲路徑
path.data: /usr/local/elastic/elasticsearch/data
#日志文件的存儲路徑
path.logs: /usr/local/elastic/elasticsearch/logs
#設置為true來鎖住內存。因為內存交換到磁盤對服務器性能來說是致命的,當jvm 開始swapping時es的效率會降低,所以要保證它不swap
bootstrap.memory_lock: true
#綁定的ip地址 這里所有都可訪問
network.host: 0.0.0.0
#設置對外服務的http端口,默認為9200
http.port: 9200
# 設置節點間交互的tcp端口,默認是9300
transport.tcp.port: 9300
#Elasticsearch將綁定到可用的環回地址,並將掃描端口9300到9305以嘗試連接到 運行在同一台服務器上的其他節點。
#這提供了自動集群體驗,而無需進行任何配置。數組設置或逗號分隔的設置。每 個值的形式應該是host:port或host
#(如果沒有設置,port默認設置會transport.profiles.default.port 回落到 transport.tcp.port)。
#請注意,IPv6主機必須放在括號內。默認為127.0.0.1, [::1]
discovery.zen.ping.unicast.hosts: ["ip:9300", "ip:9300", "ip:9300"]
#如果沒有這種設置,遭受網絡故障的集群就有可能將集群分成兩個獨立的集群 - 分裂的大腦 - 這將導致數據丟失
discovery.zen.minimum_master_nodes: 3
# 增加新的參數,這樣head插件可以訪問es,解決跨域訪問問題
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true
8. 調整jvm內存
vim /usr/local/elk/elasticsearch/config/jvm.options
#默認是1g官方建議對jvm進行一些修改,不然很容易出現OOM,參考官網改參數配置 最好不要超過內存的50%
-Xms1g
-Xmx1g
9. 分別啟動各個節點的es
/usr/local/elastic/elasticsearch/bin/elasticsearch -d
注意:
查看進程是否啟動
ps -ef|grep elasticsearch
發現並沒有啟動,什么原因呢?查看一下日志在我們配置的日志路徑下:
cd ../logs
第一個坑:日志文件會以集群名稱命名,查看es6.2.log文件,日志報以下異常:
[ERROR][o.e.b.Bootstrap ] [node-1] node validation exception
[3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: memory locking requested for elasticsearch process but memory is not locked
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決方法:
切回root用戶su - root,修改配置
① vim /etc/security/limits.conf
soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
#我選擇鎖住swapping因此需要在這個配置文件下再增加兩行代碼
es soft memlock unlimited
es hard memlock unlimited
打開: vim /etc/sysctl.conf
執行一句命令sysctl -p使系統配置生效(使用root用戶)。
Es不能使用root啟動
10. 再次重啟Elasticsearch
安裝elasticsearch-head
1.安裝nodejs和rpm
su - root
yum install epel-release
yum install nodejs npm
2.下載並安裝elasticsearch-head
git clone https://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
3.修改elasticsearch參數,以便於head插件訪問es
1.在elasticsearch下的elasticsearch.yml下新增一下兩行: http.cors.enabled: true
http.cors.allow-origin: "*"
2.重啟es
4.修改es-head的localhost地址
cd ./elasticsearch-head
vim Gruntfile.js
Add hostname
connect: {
server: {
options: {
hostname: '0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}
5.修改head連接地址
1.cd ./elasticsearch-head #(elasticsearch-head源碼文件夾)
2.vim ./_site/app.js
3.將localhost修改為ESdeIP地址 修改前:this.base_uri = this.config.base_uri; 修改后: this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://you ip address:9200";
6. 啟動elasticsearch-head
cd elasticsearch-head(elasticsearch-head源碼目錄)
./node_modules/grunt/bin/grunt server
1、啟動必須非root
2、多次啟動會報錯
3、后台啟動
/usr/local/elastic/elasticsearch/bin/elasticsearch -d
4、是否啟動查看
ps -ef | grep elasticsearch
5、啟動日志查看
elasticsearch.log