kubeSphere搭建中间件
2022-05-01 本文已影响0人
攻城老狮
本文是作者学习kubeSphere过程中的具体搭建流程,供需要的小伙伴一起学习进步,具体中间件包括:MySQL、Redis、ElasticSearch、RabbitMQ。搭建的过程从最基础的部分开始,可能比直接通过应用商店部署应用的方式复杂。但可以更加深入理解整体的搭建过程。后续真实需求场景,为方便起见,可以考虑直接通过应用商店的方式部署。本文的RabbitMQ中间件采用了应用的方式部署,供读者参考。enjoy!
1 MySQL搭建
![](https://img.haomeiwen.com/i13992547/952fce5ea41a7a49.png)
1.1 添加mysql的配置文件
- 创建新的配置文件
![](https://img.haomeiwen.com/i13992547/1d545003286c36b5.png)
- 编辑conf的基本信息,包括名称和描述信息
![](https://img.haomeiwen.com/i13992547/cdeae1d0b1d7c264.png)
- 编辑conf的配置信息,其中的键作为文件名,值作为文件中的内容
![](https://img.haomeiwen.com/i13992547/ebe976ea0f3b96d8.png)
# my.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
- 创建配置文件成功
![](https://img.haomeiwen.com/i13992547/697c940918d5422e.png)
1.2 创建mysql的服务
- 创建新的服务
![](https://img.haomeiwen.com/i13992547/fb595a0b0a23829e.png)
- 由于mysql需要保存数据,需要创建有状态的服务
![](https://img.haomeiwen.com/i13992547/7fd259729bc73d9c.png)
- 编写服务的基本信息
![](https://img.haomeiwen.com/i13992547/c72016817b1c270f.png)
- 添加容器镜像
![](https://img.haomeiwen.com/i13992547/30277d6f24cd42b2.png)
- 初始化密码设置并同步主机时区
MYSQL_ROOT_PASSWORD=199748
![](https://img.haomeiwen.com/i13992547/e6023a0db63ab2e3.png)
- 添加挂载的存储卷模版(模块会为每个实例挂载对应的data卷,而不是只存在一个卷被所有实例共享)
/var/lib/mysql
![](https://img.haomeiwen.com/i13992547/d542bbfd16a8ab32.png)
![](https://img.haomeiwen.com/i13992547/e82054886ee0287e.png)
- 添加服务的配置文件(会将配置文件挂载至对应的挂载目录下,仅仅包含挂载的文件,其他文件存在也会被覆盖)
/etc/mysql/conf.d
![](https://img.haomeiwen.com/i13992547/0918073f26907629.png)
![](https://img.haomeiwen.com/i13992547/433558980a309092.png)
1.3 配置外网访问端口
- 创建自定义方式的服务
![](https://img.haomeiwen.com/i13992547/faaf4d5b3cfc0997.png)
- 编写服务基本信息
![](https://img.haomeiwen.com/i13992547/d2d3bc0b213ee80f.png)
- 指定工作负载,并设置容器端口
![](https://img.haomeiwen.com/i13992547/a31c1527add884e2.png)
- 指定外网访问
![](https://img.haomeiwen.com/i13992547/7e2f08871906247a.png)
![](https://img.haomeiwen.com/i13992547/c250ae80453b9632.png)
1.4 连接测试
- 集群内部可以通过DNS域名访问mysql
![](https://img.haomeiwen.com/i13992547/9b2ed48cad24bf35.png)
- 集群外部可以通过NodePort暴露的port访问
![](https://img.haomeiwen.com/i13992547/83ae4b0389042265.png)
2 Redis 搭建
![](https://img.haomeiwen.com/i13992547/e4db3a67c221f4d6.png)
2.1 添加 redis 配置文件
- 创建新的配置文件,填写redis的基本信息
![](https://img.haomeiwen.com/i13992547/7b2385d7900657b8.png)
- 编辑conf的配置信息,其中的键作为文件名,值作为文件中的内容
# redis.conf
appendonly yes
port 6379
bind 0.0.0.0
![](https://img.haomeiwen.com/i13992547/90abb342f43ae900.png)
- 创建配置文件成功
![](https://img.haomeiwen.com/i13992547/9da13b4d84caf8d4.png)
2.2 创建 redis 的服务
- 创建新的服务,由于redis需要缓存数据至本地,需要创建有状态的服务
![](https://img.haomeiwen.com/i13992547/2439086eb588a822.png)
- 编写服务的基本信息
![](https://img.haomeiwen.com/i13992547/b0181f506e8a0ff0.png)
- 添加容器
![](https://img.haomeiwen.com/i13992547/38cebcf127635cd4.png)
- 添加redis的启动命令并同步主机时区
redis-server /etc/redis/redis.conf
![](https://img.haomeiwen.com/i13992547/c9051bb19894d4b3.png)
- 添加挂载的存储卷模版(模块会为每个实例挂载对应的data卷,而不是只存在一个卷被所有实例共享)
/data
![](https://img.haomeiwen.com/i13992547/8975de125b53476f.png)
![](https://img.haomeiwen.com/i13992547/b96a48926d3e84c4.png)
- 添加服务的配置文件(会将配置文件挂载至对应的挂载目录下,仅仅包含挂载的文件,其他文件存在也会被覆盖)
/etc/redis/
![](https://img.haomeiwen.com/i13992547/55de79e2d5d7313e.png)
2.3 配置外网访问端口
参考 MySQL 搭建的流程,与其一致,指定为NodePort形式
2.4 连接测试
- 集群内部可以通过DNS域名访问 redis
![](https://img.haomeiwen.com/i13992547/da6fdc05f265d850.png)
- 集群外部可以通过NodePort暴露的port访问
![](https://img.haomeiwen.com/i13992547/ec67d667e9212aa2.png)
3 ElasticSearch 搭建
![](https://img.haomeiwen.com/i13992547/2a0e1478a25eef0f.png)
3.1 添加 ES 配置文件
- 编写基础配置信息
![](https://img.haomeiwen.com/i13992547/9c7cee9d65ea7bdf.png)
- 添加两个配置信息
- elasticsearch配置信息
# elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
![](https://img.haomeiwen.com/i13992547/81238a6ef306db5a.png)
- jvm配置信息
# jvm.options
################################################################
##
## JVM configuration
##
################################################################
##
## WARNING: DO NOT EDIT THIS FILE. If you want to override the
## JVM options in this file, or set any additional options, you
## should create one or more files in the jvm.options.d
## directory containing your adjustments.
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
## for more information.
##
################################################################
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## and the min and max should be set to the same value. For
## example, to set the heap to 4 GB, create a new file in the
## jvm.options.d directory containing these lines:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
################################################################
## Expert settings
################################################################
##
## All settings below here are considered expert settings. Do
## not adjust them unless you understand what you are doing. Do
## not edit them in this file; instead, create a new file in the
## jvm.options.d directory containing your adjustments.
##
################################################################
## GC configuration
8-13:-XX:+UseConcMarkSweepGC
8-13:-XX:CMSInitiatingOccupancyFraction=75
8-13:-XX:+UseCMSInitiatingOccupancyOnly
## G1GC Configuration
# NOTE: G1 GC is only supported on JDK version 10 or later
# to use G1GC, uncomment the next two lines and update the version on the
# following three lines to your version of the JDK
# 10-13:-XX:-UseConcMarkSweepGC
# 10-13:-XX:-UseCMSInitiatingOccupancyOnly
14-:-XX:+UseG1GC
## JVM temporary directory
-Djava.io.tmpdir=${ES_TMPDIR}
## heap dumps
# generate a heap dump when an allocation from the Java heap fails; heap dumps
# are created in the working directory of the JVM unless an alternative path is
# specified
-XX:+HeapDumpOnOutOfMemoryError
# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data
# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log
## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m
# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
![](https://img.haomeiwen.com/i13992547/ca7fefee2c078640.png)
- 创建配置文件成功
![](https://img.haomeiwen.com/i13992547/499d07f62fbd9f84.png)
3.2 创建 es 服务
- 创建有状态服务,由于es需要存储数据
![](https://img.haomeiwen.com/i13992547/ea510369753fc41c.png)
- 编写服务基本信息
![](https://img.haomeiwen.com/i13992547/bd4fa903f75c3de6.png)
- 添加镜像
![](https://img.haomeiwen.com/i13992547/0d515f8916c1d0e9.png)
- 添加环境变量
discovery.type single-node
ES_JAVA_OPTS -Xms512m -Xmx512m
![](https://img.haomeiwen.com/i13992547/48b4f331a9ead0aa.png)
- 挂载存储模版
/usr/share/elasticsearch/data
![](https://img.haomeiwen.com/i13992547/d5323ae22b3e64c9.png)
- 挂载两个配置文件
- 挂载第一个配置文件
/usr/share/elasticsearch/config/elasticsearch.yml
![](https://img.haomeiwen.com/i13992547/ed1c1d9abc9a92de.png)
- 挂载第二个配置文件
/usr/share/elasticsearch/config/jvm.options
![](https://img.haomeiwen.com/i13992547/01e50f5aa5cda33e.png)
3.3 配置外网访问端口
参考 MySQL 搭建的流程,与其一致,指定为NodePort形式
3.4 连接测试
- 集群内部连接测试
![](https://img.haomeiwen.com/i13992547/ccb0a51432092e61.png)
- 集群外部连接测试
![](https://img.haomeiwen.com/i13992547/c3f19393b1e4249c.png)
4 RabbitMQ 搭建(应用市场)
4.1 添加应用市场仓库
- 登陆拥有企业空间权限的账号「beijing-boss」
- 添加应用仓库地址
https://charts.bitnami.com/bitnami
![](https://img.haomeiwen.com/i13992547/9663173cac4e6704.png)
![](https://img.haomeiwen.com/i13992547/debd35cc68c55345.png)
- 添加应用仓库成功
![](https://img.haomeiwen.com/i13992547/0bb15b4c39a055d3.png)
4.2 通过应用商店部署RabbitMQ
- 切换至bitnami的应用商店,并选择 RabbitMQ 应用
![](https://img.haomeiwen.com/i13992547/550a2a12b6af35e8.png)
- 填写基本信息和选择版本后,部署
![](https://img.haomeiwen.com/i13992547/39810bb1a98762f9.png)
- 开放外网访问端口
![](https://img.haomeiwen.com/i13992547/6fa0d0c3cde75eee.png)
- 部署成功,可以外网登陆 RabbitMQ
![](https://img.haomeiwen.com/i13992547/7a96f471736d22c5.png)