docker搭建常用应用以及遇到的坑

Posted wenhuazzz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker搭建常用应用以及遇到的坑相关的知识,希望对你有一定的参考价值。

1. mysql
docker pull mysql:5.7
docker run --name jdb-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=1234 -d mysql:5.7

解决MYSQL中文乱码的问题
1.docker exec进入容器
docker exec -it 78d6e55158ff bash
2.执行以下命令,将 character-set-server=utf8 写入mysql配置文件
echo "character-set-server=utf8" >> /etc/mysql/mysql.conf.d/mysqld.cnf
3.重启mysql 容器使以上修改生效
docker restart 78d6e55158ff


2. Redis
docker pull redis
无密码:docker run --name redis -p 6379:6379 -d redis
有密码:docker run --name jdb-redis -p 6379:6379 -d redis --requirepass "123456"


3. Elasticsearch 拉取:
docker pull elasticsearch:7.5.0
启动
docker run --name myes -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e discovery.type=single-node -d elasticsearch:7.5.0

注:-e discovery.type=single-node 不要忘记

3.1 配置Elasticsearch跨域
进入es容器中,在文件/usr/share/elasticsearch/config/elasticsearch.yml 添加如下语句
http.cors.enabled: true
http.cors.allow-origin: "*"
例:
技术图片

3.2 配置 ik分词器 (就和exlipse安装插件一样,最后都是将插件放到plugins 文件夹下)
下载 地址 https://github.com/medcl/elasticsearch-analysis-ik/releases/download/
3.2.1 在线配置
进入 es容器 /usr/share/elasticsearch/plugins 位置 新建文件夹 "ik" 并进入ik文件夹
下载分词器 的zip包 以7.5.0版本为例
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.5.0/elasticsearch-analysis-ik-7.5.0.zip ( 要是 没有wget 命令 就安装一下 yum install wget)
下载 完成后解压 unzip XXXXXXX ( 要是 没有unzip 命令 就安装一下 yum install unzip)
然后重启容器就好。
3.2.2 离线配置
进入 es容器 /usr/share/elasticsearch/plugins 位置 新建文件夹 "ik" 并进入ik文件夹
在外面下载好ik分词器的zip包 然后cp到容器中
命令: docker cp zip的地址 <容器名>:容器内地址 例子docker cp elasticsearch-analysis-ik-7.5.0.zip myes:/usr/share/elasticsearch/plugins/ik
完成后解压 unzip XXXXXXX ( 要是 没有unzip 命令 就安装一下 yum install unzip)
然后重启容器就好。

4. Kibana
拉取 docker pull kibana:7.5.0
启动
docker run --name mykibana -e ELASTICSEARCH_URL=http://x.x.x.x:9200 -p 5601:5601 -d kibana:7.5.0

注意1: 这个x.x.x.x不是你服务器的IP 而是你elastic容器的 IP ,查看执行以下命令
// 6a8152a1ad8 是你的容器编号
docker inspect XXXXXXX |grep IPAddress
例:

技术图片

 

注意2:
当用7.5.0 版本的时候
要进入 kibana的容器中 配置 /usr/share/kibana/config/kibana.yml 文件 将
elasticsearch.hosts 改成你es容器的ip
然后将xpack.monitoring.ui.container.elasticsearch.enabled 改成 false
配置如下

技术图片

 

如果 不配置 时 ,启动kibana容器不会报错,但是你在页面访问 就一直连不上 并且你看 容器日志的时候 会有如下错误:
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["info","plugins-system"],"pid":6,"message":"Setting up [15] plugins: [timelion,features,security,licensing,spaces,code,uiActions,newsfeed,translations,inspector,embeddable,advancedUiActions,data,expressions,eui_utils]"}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["info","plugins","timelion"],"pid":6,"message":"Setting up plugin"}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["info","plugins","features"],"pid":6,"message":"Setting up plugin"}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["info","plugins","security"],"pid":6,"message":"Setting up plugin"}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["warning","plugins","security","config"],"pid":6,"message":"Generating a random key for xpack.security.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.security.encryptionKey in kibana.yml"}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["warning","plugins","security","config"],"pid":6,"message":"Session cookies will be transmitted over insecure connections. This is not recommended."}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["info","plugins","licensing"],"pid":6,"message":"Setting up plugin"}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["info","plugins","spaces"],"pid":6,"message":"Setting up plugin"}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["info","plugins","code"],"pid":6,"message":"Setting up plugin"}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["info","plugins","translations"],"pid":6,"message":"Setting up plugin"}
{"type":"log","@timestamp":"2019-12-13T07:33:15Z","tags":["info","plugins","data"],"pid":6,"message":"Setting up plugin"}
{"type":"log","@timestamp":"2019-12-13T07:33:40Z","tags":["error","elasticsearch","data"],"pid":6,"message":"Request error, retrying GET http://elasticsearch:9200/_xpack => getaddrinfo ENOTFOUND elasticsearch elasticsearch:9200"}
{"type":"log","@timestamp":"2019-12-13T07:33:41Z","tags":["warning","elasticsearch","data"],"pid":6,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2019-12-13T07:33:41Z","tags":["warning","elasticsearch","data"],"pid":6,"message":"No living connections"}
{"type":"log","@timestamp":"2019-12-13T07:33:41Z","tags":["warning","plugins","licensing"],"pid":6,"message":"License information could not be obtained from Elasticsearch for the [data] cluster. Error: No Living connections"}
{"type":"log","@timestamp":"2019-12-13T07:33:41Z","tags":["warning","legacy-plugins"],"pid":6,"path":"/usr/share/kibana/src/legacy/core_plugins/visualizations","message":"Skipping non-plugin directory at /usr/share/kibana/src/legacy/core_plugins/visualizations"}
{"type":"log","@timestamp":"2019-12-13T07:33:42Z","tags":["info","plugins-system"],"pid":6,"message":"Starting [8] plugins: [timelion,features,security,licensing,spaces,code,translations,data]"}
{"type":"log","@timestamp":"2019-12-13T07:33:42Z","tags":["error","elasticsearch","admin"],"pid":6,"message":"Request error, retrying GET http://elasticsearch:9200/.kibana_task_manager => getaddrinfo ENOTFOUND elasticsearch elasticsearch:9200"}
{"type":"log","@timestamp":"2019-12-13T07:33:42Z","tags":["error","elasticsearch","admin"],"pid":6,"message":"Request error, retrying GET http://elasticsearch:9200/.kibana => getaddrinfo ENOTFOUND elasticsearch elasticsearch:9200"}
{"type":"log","@timestamp":"2019-12-13T07:33:42Z","tags":["warning","elasticsearch","admin"],"pid":6,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2019-12-13T07:33:42Z","tags":["warning","elasticsearch","admin"],"pid":6,"message":"No living connections"}
{"type":"log","@timestamp":"2019-12-13T07:33:42Z","tags":["warning","migrations"],"pid":6,"message":"Unable to connect to Elasticsearch. Error: No Living connections"}
{"type":"log","@timestamp":"2019-12-13T07:33:42Z","tags":["warning","elasticsearch","admin"],"pid":6,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2019-12-13T07:33:42Z","tags":["warning","elasticsearch","admin"],"pid":6,"message":"No living connections"}
{"type":"log","@timestamp":"2019-12-13T07:33:44Z","tags":["warning","elasticsearch","admin"],"pid":6,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2019-12-13T07:33:44Z","tags":["warning","elasticsearch","admin"],"pid":6,"message":"No living connections"}
{"type":"log","@timestamp":"2019-12-13T07:33:44Z","tags":["warning","elasticsearch","admin"],"pid":6,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2019-12-13T07:33:44Z","tags":["warning","elasticsearch","admin"],"pid":6,"message":"No living connections"}
{"type":"log","@timestamp":"2019-12-13T07:33:46Z","tags":["warning","elasticsearch","data"],"pid":6,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2019-12-13T07:33:46Z","tags":["warning","elasticsearch","data"],"pid":6,"message":"No living connections"}
{"type":"log","@timestamp":"2019-12-13T07:33:46Z","tags":["warning","plugins","licensing"],"pid":6,"message":"License information could not be obtained from Elasticsearch for the [data]

5. 安装 elasticsearch-head
拉取
docker pull mobz/elasticsearch-head:5
创建容器
docker run --name elasticsearch-head -p 9100:9100 mobz/elasticsearch-head:5

注: ElasticSearch-head 操作时(包含操作索引,基本查询等),一直显示查询中,控制台报错报 406错误码
进入/usr/src/app/_site 目录,编辑vendor.js 共有两处

      ①. 6886行 contentType: "application/x-www-form-urlencoded

         改成

         contentType: "application/json;charset=UTF-8"

      ②. 7574行 var inspectData = s.contentType === "application/x-www-form-urlencoded" &&

        改成

       var inspectData = s.contentType === "application/json;charset=UTF-8" &&

以上是关于docker搭建常用应用以及遇到的坑的主要内容,如果未能解决你的问题,请参考以下文章

docker搭建题目遇到的坑

我在部署docker的时候遇到的坑

python+selenium环境搭建以及遇到的坑

Centos7.4 搭建FTP服务器以及遇到的坑

LVS详细介绍以及遇到的坑

Docker实践中遇到的坑