您的位置:首页 > 运维架构 > Linux

centos7-elasticsearch安装配置

2017-06-23 07:56 531 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  elasticsearch