This commit is contained in:
YUN-PC5\user 2023-11-10 16:05:05 +08:00
parent 85aa55b3a1
commit 2ec73f7b87
4 changed files with 319 additions and 14 deletions

View File

@ -35,12 +35,16 @@ yum list docker-ce --showduplicates | sort -r
yum install docker-ce-18.03.1.ce yum install docker-ce-18.03.1.ce
# almalinux centos8 # almalinux centos8
dnf clean all
dnf update
# 添加必要的Docker存储库 # 添加必要的Docker存储库
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
# 找到Docker CE的可安装版本 # 找到Docker CE的可安装版本
dnf list docker-ce --showduplicates | sort -r dnf list docker-ce --showduplicates | sort -r
# 安装Docker CE # 安装Docker CE
dnf install docker-ce-3:24.0.7-1.el9 dnf install docker-ce-3:24.0.7-1.el9 -y
# 镜像源配置
vim /etc/docker/daemon.json
``` ```
1、镜像image。一个镜像代表一个软件。如redis镜像mysql镜像tomcat镜像。。 1、镜像image。一个镜像代表一个软件。如redis镜像mysql镜像tomcat镜像。。
@ -67,7 +71,37 @@ docker info
docker images docker images
``` ```
## Docker 安装镜像 image ## 查找镜像和下载
### 远程查找镜像
```shell
docker search ubuntu
```
### 查找容器的版本信息
在找到所需要的容器镜像的名称之后通常需要进一步在docker的镜像源中查找该镜像的版本列表。由于docker本身没有直接提供查看版本的功能因此在这里我们为大家提供了一个可以查看镜像版本的简单脚本docker-tags。我们生成docker-tags脚本并加入以下内容
```shell
vim docker-tags
# 添加以下内容
curl -s -S "https://registry.hub.docker.com/v2/repositories/library/$1/tags/?page=$2" |
sed -e 's/,/\n/g' -e 's/\[/\\\[\n/g' |
grep -E '"name":|"count":' |
sed -e 's/"//g' -e "s/name:/$1:/g" -e "s/{count:/$1总版本数-/"
```
docker-tags脚本编辑好之后需要通过chmod修改文件权限才可以执行。在权限修改完成之后就可以使用docker-tags脚本来查询相关镜像的最近版本信息了。
```shell
chmod 777 docker-tags
./docker-tags ubuntu
```
## Docker 镜像操作
### 安装镜像
MySQL 5.7 MySQL 5.7
@ -75,19 +109,28 @@ MySQL 5.7
docker pull mysql:5.7 docker pull mysql:5.7
``` ```
## Docker 移除镜像 image ### 删除镜像
若已有镜像用于容器,请先将容器删除 若已有镜像用于容器,请先将容器删除
```shell ```shell
docker rm -f <CONTAINER ID> docker rm -f <CONTAINER ID>
docker image rm <IMAGE ID>
docker rmi <IMAGE ID>
# 强制删除镜像(已经创建容器的镜像)
docker rmi --force <IAMGE ID>
``` ```
### 查看镜像
```shell ```shell
docker image rm hello-world docker inspect <IMAGE ID>
docker rmi hello-world
``` ```
## Docker 容器操作
### 运行容器
```shell ```shell
# 第一个8080是外部海豚上的 第二个8080是内部集装箱上的 # 第一个8080是外部海豚上的 第二个8080是内部集装箱上的
docker run -p 8080:8080 docker run -p 8080:8080
@ -112,24 +155,91 @@ docker run -p 8080:8080
--expose=[]: 开放一个端口或一组端口; --expose=[]: 开放一个端口或一组端口;
--volume , -v 绑定一个卷 --volume , -v 绑定一个卷
docker启动容器 ### 启动容器
```shell ```shell
docker start <container id> docker start <container id>
``` ```
docker停止容器 ### 停止容器
```shell ```shell
docker stop <container id> docker stop <container id>
``` ```
docker重启容器 ### 重启容器
```shell ```shell
docker restart <container id> docker restart <container id>
``` ```
### 删除容器
```shell
docker rm <container id>
```
### 强制删除容器(正在运行的容器)
```shell
docker rm --force <container id>
# 或者
docker rm -f <container id>
```
### 查看容器
```shell
docker inspect <container id>
```
## Docker 镜像保存和加载
### 本地保存
首先可以通过`docker save`命令可以将docker内部的一个或多个镜像导出成文件。下面的命令中先下载nginxhello-world两个镜像然后再将镜像导出到images.tar文件中。`docker save的格式为docker save -o [导出文件名] [需要导出的镜像列表]...`
```shell
docker pull hello-world
docker pull nginx
docker save -o images.tar nginx hello-world
ll images.tar
```
### 从本地加载镜像文件
接下来通过`docker load`命令将`images.tar`中的两个镜像导入回docker内部。即可实现在没有网络访问的情况更新镜像。docker load的格式为`docker load -i [导入文件名]`。要注意的是如果docker内部已经存在了相关的镜像文件中的镜像会被忽略。
在镜像导入完毕之后,可以通过`docker images`进行验证。
```shell
docker load -i images.tar
docker images
```
## Docker 容器快照的导出和导入
### 容器快照的导出
当容器文件修改之后,可以通过`docker export`命令将容器以快照的形式导出到文件。其命令的格式为`docker export 容器名 > 快照文件名`。和镜像导出不同,快照的导出,会将容器的镜像,和容器在镜像之上的修改部分同时导出
```shell
docker export python-1 > python-snapshot.tar
ll python-snapshot.tar
```
### 容器快照的导入
对于通过`docker export`导出的容器快照文件。可以通过`docker import`命令将其导入到docker中在这里需要特别注意的是`docker import是以镜像而不是容器的形式导入快照`。也就是说导入的快照并不能直接运行,而是需要根据此快照镜像再次创建容器才可以使用。`docker import`命令的格式为`docker import 快照文件 导入镜像名称:版本号`
```shell
docker import python-snapshot.tar python-snapshot:latest
```
## Docker 容器与宿主机时间不同步 ## Docker 容器与宿主机时间不同步
对于已创建的容器: 对于已创建的容器:
@ -172,6 +282,24 @@ docker ps -a
docker start <container id> docker start <container id>
``` ```
## Docker 动态修改 --restart 参数
--restart参数
- no 不自动重启
- on-failure:重启次数 指定自动重启的失败次数,到达失败次数后不再重启
- always 自动重启
修改线上容器--restart参数值
```shell
docker update --restart=no [容器名]
docker update --restart=always [容器名]
docker update --restart=on-failure:3 [容器名]
```
## Docker 的镜像迁移到另一台服务器 ## Docker 的镜像迁移到另一台服务器
```shell ```shell

View File

@ -1,7 +1,7 @@
--- ---
title: Linux title: Linux
author: 文永达 author: 文永达
top_img: https://gcore.jsdelivr.net/gh/volantis-x/cdn-wallpaper/abstract/00E0F0ED-9F1C-407A-9AA6-545649D919F4.jpeg top_img:https://gcore.jsdelivr.net/gh/volantis-x/cdn-wallpaper/abstract/00E0F0ED-9F1C-407A-9AA6-545649D919F4.jpeg
--- ---
# Linux # Linux
@ -31,6 +31,14 @@ dev存放设备文件
## Linux指令 ## Linux指令
Ctrl+u 删除命令行开始至光标处
Ctrl+k 删除光标至命令行结尾
Ctrl+a 光标移到最前
Ctrl+e 光标移到最后
ip addrip a查看主机的ip地址 ip addrip a查看主机的ip地址
clear清屏 clear清屏
@ -60,7 +68,6 @@ cp -r init spring/
ls列出当前目录下的所有文件及目录 ls列出当前目录下的所有文件及目录
ls -l给ls指令传了一个参数l。等同于ll。列出当前目录下的所有文件及目录的详情。 ls -l给ls指令传了一个参数l。等同于ll。列出当前目录下的所有文件及目录的详情。
ls binls后可以接目录名要么接绝对路径。 ls binls后可以接目录名要么接绝对路径。
@ -139,7 +146,14 @@ systemctl status network
netstat -lnp | grep 8080 netstat -lnp | grep 8080
``` ```
### 获取路径:
```shell
readlink -f sample.txt /home/gliu/sample.txt
realpath -s sample.txt /home/gliu/sample.txt
find $(pwd) -name sample.txt /home/gliu/sample.txt
ls -l $PWD/sample.txt
```
## 文件详情以home目录为例 ## 文件详情以home目录为例
@ -442,6 +456,85 @@ flush privileges;
--- ---
### AlmaLinux 安装
1. 首先确保系统是最新的。
```shell
sudo dnf clean all
sudo dnf update
sudo dnf groupinstall "Development Tools"
```
2. 安装 MySQL
默认情况下MySQL 在 AlmaLinux 9 基础存储库中可用。 只需使用以下命令安装 MySQL 服务器包 `dnf` 命令:
```shell
sudo dnf install mysql mysql-server
```
设置表名不区分大小写
```shell
vim /etc/my.cnf.d/mysql-server.cnf
# 在 [mysqld] 中添加
lower_case_table_names=1
```
初始化后查询是否生效
```mysql
show global variables like '%lower_case%';
# lower_case_table_names 为 1
```
启动 MySQL 服务并通过运行以下命令使其在启动时自动启动:
```shell
sudo systemctl status mysqld
sudo systemctl enable --now mysqld
```
确认安装并检查已安装的 MySQL 构建版本:
```shell
mysql --version
```
3. 在 AlmaLinux 9 上保护 MySQL。
默认情况下MySQL 未加固。 您可以使用 `mysql_secure_installation` 脚本。 您应该仔细阅读以下每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录、删除测试数据库和访问安全 MySQL
```shell
mysql_secure_installation
```
对提示使用以下选项:
```shell
Enter current password for root (enter for none): Just press the Enter
Set root password? [Y/n]: Y
New password: Enter your password
Re-enter new password: Repeat your password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
```
安全后,您可以使用以下命令登录 MySQL shell:
```shell
sudo mysql -u root -p
```
要创建数据库、数据库用户并向数据库用户授予所有权限,请运行以下命令:
```mysql
CREATE DATABASE test_db;
CREATE USER 'test_user'@'localhost' IDENTIFIED BY 'your-password';
GRANT ALL ON tests_db.* TO 'test_user'@'localhost';
FLUSH PRIVILEGES;
EXIT
```
## 配置Java环境变量 ## 配置Java环境变量
将tar.gz格式的jdk解压后移动到/usr目录下 将tar.gz格式的jdk解压后移动到/usr目录下
@ -660,6 +753,30 @@ systemd=true
wsl --shutdown wsl --shutdown
``` ```
## 安装 7zip
```shell
# 更新系统数据库
sudo dnf update -y
# 启用 Epel repository
sudo dnf install epel-release
# 安装 7-Zip
sudo dnf install p7zip p7zip-plugins
# 检验是否安装上
7z
# 使用
# 创建压缩文件 命令中的选项a用于压缩
7z a data.7z data.txt
# 显示每个存档文件的详细信息列表
7z l data.7z
# 解压缩
# 注意 -o 用来指定解压缩文件存放目录,-o 后是没有空格的,直接接目录
7z x data.7z -r -o./data
```
## 安装 Nginx ## 安装 Nginx
```shell ```shell
@ -721,6 +838,7 @@ sudo systemctl enable redis
```shell ```shell
sudo systemctl is-enabled redis sudo systemctl is-enabled redis
sudo systemctl status redis sudo systemctl status redis
redis-server
``` ```
下面的输出确认Redis正在运行并被启用这意味着它将在系统启动时自动运行。 下面的输出确认Redis正在运行并被启用这意味着它将在系统启动时自动运行。
@ -733,6 +851,14 @@ sudo systemctl status redis
sudo vim /etc/redis.conf sudo vim /etc/redis.conf
``` ```
### Redis-CLI
```shell
redis-cli
auth <password>
```
## 安装.Net 6 SDK ## 安装.Net 6 SDK
```shell ```shell

View File

@ -208,8 +208,13 @@ mysqldump -uroot -p -B test > test.sql
make 被 compat-openssl10-1:1.0.2o-3.el8.x86_64 需要 make 被 compat-openssl10-1:1.0.2o-3.el8.x86_64 需要
rpm -i compat-openssl10-1.0.2o-3.el8.x86_64.rpm --nodeps --force rpm -i compat-openssl10-1.0.2o-3.el8.x86_64.rpm --nodeps --force
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
cp /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
cp /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
``` ```
# MySQL 客户端 # MySQL 客户端

View File

@ -65,6 +65,52 @@ requirepass yourpassword
# Redis指令 # Redis指令
Redis 命令用于在 redis 服务上执行操作。
要在 redis 服务上执行命令需要一个 redis 客户端。Redis 客户端在我们之前下载的的 redis 的安装包中。语法
Redis 客户端的基本语法为:
```
$ redis-cli
```
### 实例
以下实例讲解了如何启动 redis 客户端:
启动 redis 服务器,打开终端并输入命令 **redis-cli**,该命令会连接本地的 redis 服务。
```shell
$ redis-cli
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING
PONG
```
在以上实例中我们连接到本地的 redis 服务并执行 **PING** 命令,该命令用于检测 redis 服务是否启动。在远程服务上执行命令
如果需要在远程 redis 服务上执行命令,同样我们使用的也是 **redis-cli** 命令。
### 语法
```shell
$ redis-cli -h host -p port -a password
```
### 实例
以下实例演示了如何连接到主机为 127.0.0.1,端口为 6379 ,密码为 mypass 的 redis 服务上。
```shell
$redis-cli -h 127.0.0.1 -p 6379 -a "mypass"
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING
PONG
```
## key操作指令 ## key操作指令
1. set: 设置key-value 1. set: 设置key-value
@ -180,7 +226,7 @@ requirepass yourpassword
11. hincrby:为value进行加法计算 11. hincrby:为value进行加法计算
12. hincrbyfloat:为value进行加分计算,小数 12. hincrbyfloat:为value进行加分计算,小数
### Redis主从架构 # Redis主从架构
在redis主从架构中Master节点负责处理写请求Slave节点只处理读请求。对于写请求少读请求多的场景例如电商详情页通过这种读写分离的操作可以大幅提高并发量通过增加redis从节点的数量可以使得redis的QPS达到10W+。 在redis主从架构中Master节点负责处理写请求Slave节点只处理读请求。对于写请求少读请求多的场景例如电商详情页通过这种读写分离的操作可以大幅提高并发量通过增加redis从节点的数量可以使得redis的QPS达到10W+。
@ -218,7 +264,7 @@ slaveof 192.168.56.101 6379
此时就需要用到Redis哨兵机制 此时就需要用到Redis哨兵机制
### Redis哨兵机制 # Redis哨兵机制
哨兵机制就是起一台机器用作哨兵,这个哨兵负责监听主机,如果主机挂了,那么它会让从机接替主机位,以此类推,需要用到选举 哨兵机制就是起一台机器用作哨兵,这个哨兵负责监听主机,如果主机挂了,那么它会让从机接替主机位,以此类推,需要用到选举
@ -243,7 +289,7 @@ cp /root/sentinel/sentinel.conf /usr/redis/bin
./redis-sentinel sentinel.conf ./redis-sentinel sentinel.conf
``` ```
## Redis缓存穿透 # Redis缓存穿透
> 缓存穿透指的查询缓存和数据库中都不存在的数据,这样每次请求直接打到数据库,就好像缓存不存在一样。 > 缓存穿透指的查询缓存和数据库中都不存在的数据,这样每次请求直接打到数据库,就好像缓存不存在一样。