1、java jdk1.8安裝:
- 檢查當前系統是否有jdk
java -version
rpm -qa|grep java - 移除當前系統安裝的jdk
rpm -e xxx - 解壓jdk8
sudo tar -zxvf jdk-8u131-linux-x64.tar.gz -C /usr/local/ - 在profile文件中添加環境變量
sudo vim /etc/profile
JAVA_HOME=/usr/local/jdk1.8.0_131
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
source /etc/profile
2、elasticsearch.yml配置:
- 安裝之前關閉防火牆
查看防火牆狀態:systemctl status firewalld
停止防火牆:sudo systemctl stop firewalld
設置開機不啓用防火牆:sudo systemctl disable firewalld
vim config/elasticsearch.yml
大小寫敏感,使用縮進表示層級關係,縮進時不允許使用Tab鍵,只允許使用空格。縮進的空格數目不重要,只要相同層級的元素左側對齊即可# 表示註釋,從這個字符一直到行尾,都會被解析器忽略。
cluster.name: elasticsearch
node.name: es-node01
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
network.host: 192.168.1.101
http.port: 9200
- 禁用swap:
sudo swapoff -a - 修改linux內核參數
sudo vim /etc/security/limits.conf
添加如下內容:
* soft nofile 65536
* hard nofile 131072
* soft memlock unlimited
* hard memlock unlimited
- 修改虛擬內存空間及swap使用率
sudo vim /etc/sysctl.conf
vm.max_map_count=655360
vm.swappiness=1
sudo sysctl -p
- 修改創建本地線程數
sudo vim /etc/security/limits.d/90-nproc.conf
修改爲
* soft nproc 2048
啓動過程中若存在權限訪問,請授權
開機啓動
vim /etc/rc.local
su - es -c "/usr/local/elasticsearch-5.4.1/bin/elasticsearch -d"
- 瀏覽器訪問驗證
http://192.168.67.152:9200/
3、安裝nodejs
- yum方式安裝 切換到root用戶安裝
curl –silent –location https://rpm.nodesource.com/setup_6.x | bash -
sudo yum -y install nodejs
- xz包方式安裝
xz –d node-v6.10.2-linux-x64.tar.xz
tar xvf node-v6.10.2-linux-x64.tar
mv node-v6.10.2-linux-x64 /usr/local/node
vim /etc/profile
export NODE_HOME=/usr/local/node-v6.10.3-linux-x64
export PATH=$PATH:$NODE_HOME/bin
source /etc/profile
- node –v
v6.10.3
- npm –v
3.10.10
4、安裝elasticsearch-head插件
–安裝head插件需要更改elasticsearch.yml(顯示未連接)
- 是否支持跨域
http.cors.enabled: true
- 表示支持所有域名
http.cors.allow-origin: “*”
- 安裝了xpack,啓用了basic authentication
http.cors.allow-headers: Authorization
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
sudo npm install -g cnpm –registry=https://registry.npm.taobao.org
sudo npm install
修改文件
vim /usr/local/elasticsearch-head/Gruntfile.js
connect: {
server: {
options: {
hostname: '192.168.1.101',
port: 9100,
base: '.',
keepalive: true
}
}
}
修改_site/app.js
vim /usr/local/elasticsearch-head/_site/app.js
修改
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
–>
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.1.101:9200";
- 啓動
npm run start
或者
/usr/local/elasticsearch-head/node_modules/grunt/bin/grunt server &
open http://localhost:9100/
This will start a local webserver running on port 9100 serving elasticsearch-head
- 如果安裝了xpack或Basic Authentication,訪問時使用
http://192.168.1.101:9100/?auth_user=elastic&auth_password=123456
5、安裝elasticsearch-ik分詞器
https://github.com/medcl/elasticsearch-analysis-ik
下載
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.4.0/elasticsearch-analysis-ik-5.4.0.zip
mkdir -p /usr/local/elasticsearch/plugins/ik/
cd /usr/local/elasticsearch/plugins/ik/
上傳到/usr/local/elasticsearch/plugins/ik/elasticsearch-analysis-ik-5.4.0.zip
unzip elasticsearch-analysis-ik-5.4.0.zip
rm -rf elasticsearch-analysis-ik-5.4.0.zip
重新啓動ES節點,顯示如下信息代表加載ik分詞器成功
[es-node01] loaded plugin [analysis-ik]
注意:
在5.0.0之後的版本中,移除名爲 ik 的analyzer和tokenizer,請分別使用 ik_smart 和 ik_max_word
ik_max_word: 會將文本做最細粒度的拆分,比如會將“中華人民共和國國歌”拆分爲“中華人民共和國,中華人民,中華,華人,人民共和國,人民,人,民,共和國,共和,和,國國,國歌”,會窮盡各種可能的組合;
ik_smart: 會做最粗粒度的拆分,比如會將“中華人民共和國國歌”拆分爲“中華人民共和國,國歌”。
測試:
http://192.168.1.101:9200/test/_analyze?text=中華人民共和國MN&tokenizer=ik_max_word
http://192.168.1.101:9200/test/_analyze?text=中華人民共和國MN&tokenizer=ik_smart