1.docker 容器化部署nginx

  1. 创建 在docker host暴露80端口 ```shell

    创建docker nginx

    docker run -d -p 80:80 —name nginx-server-port -v /opt/nginx-server-port:/usr/share/nginx/html:ro nginx
  1. 2. 挂载配置文件 创建nginx
  2. ```shell
  3. ## 创建挂载文件的目录
  4. mkdir -p /opt/docker/nginx/conf
  5. ## 拷贝docker 容器中的nginx 配置文件
  6. docker cp nginx-server-port:/etc/nginx/nginx.conf /opt/docker/nginx/conf
  7. ## 创建启动docker容器
  8. docker run -d -p 82:80 --name nginx-server-conf -v /opt/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro -v /opt/docker/nginx/html:/usr/share/nginx/html:ro nginx
  9. ## 创建index.html
  10. echo "nginx is running" > /opt/docker/nginx/html/index.html
  1. 浏览器访问http://10.0.0.10 :80 显示 nginx is runing 表示容器启动成功

    2. docker 容器化部署tomcat

  2. 创建docker 容器

    1. ## 创建tomcat docker应用
    2. docker run -d -p 8081:8080 -v /opt/docker/tomcat/:/usr/local/tomcat/webapps/ROOT tomcat:9.0
    3. ## 创建tomcat文件
    4. echo "tomcat running" > /opt/docker/tomcat/index.html
  3. 浏览器访问http://10.0.0.10 :8081 显示 tomcat is runing 表示容器启动成功

    3. docker容器化部署mysql

    3.1docker容器化部署单节点mysql

    1. ## 创建docker 容器
    2. docker run -p 3306:3306 --name mysql -v /opt/docker/mysql/log:/var/log/mysql -v /opt/docker/mysql/data:/var/lib/mysql -v /opt/docker/mysql/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=ro
    3. ot -d mysql:5.7
    4. ## 访问mysql数据库
    5. docker exec -it mysql mysql -uroot -proot

    3.2.docker 容器化部署mysql 主从复制

    MySQL主节点部署

    1. docker run -p 3307:3306 --name mysql-master -v /opt/docker/mysql-master/log:/var/log/mysql -v /opt/docker/mysql-master/data:/var/lib/mysql -v /opt/docker/mysql-master/conf:/etc/mys
    2. ql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7

    MySQL主节点配置

    ```shell vim /opt/docker/mysql-master/conf/my.cnf

    加入如下配置

    [client] default-character-set=utf8

[mysql] default-character-set=utf8

[mysqld] init_connect=’SET collation_connection = utf8_unicode_ci’ init_connect=’SET NAMES utf8’ character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve

server_id=1 log-bin=mysql-bin read-only=0 binlog-do-db=kubemsb_test

replicate-ignore-db=mysql replicate-ignore-db=sys replicate-ignore-db=information_schema replicate-ignore-db=performance_schema

重启 docker mysql-master

docker restart mysql-master

  1. <a name="cpQfK"></a>
  2. #### mysql从节点部署
  3. ```shell
  4. docker run -p 3308:3306 --name mysql-slave -v /opt/docker/mysql-slave/log:/var/log/mysql -v /opt/docker/mysql-slave/data:/var/lib/mysql -v /opt/docker/mysql-slave/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=root -d --link mysql-master:mysql-master mysql:5.7

mysql从节点配置

  1. vim /opt/docker/mysql-slave/conf/my.cnf
  2. ## 配置如下内容
  3. [client]
  4. default-character-set=utf8
  5. [mysql]
  6. default-character-set=utf8
  7. [mysqld]
  8. init_connect='SET collation_connection = utf8_unicode_ci'
  9. init_connect='SET NAMES utf8'
  10. character-set-server=utf8
  11. collation-server=utf8_unicode_ci
  12. skip-character-set-client-handshake
  13. skip-name-resolve
  14. server_id=2
  15. log-bin=mysql-bin
  16. read-only=1
  17. binlog-do-db=kubemsb_test
  18. replicate-ignore-db=mysql
  19. replicate-ignore-db=sys
  20. replicate-ignore-db=information_schema
  21. replicate-ignore-db=performance_schema
  22. ## 重启 docker mysql-master
  23. docker restart mysql-slave

master节点配置

  1. ## 进入mysql master 容器 并进入mysql数据库
  2. docker exec -it mysql-master mysql -uroot -proot -P 3307
  3. ## 执行授权配置
  4. MySQL [(none)]> grant replication slave on *.* to 'backup'@'%' identified by '123456';
  5. ## 退出容器 重启容器
  6. docker restart mysql-master
  7. #查看配置是否生效
  8. show master status\G

slave节点配置

  1. ## 进入mysql master 容器 并进入mysql数据库
  2. docker exec -it mysql-slave mysql -uroot -proot -P 3308
  3. ## 执行授权配置
  4. MySQL [(none)]> change master to master_host='mysql-master', master_user='backup', master_password='123456', master_log_file='mysql-bin.000002', master_log_pos=154, master_port=3306;
  5. ## 退出容器 重启容器
  6. docker restart mysql-master
  7. #查看配置是否生效
  8. show master status\G

验证MySQL集群可用性

  1. #在MySQL Master节点添加kubemsb_test数据库
  2. docker exec -it mysql-master mysql -uroot -proot -P 3307
  3. MySQL [(none)]> create database kubemsb_test;
  4. MySQL [(none)]> show databases;
  5. mysql> show databases;
  6. +--------------------+
  7. | Database |
  8. +--------------------+
  9. | information_schema |
  10. | kubemsb_test |
  11. | mysql |
  12. | performance_schema |
  13. | sys |
  14. +--------------------+
  15. 5 rows in set (0.00 sec)
  1. #在MySQL Slave节点查看同步情况
  2. docker exec -it mysql-slave mysql -uroot -proot -P 3308
  3. mysql> show databases;
  4. +--------------------+
  5. | Database |
  6. +--------------------+
  7. | information_schema |
  8. | kubemsb_test |
  9. | mysql |
  10. | performance_schema |
  11. | sys |
  12. +--------------------+
  13. 5 rows in set (0.00 sec)
  14. ## master 和slave 同时出现kubemsb_test 数据库 说明 主从数据库配置成功

4. docker 容器化部署oracle

  1. ## 下载docker 容器
  2. docker pull oracleinanutshell/oracle-xe-11g
  3. ## 启动docker 氢气
  4. docker run -h oracle --name oracle -d -p 49160:22 -p 49161:1521 -p 49162:8080 oracleinanutshell/oracle-xe-11g
  5. ## 说明
  6. 49160 ssh端口
  7. 49161 sqlplus端口
  8. 49162 oem端口
  9. oracle数据库连接信息
  10. port:49161
  11. sid:xe
  12. username:system
  13. password:oracle
  14. SYS用户密码为:oracle

下载 sqldeveloper 测试连接oracle
image.png

1.png

5. docker 容器化部署elasticeSearch和kibana

5.1 docker 部署 es

  1. ## 下载es容器
  2. docker pull elasticsearch:7.17.0
  3. ##
  4. mkdir -p /opt/docker/es/config
  5. mkdir -p /opt/docker/es/data
  6. echo "http.host: 0.0.0.0" >> /opt/docker/es/config/elasticsearch.yml
  7. chmod -R 777 /opt/docker/es/
  8. ## 启动docker容器
  9. docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
  10. -e "discovery.type=single-node" \
  11. -e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
  12. -v /opt/docker/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
  13. -v /opt/docker/es/data:/usr/share/elasticsearch/data \
  14. -v /opt/docker/es/plugins:/usr/share/elasticsearch/plugins \
  15. -d elasticsearch:7.17.0

访问 http://10.0.0.10:9200
image.png

5.2 docker 部署kibana

  1. ## 下载 kibana
  2. docker pull kibana:7.17.0
  3. #启动docker 容器
  4. docker run --name kibana -e ELASTICSEARCH_HOSTS=http://10.0.0.10:9200 -p 5601:5601 \
  5. -d kibana:7.17.0

浏览器访问 http://10.0.0.10:5601
image.png

6. docker 容器化部署Redis

6.1 docker容器化部署单节点Redis

  1. mkdir -p /opt/docker/redis/conf
  2. touch /opt/docker/redis/conf/redis.conf
  3. docker run -p 6379:6379 --name redis -v /opt/docker/redis/data:/data \
  4. -v /opt/docker/redis/conf:/etc/redis \
  5. -d redis redis-server /etc/redis/redis.conf

验证redis 安装是否成功

  1. [root@localhost ~]# docker exec -it redis redis-cli
  2. 127.0.0.1:6379> set key1 abc
  3. OK
  4. 127.0.0.1:6379> get key1 abc
  5. "abc"

6.2 docker 容器化部署Redis集群

安装redis-cluster;3主3从方式,从为了同步备份,主进行slot数据分片

  1. vim redis-cluster.sh
  2. ## 脚本内容如下
  3. for port in $(seq 8001 8006); \
  4. do \
  5. mkdir -p /opt/docker/redis-cluster/redis/node-${port}/conf
  6. touch /opt/docker/redis-cluster/redis/node-${port}/conf/redis.conf
  7. cat << EOF >/opt/docker/redis-cluster/redis/node-${port}/conf/redis.conf
  8. port ${port}
  9. cluster-enabled yes
  10. cluster-config-file nodes.conf
  11. cluster-node-timeout 5000
  12. cluster-announce-ip 10.0.0.10
  13. cluster-announce-port ${port}
  14. cluster-announce-bus-port 1${port}
  15. appendonly yes
  16. EOF
  17. docker run -p ${port}:${port} -p 1${port}:1${port} --name redis-${port} \
  18. -v /opt/docker/redis-cluster/redis/node-${port}/data:/data \
  19. -v /opt/docker/redis-cluster/redis/node-${port}/conf/redis.conf:/etc/redis/redis.conf \
  20. -d redis:5.0.7 redis-server /etc/redis/redis.conf; \
  21. done
  22. ## 执行脚本
  23. sh redis-cluster.sh

登录容器进行配置

  1. ##登录redis容器
  2. docker exec -it redis-8001 bash
  3. ## 创建redis-cluster
  4. root@d47c3843ed2c:/data# redis-cli --cluster create 10.0.0.10:8001 10.0.0.10:8002 10.0.0.10:8003 10.0.0.10:8004 10.0.0.10:8005 10.0.0.10:8006 --cluster-replicas 1
  5. ## 输出如下
  6. >>> Performing hash slots allocation on 6 nodes...
  7. Master[0] -> Slots 0 - 5460
  8. Master[1] -> Slots 5461 - 10922
  9. Master[2] -> Slots 10923 - 16383
  10. Adding replica 10.0.0.10:8005 to 10.0.0.10:8001
  11. Adding replica 10.0.0.10:8006 to 10.0.0.10:8002
  12. Adding replica 10.0.0.10:8004 to 10.0.0.10:8003
  13. >>> Trying to optimize slaves allocation for anti-affinity
  14. [WARNING] Some slaves are in the same host as their master
  15. M: 996456e419e8510e308395b42764bc8b6f9cc2fa 10.0.0.10:8001
  16. slots:[0-5460] (5461 slots) master
  17. M: 5ad906a397cbf4d6a7ed75701579080101da46f0 10.0.0.10:8002
  18. slots:[5461-10922] (5462 slots) master
  19. M: 85ae27fe8fea16019b47b62cdcf2688f8e4ce6cc 10.0.0.10:8003
  20. slots:[10923-16383] (5461 slots) master
  21. S: ffaa41fc81a8afca768c5e8982bf3d26106edf78 10.0.0.10:8004
  22. replicates 85ae27fe8fea16019b47b62cdcf2688f8e4ce6cc
  23. S: dcb74d0322a8cc1cac645259f9e3c425db8ad4a6 10.0.0.10:8005
  24. replicates 996456e419e8510e308395b42764bc8b6f9cc2fa
  25. S: 2d52bc15414aab82b8da79b1fdf4d1e51bf0ce9e 10.0.0.10:8006
  26. replicates 5ad906a397cbf4d6a7ed75701579080101da46f0
  27. Can I set the above configuration? (type 'yes' to accept): yes
  28. >>> Nodes configuration updated
  29. >>> Assign a different config epoch to each node
  30. >>> Sending CLUSTER MEET messages to join the cluster
  31. Waiting for the cluster to join
  32. ...
  33. >>> Performing Cluster Check (using node 10.0.0.10:8001)
  34. M: 996456e419e8510e308395b42764bc8b6f9cc2fa 10.0.0.10:8001
  35. slots:[0-5460] (5461 slots) master
  36. 1 additional replica(s)
  37. S: ffaa41fc81a8afca768c5e8982bf3d26106edf78 10.0.0.10:8004
  38. slots: (0 slots) slave
  39. replicates 85ae27fe8fea16019b47b62cdcf2688f8e4ce6cc
  40. S: 2d52bc15414aab82b8da79b1fdf4d1e51bf0ce9e 10.0.0.10:8006
  41. slots: (0 slots) slave
  42. replicates 5ad906a397cbf4d6a7ed75701579080101da46f0
  43. M: 5ad906a397cbf4d6a7ed75701579080101da46f0 10.0.0.10:8002
  44. slots:[5461-10922] (5462 slots) master
  45. 1 additional replica(s)
  46. M: 85ae27fe8fea16019b47b62cdcf2688f8e4ce6cc 10.0.0.10:8003
  47. slots:[10923-16383] (5461 slots) master
  48. 1 additional replica(s)
  49. S: dcb74d0322a8cc1cac645259f9e3c425db8ad4a6 10.0.0.10:8005
  50. slots: (0 slots) slave
  51. replicates 996456e419e8510e308395b42764bc8b6f9cc2fa
  52. [OK] All nodes agree about slots configuration.
  53. >>> Check for open slots...
  54. >>> Check slots coverage...
  55. [OK] All 16384 slots covered.

验证集群

  1. ## 进入容器执行命令
  2. docker exec -it redis-8001 redis-cli -c -p 8001
  3. 127.0.0.1:8001> set key1 abc
  4. -> Redirected to slot [9189] located at 10.0.0.10:8002
  5. OK
  6. 10.0.0.10:8002>

7. docker容器化部署RabbitMQ

  1. docker run -d --name rabbitmq -p 5671:5671 -p 5672:5672 -p 4369:4369 -p 25672:25672 -p 15671:15671 -p 15672:15672 -v /opt/docker/rabbitmq:/var/lib/rabbitmq rabbitmq:management
  2. ##
  3. 端口说明:
  4. 4369, 25672 (Erlang发现&集群端口)
  5. 5672, 5671 (AMQP端口)
  6. 15672 (web管理后台端口)
  7. 61613, 61614 (STOMP协议端口)
  8. 1883, 8883 (MQTT协议端口)

浏览器访问http://10.0.0.10:15672 ; 用户名/密码 guest/guest
image.png
image.png