'doc:docker安装\虚拟机搭建'
5
.obsidian/app.json
vendored
@ -1 +1,4 @@
|
||||
{}
|
||||
{
|
||||
"legacyEditor": false,
|
||||
"attachmentFolderPath": "./assets"
|
||||
}
|
2
.obsidian/appearance.json
vendored
@ -1,3 +1,3 @@
|
||||
{
|
||||
"baseFontSize": 16
|
||||
"baseFontSize": 21
|
||||
}
|
35
.obsidian/workspace
vendored
@ -4,11 +4,15 @@
|
||||
"type": "split",
|
||||
"children": [
|
||||
{
|
||||
"id": "2480116cbf7e41ff",
|
||||
"id": "7eb2511e30cd8b3a",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "empty",
|
||||
"state": {}
|
||||
"type": "markdown",
|
||||
"state": {
|
||||
"file": "docker/docker-compose 安装.md",
|
||||
"mode": "source",
|
||||
"source": false
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -49,7 +53,7 @@
|
||||
}
|
||||
],
|
||||
"direction": "horizontal",
|
||||
"width": 300
|
||||
"width": 445
|
||||
},
|
||||
"right": {
|
||||
"id": "e66ca0b0c34a1e7f",
|
||||
@ -65,6 +69,7 @@
|
||||
"state": {
|
||||
"type": "backlink",
|
||||
"state": {
|
||||
"file": "docker/docker-compose 安装.md",
|
||||
"collapseAll": false,
|
||||
"extraContext": false,
|
||||
"sortOrder": "alphabetical",
|
||||
@ -82,17 +87,17 @@
|
||||
"width": 300,
|
||||
"collapsed": true
|
||||
},
|
||||
"active": "2480116cbf7e41ff",
|
||||
"active": "7eb2511e30cd8b3a",
|
||||
"lastOpenFiles": [
|
||||
"Untitled.md",
|
||||
"front_end/js/js监听键盘键盘输入.md",
|
||||
"front_end/vue/nodejs安装命令.md",
|
||||
"front_end/vue/element upload手动文件上传,多文件上传.md",
|
||||
"proxy/FRP内网穿透.md",
|
||||
"proxy/Ubuntu install 花生壳.md",
|
||||
"front_end/vue/vue引入百度地图.md",
|
||||
"ubuntu/MediaWiki搭建以及pivot皮肤配置.md",
|
||||
"network/VPN服务器搭建以及使用(L2TP类型).md",
|
||||
"elk/es、logstash安装.md"
|
||||
"docker/docker-compose 安装.md",
|
||||
"docker/Ubuntu20.04 安装Docker.md",
|
||||
"docker/无损升级Docker容器的镜像版本.md",
|
||||
"docker/重置portainer密码.md",
|
||||
"apps/vscode/VsCode-鼠标滑轮控制字体大小.md",
|
||||
"vm/virtualbox/VirtualBox 搭建Ubuntu20.04.md",
|
||||
"vm/virtualbox/assets/1650301557(1).png",
|
||||
"vm/virtualbox/assets/1650303777(1).png",
|
||||
"vm/virtualbox/assets/1650304260(1).png",
|
||||
"vm/virtualbox/assets/Pasted image 20220419004014.png"
|
||||
]
|
||||
}
|
21
apps/vscode/VsCode-鼠标滑轮控制字体大小.md
Normal file
@ -0,0 +1,21 @@
|
||||
+ 点击文件(File)
|
||||
+ 点击首选项(Preferences)
|
||||
+ 点击设置(Settings)
|
||||
+ 点击文件编辑器(Test Editor)
|
||||
+ 点击字体(Font)
|
||||
+ 找到Font Weight 后点击在setting.json中编辑
|
||||
+ 在settings.json中添加 `"editor.mouseWheelZoom": true`
|
||||
+ settings.json 内容如下
|
||||
```json
|
||||
{
|
||||
|
||||
其他配置:***,
|
||||
|
||||
其他配置:***,
|
||||
|
||||
其他配置:***,
|
||||
|
||||
"editor.mouseWheelZoom": true
|
||||
|
||||
}
|
||||
```
|
223
docker/Ubuntu20.04 安装Docker.md
Normal file
@ -0,0 +1,223 @@
|
||||
## Install
|
||||
#### 1.设置存储库
|
||||
##### a. 更新APT程序包索引并安装程序包,以允许APT通过HTTPS使用存储库:
|
||||
|
||||
```shell
|
||||
$ sudo apt-get update
|
||||
|
||||
$ sudo apt-get install \
|
||||
ca-certificates \
|
||||
curl \
|
||||
gnupg \
|
||||
lsb-release
|
||||
```
|
||||
|
||||
##### b.添加Docker官方GPG密钥
|
||||
|
||||
```shell
|
||||
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
||||
```
|
||||
|
||||
##### c.使用以下命令设置稳定的存储库。要添加夜间或测试存储库,请在下面命令中的稳定一词之后添加夜间或测试(或两者)一词。了解夜间频道和测试频道。
|
||||
|
||||
```shell
|
||||
$ echo \
|
||||
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
|
||||
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
```
|
||||
|
||||
#### 2.安装Docker
|
||||
|
||||
##### a.更新apt包索引,安装最新版本的Docker Engine和Containerd,或进入下一步安装具体版本
|
||||
|
||||
```shell
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
|
||||
```
|
||||
|
||||
>如果您启用了多个 Docker 存储库,则在 apt-get install 或 apt-get update 命令中未指定版本的情况下安装或更新始终会安装可能的最高版本,这可能不适合您的稳定性需求。
|
||||
|
||||
##### b.要安装特定版本的 Docker Engine,请在 repo 中列出可用版本,然后选择并安装:
|
||||
|
||||
列出您的存储库中可用的版本:
|
||||
|
||||
```shell
|
||||
$ apt-cache madison docker-ce
|
||||
|
||||
docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
|
||||
docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
|
||||
docker-ce | 18.06.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
|
||||
docker-ce | 18.06.0~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
|
||||
```
|
||||
|
||||
使用第二列中的版本字符串安装特定版本,例如 5:18.09.1~3-0~ubuntu-xenial
|
||||
|
||||
```shell
|
||||
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
|
||||
```
|
||||
|
||||
##### 通过运行 hello-world 映像来验证 Docker 引擎是否已正确安装。
|
||||
|
||||
```shell
|
||||
$ sudo docker run hello-world
|
||||
```
|
||||
|
||||
>此命令下载测试映像并在容器中运行它。当容器运行时,它会打印一条消息并退出。
|
||||
## Upgrade
|
||||
要升级 Docker Engine,首先运行 sudo apt-get update,然后按照安装说明(Intall的第二节第b段),选择要安装的新版本。
|
||||
|
||||
## Uninstall
|
||||
|
||||
#### 1.卸载Docker Engine、CLI和Containerd包
|
||||
**purge 命令会同时清除软件包和软件的配置文件 谨慎操作**
|
||||
|
||||
```shell
|
||||
$ sudo apt-get purge docker-ce docker-ce-cli containerd.io
|
||||
```
|
||||
|
||||
#### 2.主机上的映像、容器、卷或自定义配置文件不会自动删除。要删除所有映像、容器和卷,请执行以下操作(谨慎操作)
|
||||
```shell
|
||||
$ sudo rm -rf /var/lib/docker
|
||||
$ sudo rm -rf /var/lib/containerd
|
||||
```
|
||||
|
||||
## Expand
|
||||
|
||||
#### 1.配置镜像加速器
|
||||
docker官方镜像仓库国内访问较慢,我们需要设置国内镜像服务:
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /etc/docker
|
||||
sudo tee /etc/docker/daemon.json <<-'EOF'
|
||||
{"registry-mirrors": ["https://kaytushy.mirror.aliyuncs.com"]}
|
||||
EOF
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart docker
|
||||
```
|
||||
|
||||
#### 2.查看当前安装版本和可安装版本
|
||||
apt-cache policy 列出软件包可下载的版本 和当前安装版本
|
||||
|
||||
```bash
|
||||
$ apt-cache policy docker-ce
|
||||
docker-ce:
|
||||
Installed: 5:20.10.14~3-0~ubuntu-focal #已安装版本
|
||||
Candidate: 5:20.10.14~3-0~ubuntu-focal #候选版本(最新版本)
|
||||
Version table: #可安装版本的列表
|
||||
*** 5:20.10.14~3-0~ubuntu-focal 500
|
||||
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
|
||||
100 /var/lib/dpkg/status
|
||||
5:20.10.13~3-0~ubuntu-focal 500
|
||||
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
|
||||
5:20.10.12~3-0~ubuntu-focal 500
|
||||
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
|
||||
5:20.10.11~3-0~ubuntu-focal 500
|
||||
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
|
||||
5:20.10.10~3-0~ubuntu-focal 500
|
||||
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
|
||||
```
|
||||
|
||||
#### 3.添加用户到docker组中
|
||||
默认情况下,`docker`命令只能由 **root** 用户或由 **docker** 组中的用户运行,docker 组用户是在Docker安装过程中自动创建的。
|
||||
如果不想用 sudo 来执行 docker 命令,那么我们只需要把对应的用户添加到 docker 组中即可。
|
||||
|
||||
```bash
|
||||
sudo usermod -aG docker ${USER}
|
||||
```
|
||||
|
||||
使用新组成员身份执行命令,需要注销后重新登录,或使用su来切换身份。
|
||||
|
||||
```bash
|
||||
su - ${USER}
|
||||
```
|
||||
|
||||
我们可以通过`id`这个命令来确认刚刚添加的用户是否已经在 docker 组中:
|
||||
|
||||
```bash
|
||||
$ id -nG
|
||||
|
||||
#输出
|
||||
ds adm cdrom sudo dip plugdev lxd docker
|
||||
```
|
||||
|
||||
## ERROR
|
||||
#### 1.解决docker服务无法重启,报错loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
|
||||
|
||||
执行docker服务重启systemctl restart docker.service命令后,服务未正常启动,查看docker服务的状态,报loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)。
|
||||
|
||||
```bash
|
||||
[root@localhost ~]# systemctl start docker.service
|
||||
Job for docker.service failed because start of the service was attempted too often. See "systemctl status docker.service" and "journalctl -xe" for details.
|
||||
To force a start use "systemctl reset-failed docker.service" followed by "systemctl start docker.service" again.
|
||||
[root@localhost ~]# systemctl status docker.service
|
||||
● docker.service - Docker Application Container Engine
|
||||
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
|
||||
Active: failed (Result: start-limit) since Mo 2020-06-08 10:59:41 CST; 1min 44s ago
|
||||
Docs: https://docs.docker.com
|
||||
Process: 12296 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
|
||||
Main PID: 12296 (code=exited, status=1/FAILURE)
|
||||
|
||||
Jun 08 10:59:41 localhost.localdomain systemd[1]: start request repeated too quickly for docker.service
|
||||
Jun 08 10:59:41 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
|
||||
Jun 08 10:59:41 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
|
||||
Jun 08 10:59:41 localhost.localdomain systemd[1]: docker.service failed.
|
||||
Jun 08 11:00:06 localhost.localdomain systemd[1]: start request repeated too quickly for docker.service
|
||||
Jun 08 11:00:06 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
|
||||
Jun 08 11:00:06 localhost.localdomain systemd[1]: docker.service failed.
|
||||
Jun 08 11:00:25 localhost.localdomain systemd[1]: start request repeated too quickly for docker.service
|
||||
Jun 08 11:00:25 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
|
||||
Jun 08 11:00:25 localhost.localdomain systemd[1]: docker.service failed.
|
||||
```
|
||||
|
||||
##### a.检查/etc/docker/daemon.json文件配置是否正确。
|
||||
```bash
|
||||
[root@localhost ~]# cat /etc/docker/daemon.json
|
||||
{
|
||||
"insecure-registries":["11.1.14.145:8080"],
|
||||
"hosts": ["tcp://127.0.0.1:2375", "unix:///var/run/docker.sock"]
|
||||
}
|
||||
```
|
||||
|
||||
##### b.检查/usr/lib/systemd/system/docker.service文件是否正常。
|
||||
```bash
|
||||
[root@localhost ~]# cat /usr/lib/systemd/system/docker.service
|
||||
[Unit]
|
||||
Description=Docker Application Container Engine
|
||||
Documentation=https://docs.docker.com
|
||||
After=network-online.target firewalld.service
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
# the default is not to use systemd for cgroups because the delegate issues still
|
||||
# exists and systemd currently does not support the cgroup feature set required
|
||||
# for containers run by docker
|
||||
ExecStart=/usr/bin/dockerd
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
# Having non-zero Limit*s causes performance problems due to accounting overhead
|
||||
# in the kernel. We recommend using cgroups to do container-local accounting.
|
||||
LimitNOFILE=infinity
|
||||
LimitNPROC=infinity
|
||||
LimitCORE=infinity
|
||||
# Uncomment TasksMax if your systemd version supports it.
|
||||
# Only systemd 226 and above support this version.
|
||||
#TasksMax=infinity
|
||||
TimeoutStartSec=0
|
||||
# set delegate yes so that systemd does not reset the cgroups of docker containers
|
||||
Delegate=yes
|
||||
# kill only the docker process, not all processes in the cgroup
|
||||
KillMode=process
|
||||
# restart the docker process if it exits prematurely
|
||||
Restart=on-failure
|
||||
StartLimitBurst=3
|
||||
StartLimitInterval=60s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
**参考:**
|
||||
[docker官方ubuntu安装文档](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository)
|
||||
[阿里云镜像加速器配置](https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors)
|
||||
[docker扩展配置](https://kalacloud.com/blog/how-to-install-and-use-docker-on-ubuntu)
|
||||
[docker 启动错误](https://www.jianshu.com/p/7d38cd3bf387)
|
39
docker/docker-compose 安装.md
Normal file
@ -0,0 +1,39 @@
|
||||
## Install
|
||||
1.运行以下命令下载当前稳定版本的Docker-Compose
|
||||
```bash
|
||||
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
```
|
||||
|
||||
2.对二进制文件应用可执行权限
|
||||
```bash
|
||||
sudo chmod +x /usr/local/bin/docker-compose
|
||||
```
|
||||
|
||||
如果修改可执行权限失败。还可以使用另一种方法,创建指向 /usr/bin的软连接
|
||||
|
||||
```bash
|
||||
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
|
||||
```
|
||||
|
||||
3.测试是否安装成功
|
||||
```bash
|
||||
docker-compose --version
|
||||
```
|
||||
## Upgrade
|
||||
如果您从 Compose 1.2 或更早版本升级,请在升级 Compose 后移除或迁移现有容器。这是因为,从 1.3 版开始,Compose 使用 Docker 标签来跟踪容器,并且需要重新创建容器以添加标签。
|
||||
|
||||
如果 Compose 检测到创建时没有标签的容器,它会拒绝运行,这样您就不会得到两组容器。如果您想继续使用现有容器(例如,因为它们有您想要保留的数据卷),您可以使用 Compose 1.5.x 使用以下命令迁移它们:
|
||||
|
||||
```bash
|
||||
docker-compose migrate-to-labels
|
||||
```
|
||||
|
||||
或者,如果您不担心保留它们,则可以删除它们。 Compose 只是创建新的。
|
||||
|
||||
```bash
|
||||
docker container rm -f -v myapp_web_1 myapp_db_1 ...
|
||||
```
|
||||
## UnInstall
|
||||
```bash
|
||||
sudo rm /usr/local/bin/docker-compose
|
||||
```
|
29
docker/无损升级Docker容器的镜像版本.md
Normal file
@ -0,0 +1,29 @@
|
||||
### 1.安装pip 用于安装runlike
|
||||
`apt install pip`
|
||||
|
||||
### 2.安装runlike工具
|
||||
`pip install runlike`
|
||||
|
||||
### 3.查看容器
|
||||
``` sh
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
|
||||
9ad7de103a10 dashan/blog/vue_web:1.0 "/usr/share/nginx/ht…" 8 days ago Up 8 days 0.0.0.0:9527->80/tcp, :::9527->80/tcp vue_mogu_web
|
||||
```
|
||||
### 4.停止容器
|
||||
`docker stop 9ad7de103a10 `
|
||||
### 5.使用`runlike`工具获取容器启动命令并替换
|
||||
`run like 9ad7de103a10`
|
||||
输出
|
||||
```sh
|
||||
docker run --name=vue_mogu_web --hostname=9ad7de103a10 --env=NODE_ENV=production --env=LANG=en_US.UTF-8 --env=TZ=Asia/Shanghai --network=mogu --workdir=/usr/share/nginx/html -p 9527:80 --restart=always --label='com.docker.compose.project.working_dir=/opt/docker-compose/mogu/yaml' --label='maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>' --label='com.docker.compose.project=yaml' --runtime=runc --detach=true dashan/blog/vue_web:1.0 nginx -g 'daemon off;'
|
||||
```
|
||||
### 6.创建新的容器并继承原有容器配置和数据(确定镜像版本已经升级)
|
||||
为了避免容器命名冲突,此处需要更改以下容器名称,然后拷贝以上命令即可得到更新镜像后的容器。
|
||||
|
||||
```sh
|
||||
docker run --name=new_vue_mogu_web --hostname=9ad7de103a10 --env=NODE_ENV=production --env=LANG=en_US.UTF-8 --env=TZ=Asia/Shanghai --network=mogu --workdir=/usr/share/nginx/html -p 9527:80 --restart=always --label='com.docker.compose.project.working_dir=/opt/docker-compose/mogu/yaml' --label='maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>' --label='com.docker.compose.project=yaml' --runtime=runc --detach=true dashan/blog/vue_web:1.0 nginx -g 'daemon off;'
|
||||
```
|
||||
### 7.清理旧的容器
|
||||
`docker rm 9ad7de103a10`
|
||||
|
||||
> 注:未映射到外部的容器数据可能会丢失
|
16
maven/下载依赖异常.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Maven 依赖下载异常处理
|
||||
## 系统找不到路径
|
||||
`D:\Program Files\maven\repository\org\springframework\boot\spring-boot-starter-parent\2.3.9.RELEASE\spring-boot-starter-parent-2.3.9.RELEASE.pom.part.lock (系统找不到指定的路径。)`
|
||||
|
||||
**解决方法:**
|
||||
|
||||
找到本地仓库的文件夹
|
||||
右击文件夹
|
||||
点击属性
|
||||
点击安全
|
||||
查看电脑用户是否有写入权限
|
||||
点击编辑为当前用户添加写入权限
|
||||
点击应用,进入idea重新加载依赖
|
||||
完成
|
||||
|
||||
|
143
spring-cloud/eureka/Eureka 自我保护机制、健康检查的作用、actuator 模块监控.md
Normal file
@ -0,0 +1,143 @@
|
||||
> 原文地址 [www.cnblogs.com](https://www.cnblogs.com/jpfss/p/11314742.html)
|
||||
|
||||
* #### Eureka 自我保护机制
|
||||
|
||||
接着以上篇文章建立的三个工程为基础(eureka-server,uerreg,myweb), 默认 Eureka 是开启自我保护的。我们来做个测试,我们先启动三个工程,我们访问注册中心 [http://localhost:8761/](http://localhost:8761/),
|
||||
|
||||
![[Pasted image 20220406220855.png]]
|
||||
可以看到,实例是成功注册到中心的。此时我们将 uerreg 服务关闭,刷新注册中心,我们会发现如下界面
|
||||
![[Pasted image 20220406220914.png]]
|
||||
我们除了看到了一行红色的警告信息,还发现了一件神奇的事情,就是我们的服务实例虽然被 kill 了,但是在服务注册中心他还是存在的。这就是 Eureka 自我保护机制,他不会剔除已经挂掉的服务,他会认为这个服务是在尝试重新连接的。
|
||||
我们在开发过程中肯定是不希望这样的,不利于开发。我们可以关闭 Eureka 的自我保护机制(实际生产环境不建议关闭)。
|
||||
|
||||
* eureka-server 服务端
|
||||
配置文件中我们添加如下配置
|
||||
|
||||
```properties
|
||||
#关闭保护机制,以确保注册中心将不可用的实例正确剔除
|
||||
eureka.server.enable-self-preservation=false
|
||||
#(代表是5秒,单位是毫秒,清理失效服务的间隔 )
|
||||
eureka.server.eviction-interval-timer-in-ms=5000
|
||||
```
|
||||
|
||||
* userreg 客户端
|
||||
配置文件中我们添加如下配置
|
||||
|
||||
```properties
|
||||
# 心跳检测检测与续约时间
|
||||
# 测试时将值设置设置小些,保证服务关闭后注册中心能及时踢出服务
|
||||
# 配置说明
|
||||
# lease-renewal-interval-in-seconds 每间隔10s,向服务端发送一次心跳,证明自己依然”存活“
|
||||
# lease-expiration-duration-in-seconds 告诉服务端,如果我20s之内没有给你发心跳,就代表我“死”了,将我踢出掉。
|
||||
eureka.instance.lease-renewal-interval-in-seconds=10
|
||||
eureka.instance.lease-expiration-duration-in-seconds=20
|
||||
```
|
||||
|
||||
我们重新启动服务,然后关闭 userreg 客户端进行测试。
|
||||
![[Pasted image 20220406220933.png]]
|
||||
此时我们发现,红色警告变成了自我保护被关闭的警告,且实例被注册中心剔除,表明此时自我保护机制被关闭。
|
||||
|
||||
* #### 健康检查
|
||||
|
||||
人会生病,就像人一样服务有时候也会出现异常情况,我们也需要知道某个服务的健康状况。我们可以通过添加如下依赖,开启某个服务的健康检查。以 userreg 服务为例
|
||||
pom 文件中添加如下依赖
|
||||
|
||||
```xml
|
||||
<!--健康检查依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
ok, 其他的什么都不变,我们来访问一下这个接口 [http://localhost:9001/health](http://localhost:9001/health)
|
||||
我们看到了一个很简短的健康报告:{"description":"Spring Cloud Eureka Discovery Client","status":"UP"},类似的还有
|
||||
|
||||
> info 显示任意的应用信息
|
||||
> metrics 展示当前应用的指标信息 true
|
||||
> mappings 显示所有 @RequestMapping 路径的整理列表
|
||||
> trace 显示 trace 信息(默认为最新的一些 HTTP 请求)
|
||||
> health 展示应用的健康信息
|
||||
> beans 显示一个应用中所有 Spring Beans 的完整列表
|
||||
|
||||
这其中有一些是敏感信息,出于安全考虑,如果不设置
|
||||
|
||||
```properties
|
||||
#关掉认证(公网下的生产环境不建议,内网部署可以)
|
||||
#management.security.enabled=false
|
||||
```
|
||||
|
||||
默认是无法访问的。
|
||||
如果我们要访问查看而且想保证一定的安全性,我们应该做什么呢?我们在 userreg 的 pom 文件中引入
|
||||
|
||||
```xml
|
||||
<!--安全认证依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
此时我们访问 / beans 敏感信息时,弹出如下信息,需要我们进行身份认证
|
||||
|
||||
![[Pasted image 20220406220957.png]]
|
||||
|
||||
仅仅引入依赖其实是有问题的,因为我们请求正常的业务接口他也会要求进行认证,解决办法可以在 userreg 工程的配置文件中添加如下设置:
|
||||
|
||||
```properties
|
||||
#(增加了访问路径)
|
||||
management.context-path=/admin
|
||||
security.user.name=root
|
||||
security.user.password=123
|
||||
#只对/admin进行安全认证
|
||||
security.basic.path=/admin
|
||||
```
|
||||
|
||||
重启服务,我们访问 [http://localhost:9001/admin/beans](http://localhost:9001/admin/beans),注意哦,我们在配置文件中添加了相对路径,只对 admin 进行验证,此时我们输入正确的用户名和密码(已在配置文件中配置)会显示我们需要的信息。
|
||||
|
||||
* #### 实战健康检查
|
||||
|
||||
|
||||
健康检查在实际应用场景中有哪些呢?举个例子,我们配置 userreg 工程数据源
|
||||
在 pom 文件中引入以下依赖
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
然后建立一个配置类,配置数据源 DataSource
|
||||
|
||||
```java
|
||||
@Configuration
|
||||
public class Myconfig {
|
||||
@Bean
|
||||
public DataSource dataSource()
|
||||
{
|
||||
org.apache.tomcat.jdbc.pool.DataSource dataSource=new org.apache.tomcat.jdbc.pool.DataSource();
|
||||
dataSource.setUrl("jdbc:mysql://localhost/test?characterEncoding=UTF-8");
|
||||
dataSource.setUsername("root");
|
||||
dataSource.setPassword("mysql");
|
||||
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
return dataSource;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
这个在 springboot 中已经学习过,后续我会把 springboot 学习过程以博客的方式记录下来,配置完成数据源之后,我们启动服务,访问 [http://localhost:9001/admin/health](http://localhost:9001/admin/health) 查看健康情况
|
||||
![[Pasted image 20220406221207.png]]
|
||||
|
||||
我们可以看到 db 的健康情况。假如此时我们的 mysql 服务挂掉,会怎样呢?
|
||||
![[Pasted image 20220406221107.png]]
|
||||
|
||||
我们手动停止 mysql 服务,然后再看健康情况
|
||||
|
||||
![[Pasted image 20220406221125.png]]
|
||||
发现 db 状态已经由 “UP” 变成了 “DOWN” 并显示了错误信息,这样就很方便我们查看服务的健康情况了。
|
132
spring-cloud/eureka/Eureka注册中心.md
Normal file
@ -0,0 +1,132 @@
|
||||
# 1.Eureka注册中心的作用
|
||||
在Eureka架构中,微服务角色分为两类
|
||||
+ EurekaServer:服务端,注册中心
|
||||
+ 记录服务信息
|
||||
+ 心跳监控
|
||||
+ EurekaClient:客户端
|
||||
+ 注册自己的信息到EurakaServer中
|
||||
+ 每隔30秒向EurakaServer发送心跳
|
||||
+ 根据服务名称向其他客户端发起远程调用
|
||||
+ 基于服务列表做负载均衡,选中一个服务后发起远程调用
|
||||
# 2.搭建eureka-server
|
||||
|
||||
首先大家注册中心服务端:eureka-server,这必须是一个独立的微服务
|
||||
|
||||
## 2.1.创建eureka-server服务
|
||||
|
||||
在cloud-demo父工程下,创建一个子模块:
|
||||
|
||||
![[Pasted image 20220405222734.png]]
|
||||
|
||||
填写模块信息:
|
||||
|
||||
![[Pasted image 20220405223018.png]]
|
||||
|
||||
然后填写服务信息:
|
||||
|
||||
![[Pasted image 20220405223056.png]]
|
||||
|
||||
## 2.2.引入eureka依赖
|
||||
|
||||
引入SpringCloud为eureka提供的starter依赖:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
## 2.3.编写启动类
|
||||
|
||||
给eureka-server服务编写一个启动类,一定要添加一个@EnableEurekaServer注解,开启eureka的注册中心功能:
|
||||
|
||||
```java
|
||||
package cn.itcast.eureka;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableEurekaServer
|
||||
public class EurekaApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EurekaApplication.class, args);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 2.4.编写配置文件
|
||||
|
||||
编写一个application.yml文件,内容如下:
|
||||
|
||||
```yaml
|
||||
server:
|
||||
port: 10086
|
||||
spring:
|
||||
application:
|
||||
name: eureka-server
|
||||
eureka:
|
||||
client:
|
||||
service-url:
|
||||
defaultZone: http://127.0.0.1:10086/eureka
|
||||
```
|
||||
|
||||
## 2.5.启动服务
|
||||
|
||||
启动微服务,然后在浏览器访问:[http://127.0.0.1:10086](http://127.0.0.1:10086)
|
||||
|
||||
看到下面结果应该是成功了:
|
||||
|
||||
![[Pasted image 20220405224233.png]]
|
||||
|
||||
# 3.服务注册
|
||||
## 3.1 引入依赖
|
||||
在要注册服务的pom文件中引入euraka-client依赖:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
## 3.2 配置文件
|
||||
修改application.yml文件,添加服务名称、eureka地址:
|
||||
|
||||
```yaml
|
||||
spring:
|
||||
application:
|
||||
name: userservice #当前服务名称
|
||||
eureka:
|
||||
client:
|
||||
service-url:
|
||||
defaultZone: http://127.0.0.1:10086/eureka #eureka-server 地址
|
||||
```
|
||||
|
||||
## 3.3启动多个userservice实例
|
||||
为了演示一个服务有多个实例的场景,我们添加一个SpringBoot的启动配置,再启动一个user-service。
|
||||
|
||||
|
||||
首先,复制原来的user-service启动配置:
|
||||
|
||||
![[Pasted image 20220405224152.png]]
|
||||
|
||||
然后,在弹出的窗口中,填写信息:
|
||||
|
||||
![[Pasted image 20220405224314.png]]
|
||||
|
||||
现在,SpringBoot窗口会出现两个user-service启动配置:
|
||||
|
||||
![[Pasted image 20220405224333.png]]
|
||||
|
||||
不过,第一个是8081端口,第二个是8082端口。
|
||||
|
||||
启动两个user-service实例:
|
||||
|
||||
![[Pasted image 20220405224355.png]]
|
||||
|
||||
查看eureka-server管理页面:
|
||||
|
||||
![[Pasted image 20220405224406.png]]
|
BIN
spring-cloud/eureka/assets/Pasted image 20220405222734.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220405223018.png
Normal file
After Width: | Height: | Size: 141 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220405223056.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220405224152.png
Normal file
After Width: | Height: | Size: 92 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220405224233.png
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220405224314.png
Normal file
After Width: | Height: | Size: 75 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220405224333.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220405224355.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220405224406.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220406220855.png
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220406220914.png
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220406220933.png
Normal file
After Width: | Height: | Size: 56 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220406220957.png
Normal file
After Width: | Height: | Size: 49 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220406221107.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220406221125.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
spring-cloud/eureka/assets/Pasted image 20220406221207.png
Normal file
After Width: | Height: | Size: 43 KiB |
140
vm/virtualbox/VirtualBox 搭建Ubuntu20.04.md
Normal file
@ -0,0 +1,140 @@
|
||||
# VirtualBox 搭建Ubuntu20.04
|
||||
## 演示环境
|
||||
+ VirtualBox 6.1.32
|
||||
+ ubuntu-20.04.4-live-server-amd64.iso
|
||||
## 依赖下载
|
||||
[VirtualBox 官网地址](https://www.virtualbox.org/wiki/Downloads)
|
||||
[Ubuntu20.04 阿里云镜像站](http://mirrors.aliyun.com/ubuntu-releases/20.04/)
|
||||
|
||||
> VirtualBox 安装较为简单不做演示
|
||||
|
||||
## 开始搭建
|
||||
### 新建虚拟电脑
|
||||
选择工具点击新建
|
||||
![[Pasted image 20220419003859.png]]
|
||||
|
||||
设置内存大小
|
||||
![[Pasted image 20220419003957.png]]
|
||||
|
||||
默认
|
||||
![[Pasted image 20220419004014.png]]
|
||||
|
||||
默认
|
||||
![[Pasted image 20220419004022.png]]
|
||||
|
||||
这里我为了演示节省时间选择的是动态大小 硬盘空间充足的话建议选择固定大小
|
||||
![[Pasted image 20220419004030.png]]
|
||||
|
||||
设置硬盘大小
|
||||
![[Pasted image 20220419004037.png]]
|
||||
|
||||
### 设置虚拟网卡
|
||||
ctrl+h 打开网络管理器 选中已有的网卡或新建网卡进行配置 点击属性配置网卡的信息 我这里改的是10.0.0 的网段
|
||||
不懂网络的同学可以按照我的去做
|
||||
![[Pasted image 20220419005241.png]]
|
||||
|
||||
![[Pasted image 20220419005247.png]]
|
||||
|
||||
### 修改虚拟机配置
|
||||
选中我们创建的虚拟机点击设置 打开虚拟机的配置页面
|
||||
![[Pasted image 20220419010011.png]]
|
||||
|
||||
设置内存大小 建议不超过宿主机内存的百分之五十
|
||||
![[Pasted image 20220419010034.png]]
|
||||
|
||||
设置处理器数量 建议不超过宿主机的百分之五十
|
||||
![[Pasted image 20220419010045.png]]
|
||||
|
||||
显存可以设置小一点
|
||||
![[Pasted image 20220419010054.png]]
|
||||
|
||||
根据步骤添加我们下载的镜像为虚拟光盘
|
||||
![[Pasted image 20220419010455.png]]
|
||||
|
||||
设置好的样子
|
||||
![[Pasted image 20220419010110.png]]
|
||||
|
||||
配置网络
|
||||
网卡一连接方式选择Host-Only 可以在这个网络下和宿主机以及其他虚拟机组成一个局域网
|
||||
![[Pasted image 20220419010116.png]]
|
||||
|
||||
网卡二 连接方式选中桥接网卡 界面名称选择你电脑上可以链接到公网的网卡 网卡二可以让我们的虚拟机上公网
|
||||
![[Pasted image 20220419010124.png]]
|
||||
|
||||
### 开始安装
|
||||
双击启动 默认选择英文不需要改动 直接回车进入下一步
|
||||
![[Pasted image 20220419010926.png]]
|
||||
|
||||
配置键盘布局 选择“Done” 回车
|
||||
![[Pasted image 20220419010935.png]]
|
||||
|
||||
网络配置 不需要动,以防修改错误后续操作无法进行 继续Done
|
||||
![[Pasted image 20220419010944.png]]
|
||||
|
||||
不需要填 选中Done回车
|
||||
![[Pasted image 20220419010951.png]]
|
||||
|
||||
这里可以改为阿里云软件源的镜像地址 https://mirrors.aliyun.com/ubuntu/
|
||||
![[Pasted image 20220419010958.png]]
|
||||
|
||||
后面的的配置默认不需要修改 选择Done 和 continue 知道自定义用户账号信息
|
||||
|
||||
自定义用户账号信息,输入完成之后,选择“Done”,按Enter键
|
||||
![[Pasted image 20220419011004.png]]
|
||||
|
||||
中间页面默认不需要修改
|
||||
|
||||
安装ssh远程连接 建议在进入系统后手动安装
|
||||
![[Pasted image 20220419011015.png]]
|
||||
|
||||
默认选中Done 下一步至此页面 等待漫长的安装过程
|
||||
|
||||
![[Pasted image 20220419011022.png]]
|
||||
|
||||
安装完成后会出现Reboot Now选项 选择此选项回车进行重启
|
||||
![[Pasted image 20220419012839.png]]
|
||||
|
||||
等待重启过程中,如果卡住,多按几次Enter键即可
|
||||
![[Pasted image 20220419012853.png]]
|
||||
|
||||
在登陆页面 如果卡住 同时按alt+f2 切换一个控制台进行登录 不出现的话多按几次
|
||||
![[Pasted image 20220419012859.png]]
|
||||
|
||||
输入账号密码进入系统
|
||||
![[Pasted image 20220419012906.png]]
|
||||
|
||||
执行以下命令解决Used fallback datasource问题 [修复此问题原文地址](https://askubuntu.com/questions/1321968/ubuntu-server-20-04-2-lts-hangs-after-bootup-cloud-init-1781-yyyy-mm-dd-h)
|
||||
```shell
|
||||
sudo touch /etc/cloud/cloud-init.disabled
|
||||
```
|
||||
|
||||
### 配置固定ip并测试网络
|
||||
|
||||
```shell
|
||||
#安装net-tools
|
||||
sudo apt install net-tools
|
||||
|
||||
#查看当前的网络
|
||||
ifconfig
|
||||
|
||||
```
|
||||
|
||||
![[Pasted image 20220419013832.png]]
|
||||
|
||||
设置固定ip地址
|
||||
编辑/etc/netplan/ 下的yaml文件
|
||||
`sudo vim /etc/netplan/***.yaml`
|
||||
![[Pasted image 20220419015105.png]]
|
||||
|
||||
```shell
|
||||
#使刚才设置网卡的配置生效
|
||||
sudo netplan apply
|
||||
#使用ifconfig查看ip是否设置成功
|
||||
ifconfig
|
||||
#使用ping命令查看是否可以访问公网
|
||||
ping www.baidu.com
|
||||
```
|
||||
|
||||
![[Pasted image 20220419014308.png]]
|
||||
|
||||
到此位置你的Ubuntu已经搭建完毕.
|
BIN
vm/virtualbox/assets/Pasted image 20220419003859.png
Normal file
After Width: | Height: | Size: 172 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419003957.png
Normal file
After Width: | Height: | Size: 166 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419004011.png
Normal file
After Width: | Height: | Size: 173 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419004014.png
Normal file
After Width: | Height: | Size: 173 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419004022.png
Normal file
After Width: | Height: | Size: 174 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419004030.png
Normal file
After Width: | Height: | Size: 177 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419004037.png
Normal file
After Width: | Height: | Size: 174 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419005241.png
Normal file
After Width: | Height: | Size: 184 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419005247.png
Normal file
After Width: | Height: | Size: 181 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010011.png
Normal file
After Width: | Height: | Size: 141 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010023.png
Normal file
After Width: | Height: | Size: 141 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010034.png
Normal file
After Width: | Height: | Size: 39 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010045.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010054.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010103.png
Normal file
After Width: | Height: | Size: 260 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010110.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010116.png
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010124.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010455.png
Normal file
After Width: | Height: | Size: 64 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010926.png
Normal file
After Width: | Height: | Size: 147 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010935.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010939.png
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010944.png
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010951.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419010958.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419011004.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419011010.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419011015.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419011022.png
Normal file
After Width: | Height: | Size: 59 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419012839.png
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419012853.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419012859.png
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419012906.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419013832.png
Normal file
After Width: | Height: | Size: 70 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419014301.png
Normal file
After Width: | Height: | Size: 56 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419014308.png
Normal file
After Width: | Height: | Size: 89 KiB |
BIN
vm/virtualbox/assets/Pasted image 20220419015105.png
Normal file
After Width: | Height: | Size: 42 KiB |