草庐IT

kubeSphere搭建中间件

攻城老湿 2023-03-28 原文

本文是作者学习kubeSphere过程中的具体搭建流程,供需要的小伙伴一起学习进步,具体中间件包括:MySQL、Redis、ElasticSearch、RabbitMQ。搭建的过程从最基础的部分开始,可能比直接通过应用商店部署应用的方式复杂。但可以更加深入理解整体的搭建过程。后续真实需求场景,为方便起见,可以考虑直接通过应用商店的方式部署。本文的RabbitMQ中间件采用了应用的方式部署,供读者参考。enjoy!

1 MySQL搭建

1631544800244-cd4ed8a8-06d0-40bc-9752-dd0ba9df325c.png

1.1 添加mysql的配置文件

  1. 创建新的配置文件
image-20220429102842467.png
  1. 编辑conf的基本信息,包括名称和描述信息
image-20220429103024950.png
  1. 编辑conf的配置信息,其中的键作为文件名,值作为文件中的内容
image-20220429103135445.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
  1. 创建配置文件成功
image-20220429103205231.png

1.2 创建mysql的服务

  1. 创建新的服务
image-20220429103313648.png
  1. 由于mysql需要保存数据,需要创建有状态的服务
image-20220429103356175.png
  1. 编写服务的基本信息
image-20220429103430019.png
  1. 添加容器镜像
image-20220429103521401.png
  1. 初始化密码设置并同步主机时区
MYSQL_ROOT_PASSWORD=199748
image-20220429103558840.png
  1. 添加挂载的存储卷模版(模块会为每个实例挂载对应的data卷,而不是只存在一个卷被所有实例共享)
/var/lib/mysql
image-20220429103937485.png
image-20220429103817368.png
  1. 添加服务的配置文件(会将配置文件挂载至对应的挂载目录下,仅仅包含挂载的文件,其他文件存在也会被覆盖)
/etc/mysql/conf.d
image-20220429104009157.png
image-20220429104038101.png

1.3 配置外网访问端口

  1. 创建自定义方式的服务
image-20220429104348076.png
  1. 编写服务基本信息
image-20220429104436524.png
  1. 指定工作负载,并设置容器端口
image-20220429104527226.png
  1. 指定外网访问
image-20220429104550075.png
image-20220429104605723.png

1.4 连接测试

  1. 集群内部可以通过DNS域名访问mysql
image-20220429104754284.png
  1. 集群外部可以通过NodePort暴露的port访问
image-20220429104940955.png

2 Redis 搭建

1631610241479-a4dc9586-872d-49ef-95a0-2d0116c9b9ed.png

2.1 添加 redis 配置文件

  1. 创建新的配置文件,填写redis的基本信息
image-20220429143957046.png
  1. 编辑conf的配置信息,其中的键作为文件名,值作为文件中的内容
# redis.conf
appendonly yes
port 6379
bind 0.0.0.0
image-20220429144105866.png
  1. 创建配置文件成功
image-20220429144151914.png

2.2 创建 redis 的服务

  1. 创建新的服务,由于redis需要缓存数据至本地,需要创建有状态的服务
image-20220429103356175.png
  1. 编写服务的基本信息
image-20220429144334755.png
  1. 添加容器
image-20220429144431014.png
  1. 添加redis的启动命令并同步主机时区
redis-server /etc/redis/redis.conf
image-20220429144526669.png
  1. 添加挂载的存储卷模版(模块会为每个实例挂载对应的data卷,而不是只存在一个卷被所有实例共享)
/data
image-20220429103937485.png
image-20220429144746259.png
  1. 添加服务的配置文件(会将配置文件挂载至对应的挂载目录下,仅仅包含挂载的文件,其他文件存在也会被覆盖)
/etc/redis/
image-20220429144921859.png

2.3 配置外网访问端口

参考 MySQL 搭建的流程,与其一致,指定为NodePort形式

2.4 连接测试

  1. 集群内部可以通过DNS域名访问 redis
image-20220429150529574.png
  1. 集群外部可以通过NodePort暴露的port访问
image-20220429150716489.png

3 ElasticSearch 搭建

1631609524580-f264a6dc-e619-4843-a717-b8852716785d.png

3.1 添加 ES 配置文件

  1. 编写基础配置信息
image-20220429160349307.png
  1. 添加两个配置信息
  • elasticsearch配置信息
# elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
image-20220429160501597.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
image-20220429160557916.png
  1. 创建配置文件成功
image-20220429160801015.png

3.2 创建 es 服务

  1. 创建有状态服务,由于es需要存储数据
image-20220429160845193.png
  1. 编写服务基本信息
image-20220429160920040.png
  1. 添加镜像
image-20220429161005484.png
  1. 添加环境变量
discovery.type     single-node
ES_JAVA_OPTS       -Xms512m -Xmx512m
image-20220429161108687.png
  1. 挂载存储模版
/usr/share/elasticsearch/data
image-20220429161310160.png
  1. 挂载两个配置文件
  • 挂载第一个配置文件
/usr/share/elasticsearch/config/elasticsearch.yml
image-20220429161908750.png
  • 挂载第二个配置文件
/usr/share/elasticsearch/config/jvm.options
image-20220429162017148.png

3.3 配置外网访问端口

参考 MySQL 搭建的流程,与其一致,指定为NodePort形式

3.4 连接测试

  1. 集群内部连接测试
image-20220429163531823.png
  1. 集群外部连接测试
image-20220429163702174.png

4 RabbitMQ 搭建(应用市场)

4.1 添加应用市场仓库

  1. 登陆拥有企业空间权限的账号「beijing-boss」
  2. 添加应用仓库地址
https://charts.bitnami.com/bitnami
image-20220429170102941.png
image-20220429170139336.png
  1. 添加应用仓库成功
image-20220429170214971.png

4.2 通过应用商店部署RabbitMQ

  1. 切换至bitnami的应用商店,并选择 RabbitMQ 应用
image-20220430151644027.png
  1. 填写基本信息和选择版本后,部署
image-20220430151735015.png
  1. 开放外网访问端口
image-20220430152118458.png
  1. 部署成功,可以外网登陆 RabbitMQ
image-20220430152054919.png

有关kubeSphere搭建中间件的更多相关文章

  1. ruby - 如何在数组中间插入一个数组? - 2

    我有一个Ruby数组[1,4]。我想在中间插入另一个数组[2,3],这样它就变成了[1,2,3,4]。我可以使用[1,4].insert(1,[2,3]).flatten实现这一点,但是有更好的方法吗? 最佳答案 您可以通过以下方式进行。[1,4].insert(1,*[2,3])insert()方法处理多个参数。因此,您可以使用splat运算符*将数组转换为参数。 关于ruby-如何在数组中间插入一个数组?,我们在StackOverflow上找到一个类似的问题:

  2. ruby-on-rails - 如何在关闭 cache_classes 的情况下使用来自中间件的域对象? - 2

    在rails开发环境中,cache_classes是关闭的,所以你可以修改app/下的代码,不用重启服务器就可以看到变化。不过,在所有环境中,中间件只会创建一次。所以如果我有这样的中间件:classMyMiddlewaredefinitialize(app)@app=appenddefcall(env)env['model']=MyModel.firstendend我在config/environments/development.rb中执行此操作:config.cache_classes=false#thedefaultfordevelopmentconfig.middleware.

  3. ruby-on-rails - 保存 PDFKit 中间件显示的 PDF 文件 - 2

    如果有人有兴趣将PDF文件保存在PDFKit中间件gem显示的文件系统中,那么这里是...重写middleware.rb文件的call方法。在覆盖中只需替换这一行:body=PDFKit.new(translate_paths(body,env),@options).to_pdf与pdf=PDFKit.new(translate_paths(body,env),@options)file=pdf.to_file('Your/file/name/path')Mymodel.my_method()#Youcanwriteyourmethodheretousethatfilebody=pdf

  4. ruby-on-rails - Rack 中间件和线程安全 - 2

    我的Rails4应用程序使用了一个自定义Rack中间件。如果客户端未提供有效信息(我'正在开发API)。因此,在每个请求之前它会更改这些header,并且在每个请求之后它会添加一个带有自定义媒体类型信息的自定义X-Something-Media-Typeheader。我想切换到Puma,因此我有点担心这种中间件的线程安全性。我没有使用实例变量,除了我们在每个中间件中遇到的常见@app.call一次,但即使在这里我也复制了一些我在RailsCasts的评论中读到的内容:definitialize(app)@app=appenddefcall(env)dup._call(env)endde

  5. ruby-on-rails - rails delete_if 使用哈希忽略当前文章(中间人) - 2

    我为你们准备了一个简单的。我想要一个特色内容部分,其中排除了当前文章所以这可以通过delete_if使用MiddlemanBlog:但是我使用的是中间人代理,所以我无法访问current_article方法...我有一个YAML结构,其中包含以下模拟数据(以及其他数据),文件夹设置如下:data>site>caseStudy>RANDOM-ID423536.yaml(由CMS生成)在每个yaml文件中,您会发现如下内容::id:2k1YccJrQsKE2siSO6o6ac:title:Heyplace我的config.rb看起来像这样data.site.caseStudy.eachdo

  6. Ruby 正则表达式 - 用文本中间的空格替换点 - 2

    我有一个很长的文本,我想用空格替换其中的点,但只能在文本的中间。例如:Domain:...................google.com我需要这样:Domain:google.com我发现了这个用单个空格替换点的正则表达式:str.gsub!(/(?但这还不够,因为它会产生:Domain:google.com我需要保留与点一样多的空格。你会如何解决? 最佳答案 你快到了,你的正则表达式没问题,只需使用String#gsub的block版本计算替换匹配的长度:▶str='Domain:...................goo

  7. ruby - 使用 gem 自动添加 Rack 中间件 - 2

    我有一个提供一些Rack中间件的gem,让它工作的唯一方法是将它放在我的application.rb中config.middleware.use"TBBC::Editor::Middleware"当我的gem在应用程序Gemfile中使用时,如何才能自动使用此中间件? 最佳答案 如果您打算将您的gem用于Rails3,您可以提供一个Railtie。如果使用Rails,您可以自动加载它。假设您的gem名称是tbbc,将它放在lib/tbbc/railtie.rb中:moduleTBBCclassRailtie在lib/tbbc.rb中

  8. ruby-on-rails - 使用机架中间件捕获无效的 JSON 解析错误 - 2

    我正在使用Rails5,我正在尝试改进对我的API的无效JSON请求的错误处理。我尝试通过救援在Controller中解析来处理无效格式的JSON,但意识到如果用户将ContentType添加到他们的请求header,Rails中间件会在我的JSON请求到达Controller之前解析它。我遵循了以下指南:https://robots.thoughtbot.com/catching-json-parse-errors-with-custom-middleware但是,在启动服务器时出现以下错误:.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems

  9. ruby - 如何打乱字符串中每个单词的中间字母? - 2

    试图重现“只有聪明人才能读懂这篇文章”的模因。这是一个示例:Hradtoblveieetahtyoucluodaulacltyuesdnatnrdwahtyor’uerdanieg.Thephaonmnealpweorofthehmuanbairn,aoccdrnigtoarscheearchatCmabrigdeUinervtisy,sowhstahtitdeosn’tmttaerinwahtoredrtheltteersinawrodare,theolnyiprmoatnttihngistahtthefristandlsatltteerbeintherghitpclae.Thers

  10. ruby - 如何在中间人的部分中渲染部分 - 2

    我有一些Haml部分,其中许多包含样板文件.容器。排.col-lg-12当我尝试抽象出ala=partial"site_section"时,我得到:syntaxerror,unexpectedkeyword_end,expectingend-of-inputend;end;end;end我正在使用ruby​​2.2.2。如何在Middleman的Haml部分中渲染Haml部分?谢谢更新这显然是处理我的部分(上图)的某种特殊情况。我还有其他局部渲染效果很好。更新关于这个thisrepo,布局实际上是:_site_section:.容器。排.col-lg-12_nested_section

随机推荐