From 2ec73f7b8773315ae81ed8e5e55bd490bd4e7ee2 Mon Sep 17 00:00:00 2001 From: "YUN-PC5\\user" Date: Fri, 10 Nov 2023 16:05:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/_posts/Docker.md | 144 +++++++++++++++++++++++++++++++++++++--- source/_posts/Linux.md | 130 +++++++++++++++++++++++++++++++++++- source/_posts/MySQL.md | 7 +- source/_posts/Redis.md | 52 ++++++++++++++- 4 files changed, 319 insertions(+), 14 deletions(-) diff --git a/source/_posts/Docker.md b/source/_posts/Docker.md index 754755c..54e7cfc 100644 --- a/source/_posts/Docker.md +++ b/source/_posts/Docker.md @@ -35,12 +35,16 @@ yum list docker-ce --showduplicates | sort -r yum install docker-ce-18.03.1.ce # almalinux centos8 +dnf clean all +dnf update # 添加必要的Docker存储库 dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo # 找到Docker CE的可安装版本 dnf list docker-ce --showduplicates | sort -r # 安装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镜像。。 @@ -67,7 +71,37 @@ docker info 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 @@ -75,19 +109,28 @@ MySQL 5.7 docker pull mysql:5.7 ``` -## Docker 移除镜像 image +### 删除镜像 若已有镜像用于容器,请先将容器删除 ```shell docker rm -f +docker image rm +docker rmi +# 强制删除镜像(已经创建容器的镜像) +docker rmi --force ``` +### 查看镜像 + ```shell -docker image rm hello-world -docker rmi hello-world +docker inspect ``` +## Docker 容器操作 + +### 运行容器 + ```shell # 第一个8080是外部海豚上的 第二个8080是内部集装箱上的 docker run -p 8080:8080 @@ -112,24 +155,91 @@ docker run -p 8080:8080 --expose=[]: 开放一个端口或一组端口; --volume , -v 绑定一个卷 -docker启动容器 +### 启动容器 ```shell docker start ``` -docker停止容器 +### 停止容器 ```shell docker stop ``` -docker重启容器 +### 重启容器 ```shell docker restart ``` +### 删除容器 + +```shell +docker rm +``` + +### 强制删除容器(正在运行的容器) + +```shell +docker rm --force +# 或者 +docker rm -f +``` + +### 查看容器 + +```shell +docker inspect +``` + + + +## Docker 镜像保存和加载 + +### 本地保存 + +首先可以通过`docker save`命令可以将docker内部的一个或多个镜像导出成文件。下面的命令中先下载nginx,hello-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 容器与宿主机时间不同步 对于已创建的容器: @@ -172,6 +282,24 @@ docker ps -a docker start ``` +## Docker 动态修改 --restart 参数 + +--restart参数 + +- no 不自动重启 +- on-failure:重启次数 指定自动重启的失败次数,到达失败次数后不再重启 +- always 自动重启 + +修改线上容器--restart参数值 + +```shell +docker update --restart=no [容器名] +docker update --restart=always [容器名] +docker update --restart=on-failure:3 [容器名] +``` + + + ## Docker 的镜像迁移到另一台服务器 ```shell diff --git a/source/_posts/Linux.md b/source/_posts/Linux.md index 348e52c..f861295 100644 --- a/source/_posts/Linux.md +++ b/source/_posts/Linux.md @@ -1,7 +1,7 @@ --- title: Linux 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 @@ -31,6 +31,14 @@ dev:存放设备文件 ## Linux指令 +Ctrl+u 删除命令行开始至光标处 + +Ctrl+k 删除光标至命令行结尾 + +Ctrl+a 光标移到最前 + +Ctrl+e 光标移到最后 + ip addr(ip a):查看主机的ip地址 clear:清屏 @@ -60,7 +68,6 @@ cp -r init spring/ - ls:列出当前目录下的所有文件及目录 ls -l:给ls指令传了一个参数l。等同于ll。列出当前目录下的所有文件及目录的详情。 ls bin:ls后可以接目录名,要么接绝对路径。 @@ -139,7 +146,14 @@ systemctl status network 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目录为例) @@ -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环境变量 将tar.gz格式的jdk解压后移动到/usr目录下 @@ -660,6 +753,30 @@ systemd=true 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 ```shell @@ -721,6 +838,7 @@ sudo systemctl enable redis ```shell sudo systemctl is-enabled redis sudo systemctl status redis +redis-server ``` 下面的输出确认Redis正在运行并被启用,这意味着它将在系统启动时自动运行。 @@ -733,6 +851,14 @@ sudo systemctl status redis sudo vim /etc/redis.conf ``` +### Redis-CLI + +```shell +redis-cli +auth + +``` + ## 安装.Net 6 SDK ```shell diff --git a/source/_posts/MySQL.md b/source/_posts/MySQL.md index 61d3524..3fea230 100644 --- a/source/_posts/MySQL.md +++ b/source/_posts/MySQL.md @@ -208,8 +208,13 @@ mysqldump -uroot -p -B test > test.sql 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 + 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 客户端 diff --git a/source/_posts/Redis.md b/source/_posts/Redis.md index 8ee72e0..1ec9270 100644 --- a/source/_posts/Redis.md +++ b/source/_posts/Redis.md @@ -65,6 +65,52 @@ requirepass yourpassword # 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操作指令 1. set: 设置key-value @@ -180,7 +226,7 @@ requirepass yourpassword 11. hincrby:为value进行加法计算 12. hincrbyfloat:为value进行加分计算,小数 -### Redis主从架构 +# Redis主从架构 在redis主从架构中,Master节点负责处理写请求,Slave节点只处理读请求。对于写请求少,读请求多的场景,例如电商详情页,通过这种读写分离的操作可以大幅提高并发量,通过增加redis从节点的数量可以使得redis的QPS达到10W+。 @@ -218,7 +264,7 @@ slaveof 192.168.56.101 6379 此时就需要用到Redis哨兵机制 -### Redis哨兵机制 +# Redis哨兵机制 哨兵机制就是起一台机器用作哨兵,这个哨兵负责监听主机,如果主机挂了,那么它会让从机接替主机位,以此类推,需要用到选举 @@ -243,7 +289,7 @@ cp /root/sentinel/sentinel.conf /usr/redis/bin ./redis-sentinel sentinel.conf ``` -## Redis缓存穿透 +# Redis缓存穿透 > 缓存穿透指的查询缓存和数据库中都不存在的数据,这样每次请求直接打到数据库,就好像缓存不存在一样。