1、下载镜像
[root@localhost mydata]# docker run -p 80:80 --name nginx -d nginx:1.10
Unable to find image 'nginx:1.10' locally
1.10: Pulling from library/nginx
6d827a3ef358: Pull complete
1e3e18a64ea9: Pull complete
556c62bb43ac: Pull complete
Digest: sha256:6202beb06ea61f44179e02ca965e8e13b961d12640101fca213efbfd145d7575
Status: Downloaded newer image for nginx:1.10
362917ba113e79615c209bf3cb758697cb34b00a8eb5a11b7c37109e5cc09890
2、查看启动容器
[root@localhost mydata]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
362917ba113e nginx:1.10 "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp nginx
fe709eb23b01 elasticsearch:7.4.2 "/usr/local/bin/dock…" 5 minutes ago Up 5 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
c628be051a39 kibana:7.4.2 "/usr/local/bin/dumb…" 21 hours ago Up 30 minutes 0.0.0.0:5601->5601/tcp, :::5601->5601/tcp kibana
e9687b99f262 redis "docker-entrypoint.s…" 2 weeks ago Up 30 minutes 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis
799d0d600e70 mysql:5.7 "docker-entrypoint.s…" 2 weeks ago Up 30 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
[root@localhost mydata]#
3、在 mydata下新建nginx目录
[root@localhost mydata]# mkdir nginx
[root@localhost mydata]# ls
elasticsearch mysql nginx redis
4、将配置文件复制到新nginx目录下
[root@localhost mydata]# docker container cp nginx:/etc/nginx .
[root@localhost mydata]# cd nginx/
[root@localhost nginx]# ls
conf.d koi-utf mime.types nginx.conf uwsgi_params
fastcgi_params koi-win modules scgi_params win-utf
5、删除原nginx
[root@localhost nginx]# docker stop nginx
nginx
[root@localhost nginx]# docker rm nginx
nginx
6、将nginx改名为conf,并将之移动到新的nginx目录里,为了分类更清晰
[root@localhost mydata]# ls
elasticsearch mysql nginx redis
[root@localhost mydata]# mv nginx conf
[root@localhost mydata]# ls
conf elasticsearch mysql redis
[root@localhost mydata]# mkdir nginx
[root@localhost mydata]# mv conf/ nginx/
[root@localhost mydata]# ls
elasticsearch mysql nginx redis
[root@localhost mydata]# cd nginx/
[root@localhost nginx]# ls
conf
[root@localhost nginx]#
7、运行自己需要的nginx
[root@localhost nginx]# docker run -p 80:80 --name nginx \
> -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
14ce70afd62b0313ecfd6701d68015225927eec19310a5d538df5c6633463484
[root@localhost nginx]#
8、nginx已启动
[root@localhost nginx]# ls
conf html logs
[root@localhost nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
14ce70afd62b nginx:1.10 "nginx -g 'daemon of…" 29 seconds ago Up 28 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp nginx
fe709eb23b01 elasticsearch:7.4.2 "/usr/local/bin/dock…" 25 minutes ago Up 25 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
c628be051a39 kibana:7.4.2 "/usr/local/bin/dumb…" 22 hours ago Up 50 minutes 0.0.0.0:5601->5601/tcp, :::5601->5601/tcp kibana
e9687b99f262 redis "docker-entrypoint.s…" 2 weeks ago Up 50 minutes 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis
799d0d600e70 mysql:5.7 "docker-entrypoint.s…" 2 weeks ago Up 50 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
[root@localhost nginx]#
9、编写测试页面
vi /mydata/nginx/html/index.html
#填写以下内容
<h1>hello nginx</h1>
[root@localhost nginx]# vi /mydata/nginx/html/index.html
[root@localhost nginx]# mkdir /mydata/nginx/html/es
[root@localhost nginx]# cd /mydata/nginx/html/es/
[root@localhost es]# vi fenci.txt
#自定义填写词
笨蛋不是蛋
[root@localhost es]#
11、修改ik分词器配置
[root@localhost es]# cd /mydata/elasticsearch/plugins/ik/config/
[root@localhost config]# ls
extra_main.dic extra_single_word_low_freq.dic main.dic stopword.dic
extra_single_word.dic extra_stopword.dic preposition.dic suffix.dic
extra_single_word_full.dic IKAnalyzer.cfg.xml quantifier.dic surname.dic
[root@localhost config]# vi IKAnalyzer.cfg.xml
配置远程扩展字典 IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict"></entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<entry key="remote_ext_dict">http://192.168.56.10/es/fenci.txt
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- words_location -->
</properties>
12、重启elasticsearch
docker restart elasticsearch
13、kibana重新测试分词效果
nginx设置虚拟机开机自启动
[root@localhost ~]# docker update nginx --restart=always
nginx
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe709eb23b01 elasticsearch:7.4.2 "/usr/local/bin/dock…" 3 days ago Up 6 hours 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
c628be051a39 kibana:7.4.2 "/usr/local/bin/dumb…" 4 days ago Up 6 hours 0.0.0.0:5601->5601/tcp, :::5601->5601/tcp kibana
e9687b99f262 redis "docker-entrypoint.s…" 2 weeks ago Up 6 hours 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis
799d0d600e70 mysql:5.7 "docker-entrypoint.s…" 2 weeks ago Up 6 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
[root@localhost ~]# docker start nginx
nginx
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
14ce70afd62b nginx:1.10 "nginx -g 'daemon of…" 3 days ago Up 4 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp nginx
fe709eb23b01 elasticsearch:7.4.2 "/usr/local/bin/dock…" 3 days ago Up 6 hours 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
c628be051a39 kibana:7.4.2 "/usr/local/bin/dumb…" 4 days ago Up 6 hours 0.0.0.0:5601->5601/tcp, :::5601->5601/tcp kibana
e9687b99f262 redis "docker-entrypoint.s…" 2 weeks ago Up 6 hours 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis
799d0d600e70 mysql:5.7 "docker-entrypoint.s…" 2 weeks ago Up 6 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
[root@localhost ~]#
小结
ik分词器配置远程扩展字典,将远程分词字典配置在nginx的/mydata/nginx/html/es/fenci.txt
目录下,之后添加新词只需在fenci.txt
分词表里添加即可