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
node

附加: 掛在外部數據卷的啓動
建立外部數據卷
docker volume create my-datamysql

查看數據卷的列表
docker volume ls
查看數據卷的信息
docker volume inspect my-datagit

查看位置:
find /. -name my-data
啓動:
docker run --name jdb-mysql -v my-data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=1234 -d mysql:5.7github

 

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 redis

拉取:
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: "*"
例:
sql

3.2 配置 ik分詞器 (就和exlipse安裝插件同樣,最後都是將插件放到plugins 文件夾下)
下載 地址 https://github.com/medcl/elasticsearch-analysis-ik/releases
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.0docker

注意1: 這個x.x.x.x不是你服務器的IP 而是你elastic容器的 IP ,查看執行如下命令
// 6a8152a1ad8 是你的容器編號
docker inspect XXXXXXX |grep IPAddress
例:express

 

注意2:
當用7.5.0 版本的時候
要進入 kibana的容器中 配置 /usr/share/kibana/config/kibana.yml 文件 將
elasticsearch.hosts 改爲你es容器的ip
而後將xpack.monitoring.ui.container.elasticsearch.enabled 改爲 false
配置以下json

 

若是 不配置 時 ,啓動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\nGET 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\nGET 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\nGET 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" &&

相關文章
相關標籤/搜索