本文是作者學(xué)習(xí)kubeSphere過(guò)程中的具體搭建流程,供需要的小伙伴一起學(xué)習(xí)進(jìn)步,具體中間件包括:MySQL、Redis、ElasticSearch、RabbitMQ。搭建的過(guò)程從最基礎(chǔ)的部分開(kāi)始,可能比直接通過(guò)應(yīng)用商店部署應(yīng)用的方式復(fù)雜。但可以更加深入理解整體的搭建過(guò)程。后續(xù)真實(shí)需求場(chǎng)景,為方便起見(jiàn),可以考慮直接通過(guò)應(yīng)用商店的方式部署。本文的RabbitMQ中間件采用了應(yīng)用的方式部署,供讀者參考。enjoy!
1 MySQL搭建

1631544800244-cd4ed8a8-06d0-40bc-9752-dd0ba9df325c.png
1.1 添加mysql的配置文件
- 創(chuàng)建新的配置文件

image-20220429102842467.png
- 編輯conf的基本信息,包括名稱和描述信息

image-20220429103024950.png
- 編輯conf的配置信息,其中的鍵作為文件名,值作為文件中的內(nèi)容

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
- 創(chuàng)建配置文件成功

image-20220429103205231.png
1.2 創(chuàng)建mysql的服務(wù)
- 創(chuàng)建新的服務(wù)

image-20220429103313648.png
- 由于mysql需要保存數(shù)據(jù),需要?jiǎng)?chuàng)建有狀態(tài)的服務(wù)

image-20220429103356175.png
- 編寫(xiě)服務(wù)的基本信息

image-20220429103430019.png
- 添加容器鏡像

image-20220429103521401.png
- 初始化密碼設(shè)置并同步主機(jī)時(shí)區(qū)
MYSQL_ROOT_PASSWORD=199748

image-20220429103558840.png
- 添加掛載的存儲(chǔ)卷模版(模塊會(huì)為每個(gè)實(shí)例掛載對(duì)應(yīng)的data卷,而不是只存在一個(gè)卷被所有實(shí)例共享)
/var/lib/mysql

image-20220429103937485.png

image-20220429103817368.png
- 添加服務(wù)的配置文件(會(huì)將配置文件掛載至對(duì)應(yīng)的掛載目錄下,僅僅包含掛載的文件,其他文件存在也會(huì)被覆蓋)
/etc/mysql/conf.d

image-20220429104009157.png

image-20220429104038101.png
1.3 配置外網(wǎng)訪問(wèn)端口
- 創(chuàng)建自定義方式的服務(wù)

image-20220429104348076.png
- 編寫(xiě)服務(wù)基本信息

image-20220429104436524.png
- 指定工作負(fù)載,并設(shè)置容器端口

image-20220429104527226.png
- 指定外網(wǎng)訪問(wèn)

image-20220429104550075.png

image-20220429104605723.png
1.4 連接測(cè)試
- 集群內(nèi)部可以通過(guò)DNS域名訪問(wèn)mysql

image-20220429104754284.png
- 集群外部可以通過(guò)NodePort暴露的port訪問(wèn)

image-20220429104940955.png
2 Redis 搭建

1631610241479-a4dc9586-872d-49ef-95a0-2d0116c9b9ed.png
2.1 添加 redis 配置文件
- 創(chuàng)建新的配置文件,填寫(xiě)redis的基本信息

image-20220429143957046.png
- 編輯conf的配置信息,其中的鍵作為文件名,值作為文件中的內(nèi)容
# redis.conf
appendonly yes
port 6379
bind 0.0.0.0

image-20220429144105866.png
- 創(chuàng)建配置文件成功

image-20220429144151914.png
2.2 創(chuàng)建 redis 的服務(wù)
- 創(chuàng)建新的服務(wù),由于redis需要緩存數(shù)據(jù)至本地,需要?jiǎng)?chuàng)建有狀態(tài)的服務(wù)

image-20220429103356175.png
- 編寫(xiě)服務(wù)的基本信息

image-20220429144334755.png
- 添加容器

image-20220429144431014.png
- 添加redis的啟動(dòng)命令并同步主機(jī)時(shí)區(qū)
redis-server /etc/redis/redis.conf

image-20220429144526669.png
- 添加掛載的存儲(chǔ)卷模版(模塊會(huì)為每個(gè)實(shí)例掛載對(duì)應(yīng)的data卷,而不是只存在一個(gè)卷被所有實(shí)例共享)
/data

image-20220429103937485.png

image-20220429144746259.png
- 添加服務(wù)的配置文件(會(huì)將配置文件掛載至對(duì)應(yīng)的掛載目錄下,僅僅包含掛載的文件,其他文件存在也會(huì)被覆蓋)
/etc/redis/

image-20220429144921859.png
2.3 配置外網(wǎng)訪問(wèn)端口
參考 MySQL 搭建的流程,與其一致,指定為NodePort形式
2.4 連接測(cè)試
- 集群內(nèi)部可以通過(guò)DNS域名訪問(wèn) redis

image-20220429150529574.png
- 集群外部可以通過(guò)NodePort暴露的port訪問(wèn)

image-20220429150716489.png
3 ElasticSearch 搭建

1631609524580-f264a6dc-e619-4843-a717-b8852716785d.png
3.1 添加 ES 配置文件
- 編寫(xiě)基礎(chǔ)配置信息

image-20220429160349307.png
- 添加兩個(gè)配置信息
- 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
- 創(chuàng)建配置文件成功

image-20220429160801015.png
3.2 創(chuàng)建 es 服務(wù)
- 創(chuàng)建有狀態(tài)服務(wù),由于es需要存儲(chǔ)數(shù)據(jù)

image-20220429160845193.png
- 編寫(xiě)服務(wù)基本信息

image-20220429160920040.png
- 添加鏡像

image-20220429161005484.png
- 添加環(huán)境變量
discovery.type single-node
ES_JAVA_OPTS -Xms512m -Xmx512m

image-20220429161108687.png
- 掛載存儲(chǔ)模版
/usr/share/elasticsearch/data

image-20220429161310160.png
- 掛載兩個(gè)配置文件
- 掛載第一個(gè)配置文件
/usr/share/elasticsearch/config/elasticsearch.yml

image-20220429161908750.png
- 掛載第二個(gè)配置文件
/usr/share/elasticsearch/config/jvm.options

image-20220429162017148.png
3.3 配置外網(wǎng)訪問(wèn)端口
參考 MySQL 搭建的流程,與其一致,指定為NodePort形式
3.4 連接測(cè)試
- 集群內(nèi)部連接測(cè)試

image-20220429163531823.png
- 集群外部連接測(cè)試

image-20220429163702174.png
4 RabbitMQ 搭建(應(yīng)用市場(chǎng))
4.1 添加應(yīng)用市場(chǎng)倉(cāng)庫(kù)
- 登陸擁有企業(yè)空間權(quán)限的賬號(hào)「beijing-boss」
- 添加應(yīng)用倉(cāng)庫(kù)地址
https://charts.bitnami.com/bitnami

image-20220429170102941.png

image-20220429170139336.png
- 添加應(yīng)用倉(cāng)庫(kù)成功

image-20220429170214971.png
4.2 通過(guò)應(yīng)用商店部署RabbitMQ
- 切換至bitnami的應(yīng)用商店,并選擇 RabbitMQ 應(yīng)用

image-20220430151644027.png
- 填寫(xiě)基本信息和選擇版本后,部署

image-20220430151735015.png
- 開(kāi)放外網(wǎng)訪問(wèn)端口

image-20220430152118458.png
- 部署成功,可以外網(wǎng)登陸 RabbitMQ

image-20220430152054919.png