1.拉镜像
拉镜像
docker pull elasticsearch:7.4.2
docker pull kibana:7.4.2
2.建设目录
mkdir -p /mydata/elasticsearch/config # 用来存放配置文件
mkdir -p /mydata/elasticsearch/data # 数据
echo "http.host: 0.0.0.0" >/mydata/elasticsearch/config/elasticsearch.yml # 允许任何机器访问
chmod -R 777 /mydata/elasticsearch/ ## 设置elasticsearch文件可读写权限
3.启动
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.4.2
docker update elasticsearch --restart=always
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://216.127.*.*:9200 -p 5601:5601 -d kibana:7.4.2
4.测试
http://216.127.*.*:9200/
05.ik 分词
GET _analyze
{
"analyzer": "standard",
"text":"I love me"
}
cd /mydata/elasticsearch/plugins
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.2/elasticsearch-analysis-ik-7.4.2.zip
unzip elasticsearch-analysis-ik-7.4.2.zip -d ./ik
chmod -R 777 ik/
./bin/elasticsearch-plugin list
GET _analyze
{
"text": "我是中国人"
}
GET _analyze
{
"analyzer":"ik_smart",
"text": "我是中国人"
}
GET _analyze
{
"analyzer":"ik_max_word",
"text": "我是中国人"
}
06.自定义
docker run -p 15999:80 --name nginx2 -d nginx:1.10
root@zhenqk:/mydata# docker cp nginx2:/etc/nginx .
mv nginx conf
mv conf ./nginx/
docker stop d110
docker rm d110
docker run -p 15999:80 --name nginx2 \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/logs:/var/log/nginx \
-v /mydata/nginx/conf/:/etc/nginx \
-d nginx:1.10
# 中文乱码
/mydata/nginx/conf/conf.d
default.conf
charset utf-8;
cd /usr/sbin/
./nginx -s reload
https://github.com/KennFalcon/elasticsearch-analysis-hanlp/releases/download/v7.4.2/elasticsearch-analysis-hanlp-7.4.2.zip
b. 执行如下命令安装,其中 PATH 为插件包绝对路径:
./bin/elasticsearch-plugin install file://${PATH}
方式二
a. 使用 elasticsearch 插件脚本安装命令如下:
./bin/elasticsearch-plugin install https://github.com/KennFalcon/elasticsearch-analysis-hanlp/releases/download/v7.4.2/elasticsearch-analysis-hanlp-7.4.2.zip
请注意,release 包中存放的为 HanLP 源码中默认的分词数据,若要下载完整版数据包,可查看HanLP Release。数据包目录:ES_HOME/plugins/analysis-hanlp,因原版数据包自定义词典部分文件名为中文,这里的hanlp.properties中已修改为英文,使用时请对应修改文件名。
在本版本中增加了词典热更新,修改步骤如下:(每个节点都需要做这种更改)
- 在ES_HOME/plugins/analysis-hanlp/data/dictionary/custom目录中新增自定义词典;
- 修改hanlp.properties,修改CustomDictionaryPath,增加自定义词典配置;
- 等待1分钟后,词典自动加载。
hanlp 中文分词器的分词方式有:
hanlp: hanlp默认分词
hanlp_standard: 标准分词
hanlp_index: 索引分词
hanlp_nlp: NLP分词
hanlp_n_short: N-最短路分词
hanlp_dijkstra: 最短路分词
hanlp_crf: CRF分词(已有最新方式)
hanlp_speed: 极速词典分词
GET http://192.168.150.130:9200/_analyze
{
"tokenizer": "hanlp",
"text": "四川汶川发生8.0级地震"
}
https://github.com/KennFalcon/elasticsearch-analysis-hanlp