Java高级工程师Docker必装大全(一)(没有废话,全是干货)

文章目录

目录

1、docker必装--Nacos:

2、docker必装--Es:

3、docker必装--Kibana:

4、docker必装--MySQL:


安装docker配置之前大家要先备有VM,Liunx;当然要先安装docker,有不懂docker原理的程序员姥爷们请看这篇文章Docker原理(图解+秒懂+史上最全)

接下来给大家走一遍docker的安装操作(请在虚拟机里进行操作)包含Es、Kibana、MySQL、nacos、redis、rabbitMQ,这些都是Java工程师必备的一些配置,接下来我会详细讲解安装步骤,供大家参考哈,废话不多说让我们

                           

首先来安装我们的万恶之源:Nacos

                      这家伙可坏的狠啊,一步错步步错,接下来紧跟我的jio步我们开始!

                                                   

1、docker必装--Nacos:

准备工作

# 打开目录

[root@localhost~]# cd /usr/local/docker/

# 创建nacos文件夹

[root@localhost docker]# mkdir nacos

# 打开目录

[root@localhost docker]# cd nacos/

# 创建文件夹 config

[root@localhost docker]# mkdir config

# 打开文件夹

[root@localhost docker]# cd config/

上传配置文件

[root@localhost docker]# application.properties

具体配置文件

#
# Copyright 1999-2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#*************** Spring Boot Related Configurations ***************#
### Default web context path:
server.servlet.contextPath=/nacos
### Default web server port:
server.port=8848

#*************** Network Related Configurations ***************#
### If prefer hostname over ip for Nacos server addresses in cluster.conf:
# nacos.inetutils.prefer-hostname-over-ip=false

### Specify local server's IP:
# nacos.inetutils.ip-address=


#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
# spring.datasource.platform=mysql

### Count of DB:
# db.num=1

### Connect URL of DB:
# db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
# db.user.0=nacos
# db.password.0=nacos

### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

#*************** Naming Module Related Configurations ***************#
### Data dispatch task execution period in milliseconds: Will removed on v2.1.X, replace with nacos.core.protocol.distro.data.sync.delayMs
# nacos.naming.distro.taskDispatchPeriod=200

### Data count of batch sync task: Will removed on v2.1.X. Deprecated
# nacos.naming.distro.batchSyncKeyCount=1000

### Retry delay in milliseconds if sync task failed: Will removed on v2.1.X, replace with nacos.core.protocol.distro.data.sync.retryDelayMs
# nacos.naming.distro.syncRetryDelay=5000

### If enable data warmup. If set to false, the server would accept request without local data preparation:
# nacos.naming.data.warmup=true

### If enable the instance auto expiration, kind like of health check of instance:
# nacos.naming.expireInstance=true

### will be removed and replaced by `nacos.naming.clean` properties
nacos.naming.empty-service.auto-clean=true
nacos.naming.empty-service.clean.initial-delay-ms=50000
nacos.naming.empty-service.clean.period-time-ms=30000

### Add in 2.0.0
### The interval to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.interval=60000

### The expired time to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.expired-time=60000

### The interval to clean expired metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.interval=5000

### The expired time to clean metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.expired-time=60000

### The delay time before push task to execute from service changed, unit: milliseconds.
# nacos.naming.push.pushTaskDelay=500

### The timeout for push task execute, unit: milliseconds.
# nacos.naming.push.pushTaskTimeout=5000

### The delay time for retrying failed push task, unit: milliseconds.
# nacos.naming.push.pushTaskRetryDelay=1000

### Since 2.0.3
### The expired time for inactive client, unit: milliseconds.
# nacos.naming.client.expired.time=180000

#*************** CMDB Module Related Configurations ***************#
### The interval to dump external CMDB in seconds:
# nacos.cmdb.dumpTaskInterval=3600

### The interval of polling data change event in seconds:
# nacos.cmdb.eventTaskInterval=10

### The interval of loading labels in seconds:
# nacos.cmdb.labelTaskInterval=300

### If turn on data loading task:
# nacos.cmdb.loadDataAtStart=false


#*************** Metrics Related Configurations ***************#
### Metrics for prometheus
#management.endpoints.web.exposure.include=*

### Metrics for elastic search
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200

### Metrics for influx
management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
#management.metrics.export.influx.uri=http://localhost:8086
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true

#*************** Access Log Related Configurations ***************#
### If turn on the access log:
server.tomcat.accesslog.enabled=true

### The access log pattern:
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i

### The directory of access log:
server.tomcat.basedir=

#*************** Access Control Related Configurations ***************#
### If enable spring security, this option is deprecated in 1.2.0:
#spring.security.enabled=false

### The ignore urls of auth, is deprecated in 1.2.0:
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**

### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos

### If turn on auth system:
nacos.core.auth.enabled=false

### worked when nacos.core.auth.system.type=ldap,{0} is Placeholder,replace login username
# nacos.core.auth.ldap.url=ldap://localhost:389
# nacos.core.auth.ldap.userdn=cn={0},ou=user,dc=company,dc=com

### The token expiration in seconds:
nacos.core.auth.default.token.expire.seconds=18000

### The default token:
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789

### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true

### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=false

### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security

#*************** Istio Related Configurations ***************#
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false

#*************** Core Related Configurations ***************#

### set the WorkerID manually
# nacos.core.snowflake.worker-id=

### Member-MetaData
# nacos.core.member.meta.site=
# nacos.core.member.meta.adweight=
# nacos.core.member.meta.weight=

### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5
## Server domain name address of [address-server] mode
# address.server.domain=jmenv.tbsite.net
## Server port of [address-server] mode
# address.server.port=8080
## Request address of [address-server] mode
# address.server.url=/nacos/serverlist

#*************** JRaft Related Configurations ***************#

### Sets the Raft cluster election timeout, default value is 5 second
# nacos.core.protocol.raft.data.election_timeout_ms=5000
### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
# nacos.core.protocol.raft.data.snapshot_interval_secs=30
### raft internal worker threads
# nacos.core.protocol.raft.data.core_thread_num=8
### Number of threads required for raft business request processing
# nacos.core.protocol.raft.data.cli_service_thread_num=4
### raft linear read strategy. Safe linear reads are used by default, that is, the Leader tenure is confirmed by heartbeat
# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
### rpc request timeout, default 5 seconds
# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000

#*************** Distro Related Configurations ***************#

### Distro data sync delay time, when sync task delayed, task will be merged for same data key. Default 1 second.
# nacos.core.protocol.distro.data.sync.delayMs=1000

### Distro data sync timeout for one sync data, default 3 seconds.
# nacos.core.protocol.distro.data.sync.timeoutMs=3000

### Distro data sync retry delay time when sync data failed or timeout, same behavior with delayMs, default 3 seconds.
# nacos.core.protocol.distro.data.sync.retryDelayMs=3000

### Distro data verify interval time, verify synced data whether expired for a interval. Default 5 seconds.
# nacos.core.protocol.distro.data.verify.intervalMs=5000

### Distro data verify timeout for one verify, default 3 seconds.
# nacos.core.protocol.distro.data.verify.timeoutMs=3000

### Distro data load retry delay when load snapshot data failed, default 30 seconds.
# nacos.core.protocol.distro.data.load.retryDelayMs=30000

修改配置文件

[root@localhost config]# vim application.properties

具体修改配置信息 在最后一行赋值进去就ok,自己修改一下

# 连接类型
spring.datasource.platform=mysql
db.num=1
# 连接地址
db.url.0=jdbc:mysql://IP:端口/数据库名称?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&serverTimezone=UTC
# 数据库用户名
db.user=root
# 数据库密码
db.password=Dongzl828..

 初始化数据库

在nacos需要连接的数据库当中,创建数据库 nacos_config 字符集类型为 utf8mb4

 SQL脚本

nacos-mysql.sqlhttps://uploader.shimo.im/f/GAM432RosXNTiQcB.sql?fileGuid=KrkEVQL4JXIdKKAJ

导入SQL脚本

  把下载下来的文件导入进去

 导入完成

下载nacos镜像

[root@localhost nacos]# docker pull nacos/nacos-server:v2.0.4

编写脚本

# 根目录

[root@localhost config]# cd ../

# 编写脚本

[root@localhost nacos]# vim startNacos.sh

脚本内容

docker run -d \

--restart=always \

--name nacos-8848 \

-e MODE=standalone \

-e JVM_XMS=256m \

-e JVM_XMX=256m \

-e JVM_XMN=256m \

-p 8848:8848 \

-p 9848:9848 \

-v /usr/local/docker/nacos/config/application.properties:/home/nacos/conf/application.properties \

nacos/nacos-server:v2.0.4启动脚本

# 权限

[root@localhost nacos]# chmod -R 777 startNacos.sh

# 启动

[root@localhost nacos]# ./startNacos.sh

 接下来就是验证时间!

                                                      

                                                              成功!!!!

                                      ​​​​​​​        

 =========================================================================

                         很好,你已经离Java高级工程师不远了 ,接下来让我们进行第二步

2、docker必装--Es:

准备工作

# 打开目录

[root@localhost docker]# cd /usr/local/docker/

# 创建 es 目录

[root@localhost docker]# mkdir es

# 打开 es 目录

[root@localhost docker]# cd es/

 挂载目录

# 创建 数据 挂载目录

[root@localhost es]# mkdir data

# 创建 配置 挂载目录

[root@localhost es]# mkdir config

# 创建 插件 挂载目录

[root@localhost es]# mkdir plugins

# 权限赋值

[root@localhost es]# chmod -R 777 /usr/local/docker/es/

 编辑配置

# 打开 config 目录

[root@localhost es]# cd config/

 编写配置文件

# 编写配置文件

[root@localhost config]# vim elasticsearch.yml

配置文件内容

# 可访问IP

http.host: 0.0.0.0

# 跨域

http.cors.enabled: true

http.cors.allow-origin: "*"

 启动脚本

# 打开目录

[root@localhost es]# cd /usr/local/docker/es

# 编辑脚本

[root@localhost es]# vim startEs.sh

脚本内容

docker run --name es-7.17.0 \

 --restart=always \

 -p 9200:9200  -p 9300:9300 \

 -e "discovery.type=single-node" \

 -e ES_JAVA_OPTS="-Xms84m -Xmx256m" \

 -v /usr/local/docker/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \

 -v /usr/local/docker/es/data:/usr/share/elasticsearch/data \

 -v /usr/local/docker/es/plugins:/usr/share/elasticsearch/plugins \

 -d elasticsearch:7.17.0

脚本赋权

[root@localhost es]# chmod -R 700 startEs.sh

启动脚本

# 执行脚本

[root@localhost es]# ./startEs.sh

 查看结果

需要进入到   查看结果 

 地址:你的虚拟机地址:9000/#!/home

进入之后应该需要注册一下

 进来por之后点击

之后点击Containers

 显示有es-7.17.0就已经成功一半了!!接下来看看能否进入查看

之后往右看找到Published Ports点击附属链接

 他会默认为0.0.0.0改成你自己的虚拟机地址就ok了

成功访问!大功告成!

                               到这一步我们的Es就安装完成啦!!皆大欢喜~皆大欢喜~

                      

=========================================================================
 

接下来进行我们的Kibana的安装~


想要了解Kibana的请自行百度,这里不做解释sorry~

3、docker必装--Kibana:

准备工作

# 打开目录

[root@localhost docker]# cd /usr/local/docker/

# 创建 kibana 目录

[root@localhost docker]# mkdir kibana

# 进入 kibana 目录

[root@localhost docker]# cd kibana/

挂载目录

# 创建 config 挂载目录

[root@localhost kibana]# mkdir config

配置文件

# 进入 config 目录

[root@localhost localhost kibana]# cd config/

# 编写配置文件 

[root@localhost config]# vim kibana.yml

具体配置

# 主机地址,可以是ip,主机名

server.host: 0.0.0.0

# 提供服务的端口,监听端口

server.port: 5601

# 该 kibana 服务的名称,默认 your-hostname

server.name: "MuYu-kibana"

server.shutdownTimeout: "5s"



#####----------elasticsearch相关----------#####

# kibana访问es服务器的URL,就可以有多个,以逗号","隔开

elasticsearch.hosts: [ "http://你的IP地址:9200" ]

monitoring.ui.container.elasticsearch.enabled: true



####----------日志相关----------#####



# kibana日志文件存储路径,默认stdout

logging.dest: stdout



# 此值为true时,禁止所有日志记录输出

# 默认false

logging.silent: false

# 此值为true时,禁止除错误消息之外的所有日志记录输出
# 默认false
logging.quiet: false

# 此值为true时,记录所有事件,包括系统使用信息和所有请求
# 默认false
logging.verbose: false

#####----------其他----------#####

# 系统和进程取样间隔,单位ms,最小值100ms
# 默认5000ms
ops.interval: 5000
# kibana web语言
# 默认en
i18n.locale: "zh-CN"

启动脚本

[root@localhost config]# cd ../ 
[root@localhost kibana]# vim startKibana.sh

 脚本内容

docker run -d \
--name kibana-7.17.0 \
--restart=always \
-p 5601:5601 \
-e TZ="Asia/Shanghai" \
-v /usr/local/docker/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml \
kibana:7.17.0

脚本赋权

[root@localhost kibana]# chmod -R 700 startKibana.sh 

启动脚本

[root@localhost kibana]# ./startKibana.sh

                      (ps:启动完脚本之后Kibana会自己下载文件,不要着急退出) 

查看结果

 需要进入到   查看结果 

 地址:你的虚拟机地址:9000/#!/home

进入之后应该需要注册一下

 进来por之后点击

之后点击Containers

查看有无Kibana

点击附属链接进行访问

 

! 大功告成 !

 =========================================================================

接下来让我们来进行安装MySQL,非常重要,不要忽略~

4、docker必装--MySQL:

准备工作

# 打开目录

[root@localhost ~]# cd /usr/local/docker/

# 创建文件夹

[root@localhost ~]# cd /usr/local/docker/

# 打开文件夹

[root@localhost docker]# cd mysql/

创建挂载目录

# 创建配置文件目录

[root@localhost mysql]# mkdir config

# 打开config

[root@localhost  mysql]# cd config/

# 编写配置文件

[root@localhost  config]# vim my.cnf

 配置文件内容

[client]
# 端口号
port=3306

[mysql]
no-beep
default-character-set=utf8mb4

[mysqld]
# 端口号
port=3306
# 数据目录
datadir=/var/lib/mysql
# 新模式或表时将使用的默认字符集
character-set-server=utf8mb4
# 默认存储引擎
default-storage-engine=INNODB
# 将 SQL 模式设置为严格
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#  最大连接数
max_connections=1024
# 表缓存
table_open_cache=2000
# 表内存
tmp_table_size=16M
# 线程缓存
thread_cache_size=10
# 设置大小写不敏感
lower_case_table_names=1

# myisam设置
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=8M
key_buffer_size=8M
read_buffer_size=0
read_rnd_buffer_size=0

# innodb设置
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=1M
innodb_buffer_pool_size=8M
innodb_log_file_size=48M
innodb_thread_concurrency=33
innodb_autoextend_increment=64
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
# 其他设置
back_log=80
flush_time=0
join_buffer_size=256K
max_allowed_packet=4M
max_connect_errors=100
open_files_limit=4161
sort_buffer_size=256K
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000

下载镜像

[root@localhost  mysql]# docker pull mysql:5.7

编写脚本

# 打开目录

[root@localhost  config]# cd /usr/local/docker/mysql/

# 编写脚本

[root@localhost  mysql]# vim startMysql.sh

脚本内容

docker run -d \
--privileged=true \
--name mysql57 \
-p 3306:3306 \
--restart=always \
-v /usr/local/docker/mysql/data:/var/lib/mysql \
-v /usr/local/docker/mysql/config/my.cnf:/etc/mysql/my.cnf \
-e MYSQL_ROOT_PASSWORD=root mysql:5.7 \

权限赋予

# 权限赋予

[root@localhost  mysql]# chmod -R 777 startMysql.sh

 启动脚本

# 执行脚本

[root@localhost  mysql]# ./startMysql.sh

 查看结果

 需要进入到   查看结果 

 地址:你的虚拟机地址:9000/#!/home

进入之后应该需要注册一下

 进来por之后点击

之后点击Containers

查看有没有MySQL

# 进入容器

docker 进入mysql_docker进入mysql容器_yzhSWJ的博客-CSDN博客

[root@localhost mysql]# docker exec -it mysql57-3306 /bin/bash(有问题)

# 连接MySQL

root@4ff92e46f363:/# mysql -uroot -pDongzl828..

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# 查询数据库

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.01 sec)

  又是一次过关斩将!

 =========================================================================

还有几个必装等到下期做吧,已经搞不动了

 

                                                 欢迎各位程序员姥爷进行反馈和补充~

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值