首页
博客小事纪
网站统计
友情链接
推荐
百度一下
文心一言
通义千问
Search
1
基于 openEuler 操作系统的 VNC(noVNC) 部署流程
479 阅读
2
openEuler 操作系统用户权限管理——sudo 权限的授予与限制案例
426 阅读
3
基于 openEuler 操作系统使用 Sealos 构建 Kubernetes 高可用集群
349 阅读
4
openEuler 搭建本地 repo 源
269 阅读
5
基于 openEuler 22.03 LTS SP4 编译 docker 20.10.13
140 阅读
默认分类
openEuler
x2openEuler
云原生
生活随笔
登录
Search
标签搜索
openEuler
Docker
故宫
kubernetes
x2openEuler
Nginx
repo
VNC
SUSE
DeepSeek
Ollama
AI
闫志聪
累计撰写
17
篇文章
累计收到
0
条评论
首页
栏目
默认分类
openEuler
x2openEuler
云原生
生活随笔
页面
博客小事纪
网站统计
友情链接
推荐
百度一下
文心一言
通义千问
搜索到
9
篇与
的结果
2024-08-14
openEuler 搭建本地 repo 源
1 前言everything 镜像中包含了许多 rpm 包,可以提供基本的安装使用,然而还有一部分软件包需要连网到公网 repo 源中下载。但是在生产环境中,服务器大多数是不能连接公网的,因此需要搭建一个局域网 repo 源,即让一台能够连接公网的服务器从公网 repo 源中同步 rpm 包到本地,然后局域网的其他服务器再从这台能连接公网的服务器中下载 rpm 包2 所需的服务或命令2.1 Web 服务用于局域网中其他服务器访问,可以使用 httpd 服务或 nginx 服务2.2 dnf reposync 命令$ dnf reposync [OPTIONS] -c [CONFIG FILE] 指定配置文件运行(默认配置文件是 /etc/yum.conf) -q 安静操作 -v 显示详细信息 -b 尝试使用最佳的软件包版本 -C 完全从系统缓存运行,不更新缓存 -R [minutes] 最大命令等待时间 -y 所有问题自动回答 yes --assumeno 所有问题自动回答 no --enablerepo [repo] 启用其他存储库,可以指定多次 --disablerepo [repo] 禁用仓库,可以指定多次 --repo [repo], --repoid [repo] 仅使用指定的存储库 --exclude [package] 排除软件包 --forcearch ARCH 强制使用指定的架构 --arch [arch] 仅下载指定架构的软件包 --delete 删除存储库中不再存在的本地软件包 -n 仅下载最新的软件包 -p DOWNLOAD_PATH 指定软件包下载的位置 --norepopath 在下载目录中不重新生成以 `repo name` 命名的目录2.3 createrepo 命令$ createrepo [OPTION?] <directory_to_index> -q 以安静模式运行 -v 显示详细信息 -o 指定生成的元数据存放的位置 --excludes=PACKAGE_NAME_GLOB 指定生成元数据时排除的包 --update 在原有元数据上升级,只更新有变化的软件 --workers 读取 rpm 包的数量,默认为 53 同步官方源服务器名称用途操作系统版本IP 地址Server搭建局域网 repo 源openEuler 22.03 LTS SP1192.168.255.221Client模拟局域网内主机openEuler 22.03 LTS192.168.255.2203.1 Server 端配置3.1.1 系统基本设置# 关闭防火墙,并停止开机自启 $ systemctl stop firewalld $ systemctl disable firewalld # 关闭 SELinux $ setenforce 0 # 安装用于提供 reposync 命令的工具包 $ yum install -y dnf-plugins-core # 安装用于提供 createrepo 命令的工具包 $ yum install -y createrepo # 创建专用目录,保存同步的 RPM 包 $ mkdir /openEuler-22.03-LTS-REPO另外注意要留有足够的分区空间去保存 RPM 包3.1.2 配置 Web 服务此处使用 nginx 服务# 安装 nginx $ yum install -y nginx # 启动服务,并设置开机自启 $ systemctl start nginx $ systemctl enable nginx # 在默认网页根目录下创建 openEuler-22.03-LTS 目录及以下子目录,用来存放 RPM 包 $ mkdir -p /usr/share/nginx/html/openEuler-22.03-LTS/{everything,update,EPOL} $ mkdir -p /usr/share/nginx/html/openEuler-22.03-LTS/EPOL/main # 编写配置文件,允许显示目录索引 $ cat > /etc/nginx/conf.d/openEuler-22.03-LTS.conf <<EOF server { listen 8001; root /usr/share/nginx/html/openEuler-22.03-LTS; location / { autoindex on; autoindex_exact_size off; autoindex_format html; autoindex_localtime on; } } EOF # 重启 nginx 服务 $ systemctl restart nginx使用 Windows 浏览器访问 http://192.168.255.221:8001,查看访问是否正常3.1.3 配置 repo 源Server 端需要配置局域网内客户端主机操作系统的 repo 源。例如本实验中作为局域网 repo 源服务器的 Server 端的操作系统版本为 openEuler 22.03 LTS SP1,而客户端主机操作系统为 openEuler 22.03 LTS,那么需要在 Server 端配置 openEuler 22.03 LTS 操作系统的 repo 源openEuler 各版本的 repo 源可以在论坛中找到:【汇总贴】openEuler常用repo源 - 迁移 - openEuler 论坛注意:一定要修改新添加的 repo 源的 repo id 和 repo name,即修改 [ REPO ID ] 和 naem=REPO NAME 的内容,否则可能会和现有的 repo 源名字冲突# 在 Server 端配置客户端主机操作系统的 reop 源 $ cat > /etc/yum.repos.d/openEuler-22.03-LTS.repo <<EOF [openEuler-22.03-everything] name=openEuler-22.03-everything baseurl=http://repo.huaweicloud.com/openeuler/openEuler-22.03-LTS/everything/x86_64/ enabled=1 gpgcheck=0 gpgkey=http://repo.huaweicloud.com/openeuler/openEuler-22.03-LTS/everything/x86_64/RPM-GPG-KEY-openEuler [openEuler-22.03-EPOL] name=openEuler-22.03-EPOL baseurl=http://repo.huaweicloud.com/openeuler/openEuler-22.03-LTS/EPOL/main/x86_64/ enabled=1 gpgcheck=0 [openEuler-22.03-update] name=openEuler-22.03-update baseurl=http://repo.huaweicloud.com/openeuler/openEuler-22.03-LTS/update/x86_64/ enabled=1 gpgcheck=0 EOF # 清空 yum 缓存 $ yum clean all # 重建 yum 缓存 $ yum makecache # 查看当前的 repo 源 $ yum repolist repo id repo name openEuler-22.03-EPOL openEuler-22.03-EPOL openEuler-22.03-everything openEuler-22.03-everything openEuler-22.03-update openEuler-22.03-update从命令返回结果看到,openEuler 22.03 LTS 版本的 repo 源已经成功添加,另外需要记住此处的 repo id ,在同步时会指定 --repoid=REPO_ID 选项3.1.4 同步 everything 源(1)同步 everything 源的 RPM 包到本地# 同步 everything 源的 RPM 包到本地 $ dnf reposync -v --repoid=openEuler-22.03-everything -p /openEuler-22.03-LTS-REPO # 同步完成后会在 /openEuler-22.03-LTS-REPO 目录创建一个名称同 repo name 的目录 $ ls /openEuler-22.03-LTS-REPO/ openEuler-22.03-everything # 查看目录结构 $ tree -L 1 /openEuler-22.03-LTS-REPO/openEuler-22.03-everything/ /openEuler-22.03-LTS-REPO/openEuler-22.03-everything/ └── Packages(2)生成 everything 源的 RPM 包元数据# 执行以下命令生成元数据 $ createrepo -v --workers 10 /openEuler-22.03-LTS-REPO/openEuler-22.03-everything # 查看生成元数据后的目录结构 $ tree -L 1 /openEuler-22.03-LTS-REPO/openEuler-22.03-everything/ /openEuler-22.03-LTS-REPO/openEuler-22.03-everything/ ├── Packages └── repodata # 查看生成的元数据文件 $ ls /openEuler-22.03-LTS-REPO/openEuler-22.03-everything/repodata 0079e1d3bd752a19486cb91269c98c8b5a6254d3ca13e5c0326e085561f1ed2a-other.sqlite.bz2 355628d38b0cd6163757264bc7971f3d86ff1d530a44c034786f3116b167f490-filelists.xml.gz 73565b368f50f6d2bb92543e2f7bcef4a9bc159ccdfbc728fc22e9b2ed5bb528-primary.xml.gz 7c20d73494e2525944a113b55983be13ba437e354da3e45f19f456b8f39457b4-other.xml.gz 9b353c421ef03be739e96d529e92393dfc4864205d974309a6af813e47893fff-filelists.sqlite.bz2 bd6c1976aae37a44ef7c7f9390c0321b4f7a27c4991e318f57b9c37016cb32fa-primary.sqlite.bz2 repomd.xml(3)创建软链接到 nginx 网页根目录# 创建 everything 源软链接到 nginx 网页根目录 $ ln -s /openEuler-22.03-LTS-REPO/openEuler-22.03-everything/ /usr/share/nginx/html/openEuler-22.03-LTS/everything/x86_643.1.5 同步 update 源(1)同步 update 源的 RPM 包到本地# 同步 update 源的 RPM 包到本地 $ dnf reposync -v --repoid=openEuler-22.03-update -p /openEuler-22.03-LTS-REPO # 同步完成后会在 /openEuler-22.03-LTS-REPO 目录创建一个名称同 repo name 的目录 $ ls /openEuler-22.03-LTS-REPO/ openEuler-22.03-update # 查看目录结构 $ tree -L 1 /openEuler-22.03-LTS-REPO/openEuler-22.03-update/ /openEuler-22.03-LTS-REPO/openEuler-22.03-update/ └── Packages(2)生成 update 源的 RPM 包元数据# 执行以下命令生成元数据 $ createrepo -v --workers 10 /openEuler-22.03-LTS-REPO/openEuler-22.03-update # 查看生成元数据后的目录结构 $ tree -L 1 /openEuler-22.03-LTS-REPO/openEuler-22.03-update /openEuler-22.03-LTS-REPO/openEuler-22.03-update ├── Packages └── repodata # 查看生成的元数据文件 $ ls /openEuler-22.03-LTS-REPO/openEuler-22.03-update/repodata 8943580f5aefe7f532fbbd9f19d771aaf9407a855b0acad33723007d8dde4199-primary.xml.gz ad1a113f7358bfebf9d13783d8fa8ce0a9b151725ecfc2da059226280422c30a-other.xml.gz bf573c34d9f77a76757a2a496b2c9ee671dddc81d660a95b063f8b81b8d7a4f9-filelists.sqlite.bz2 c6b747c4c6ee6cb6a44683b4a3636066cba5c9e573ea19ad95a5e315a9af1836-primary.sqlite.bz2 e152e3b11a7fcf011e16a27f7e6ba855ac12025b114ec5916e09d4edb0fa61e9-other.sqlite.bz2 f88eb68a9e41086c6b2de992367613c9b1e530bea82a73aa82e6faad6e5ed53d-filelists.xml.gz repomd.xml(3)创建软链接到 nginx 网页根目录# 创建 update 源软链接到 nginx 网页根目录 $ ln -s /openEuler-22.03-LTS-REPO/openEuler-22.03-update/ /usr/share/nginx/html/openEuler-22.03-LTS/update/x86_643.1.6 同步 EPOL 源(1)同步 EPOL 源的 RPM 包到本地# 同步 update 源的 RPM 包到本地 $ dnf reposync -v --repoid=openEuler-22.03-EPOL -p /openEuler-22.03-LTS-REPO # 同步完成后会在 /openEuler-22.03-LTS-REPO 目录创建一个名称同 repo name 的目录 $ ls /openEuler-22.03-LTS-REPO/ openEuler-22.03-EPOL # 查看目录结构 $ tree -L 1 /openEuler-22.03-LTS-REPO/openEuler-22.03-EPOL /openEuler-22.03-LTS-REPO/openEuler-22.03-EPOL/ └── Packages(2)生成 EPOL 源的 RPM 包元数据# 执行以下命令生成元数据 $ createrepo -v --workers 10 /openEuler-22.03-LTS-REPO/openEuler-22.03-EPOL # 查看生成元数据后的目录结构 $ tree -L 1 /openEuler-22.03-LTS-REPO/openEuler-22.03-EPOL /openEuler-22.03-LTS-REPO/openEuler-22.03-EPOL ├── Packages └── repodata # 查看生成的元数据文件 $ ls /openEuler-22.03-LTS-REPO/openEuler-22.03-EPOL/repodata 2d41ed62331b529104c7b04fd34680e8eeb8783e212e910e5230daaa66a900a4-filelists.sqlite.bz2 3445b86e5fd0157d0fd08aaf06cde6f1feca76517b574d8fdd3b40abe827b71e-other.xml.gz 709755e7d41e355645979f47b78155234bae9d50b2422105a4b03fca6ea93c83-filelists.xml.gz 70e673639de7efb802e65a54ce80e99c49ea93b1a8a4b4a676a47a91cadc99fa-primary.xml.gz 8c1cb6add3f18391a70436bed3bca18b9e0eac6861d8c5e2266c9952be3ea9f0-other.sqlite.bz2 bae172c52a64e4637d189780ff27d983e3c97bcbc17278f74afe0a23ab6e9ecd-primary.sqlite.bz2 repomd.xml(3)创建软链接到 nginx 网页根目录# 创建 EPOL 源软链接到 nginx 网页根目录 $ ln -s /openEuler-22.03-LTS-REPO/openEuler-22.03-EPOL/ /usr/share/nginx/html/openEuler-22.03-LTS/EPOL/main/x86_643.1.7 在前端界面查看 RPM 包使用 Windows 浏览器访问: http://192.168.255.221:8001,查看 RPM 包3.2 Client 端配置3.2.1 系统基本设置# 关闭防火墙,并停止开机自启 $ systemctl stop firewalld $ systemctl disable firewalld # 关闭 SELinux $ setenforce 03.2.2 配置 repo 源# 创建备份目录,将现有的 repo 源都移动到备份目录中 $ cd /etc/yum.repos.d/ $ mkdir bak $ mv ./* bak/ # 编写新的 repo 源,URL 地址指向局域网 repo 源服务器 cat > /etc/yum.repos.d/lan.repo <<EOF [openEuler-22.03-everything] name=openEuler-22.03-everything baseurl=http://192.168.255.221:8001/everything/x86_64/ enabled=1 gpgcheck=0 [openEuler-22.03-EPOL] name=openEuler-22.03-epol baseurl=http://192.168.255.221:8001/EPOL/main/x86_64/ enabled=1 gpgcheck=0 [openEuler-22.03-update] name=openEuler-22.03-update baseurl=http://192.168.255.221:8001/update/x86_64/ enabled=1 gpgcheck=0 EOF # 清空 yum 缓存 $ yum clean all # 重建 yum 缓存 $ yum makecache # 查看当前的 repo 源 $ yum repolist repo id repo name openEuler-22.03-EPOL openEuler-22.03-epol openEuler-22.03-everything openEuler-22.03-everything openEuler-22.03-update openEuler-22.03-update3.2.3 测试 repo 源# 随便搜索一个软件包 $ yum provides tree Last metadata expiration check: 0:08:11 ago on Wed 13 Dec 2023 04:36:36 PM CST. tree-1.8.0-2.oe2203.x86_64 : Tree file viewer tool Repo : openEuler-22.03-everything Matched from: Provide : tree = 1.8.0-2.oe2203 # 安装搜索的软件包 $ yum install -y tree4 使用 .iso 镜像搭建本地 repo 源4.1 基于 HTTP 协议搭建# 安装 httpd 服务及其他工具 $ yum install -y httpd createrepo # 修改配置文件,不显示默认网页 $ mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak $ sed -i '/^\s*DirectoryIndex/ s/index.html//' /etc/httpd/conf/httpd.conf # 挂载 everything 镜像 $ mount /dev/sr0 /mnt/ # 创建 repo 目录 $ mkdir -p /var/www/html/openEuler-LTS-SP1/Package # 从镜像中复制软件包到 repo 目录 $ cp /mnt/Packages/* /var/www/html/openEuler-LTS-SP1/Package/ # 生成元数据信息 $ createrepo -v --workers 20 /var/www/html/openEuler-LTS-SP1/ # 修改目录及文件权限 $ chmod 755 /var/www/html/openEuler-LTS-SP1/Package/ $ chmod 755 /var/www/html/openEuler-LTS-SP1/repodata/ $ chmod 644 /var/www/html/openEuler-LTS-SP1/Package/* $ chmod 644 /var/www/html/openEuler-LTS-SP1/repodata/* # 启动 httpd 服务 $ systemctl start httpd客户端编写 repo 文件:# 编写 repo 文件 $ cat > /etc/yum.repos.d/local.repo <<EOF [local-repo] name=local-repo baseurl=http://192.168.230.201/openEuler-LTS-SP1/ enabled=1 gpgcheck=0 EOF4.2 基于 FTP 协议搭建# 安装 vsftpd 服务及其他工具 $ yum install -y vsftpd createrepo # 配置 vsftpd 服务,允许匿名用户登录 $ sed -i '/^anonymous_enable/c anonymous_enable=YES' /etc/vsftpd/vsftpd.conf # 挂载 everything 镜像 $ mount /dev/sr0 /mnt/ # 创建 repo 目录 $ mkdir -p /var/ftp/pub/openEuler-22.03-LTS-SP1/Packages # 从镜像中复制软件包到 repo 目录 $ cp /mnt/Packages/* /var/ftp/pub/openEuler-22.03-LTS-SP1/Packages/ # 生成元数据信息 $ createrepo -v --workers 20 /var/ftp/pub/openEuler-22.03-LTS-SP1/ # 启动 vsftpd 服务 $ systemctl start vsftpd客户端编写 repo 文件:# 编写 repo 文件 $ cat > /etc/yum.repos.d/local.repo <<EOF [local-repo] name=local-repo baseurl=ftp://192.168.230.201/pub/openEuler-22.03-LTS-SP1/ enabled=1 gpgcheck=0 EOF
2024年08月14日
269 阅读
0 评论
0 点赞
2024-08-12
openEuler 操作系统用户权限管理——sudo 权限的授予与限制案例
说明:本文旨在分享记录在 openEuler 操作系统中,如何对普通用户进行权限授予与限制所有操作演示基于 openEuler 22.03 LTS SP1 版本汇总多种权限授予与限制的案例1 sudo 权限本节内容摘自官方文档:管理用户和用户组 (openeuler.org)使用 sudo 命令可以允许普通用户执行管理员帐户才能执行的命令sudo 命令允许已经在 /etc/sudoers 文件中指定的用户运行管理员帐户命令。例如,一个已经获得许可的普通用户可以运行如下命令:sudo /usr/sbin/useradd newuserl/etc/sudoers 的配置行如下所示:空行或注释行(以 # 字符打头):无具体功能的行可选的主机别名行:用来创建主机列表的简称。必须以 Host_Alias 关键词开头,列表中的主机必须用逗号(,)隔开,如:Host_Alias FILESERVERS = fs1, fs2可选的用户别名行:用来创建用户列表的简称。用户别名行必须以 User_Alias 关键词开头,列表中的用户名必须以逗号(,)隔开。其格式同主机别名行:User_Alias ADMINS = jsmith, mikem可选的命令别名行:用来创建命令列表的简称。必须以 Cmnd_Alias 开头,列表中的命令必须用逗号(,)隔开:Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall可选的运行方式别名行:用来创建用户列表的简称。不同的是,使用这样的别名可以告诉 sudo 程序以列表中某一用户的身份来运行程序必要的用户访问说明行:user host=[ run as user ] command list以上字段的含义及说明如下表所示:字段含义说明user要授予 sudo 权限的用户指定一个真正的用户名或定义过的别名host该用户可以在哪个主机上执行命令指定一个真正的主机名或者定义过的主机别名run as user该用户以什么身份执行命令默认情况下,sudo 执行的所有命令都是以 root 身份执行command list该用户可以执行哪些命令可以是以逗号(,)分隔的命令列表,也可以是一个已经定义过的别名说明:可以在一行定义多个别名,中间用冒号 (:) 隔开可在命令或命令别名之前加上感叹号 (!),使该命令或命令别名无效有两个关键词:ALL 和NOPASSWD。ALL 意味着“所有”(所有文件、所有主机或所有命令),NOPASSWD 意味着不用密码通过修改用户访问,将普通用户的访问权限修改为同 root 一样,则可以给普通用户分配特权对于 /etc/sudoers 文件的修改,推荐使用 visudo 命令,能够在保存时检查语法是否有误/etc/sudoers 文件预先添加了一个用户(root)和一个用户组(wheel):## Allow root to run any commands anywhere root ALL=(ALL) ALL ## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL基于以上知识,可以实现对普通用户各种各样的授权与限制2 案例汇总2.1 案例一目标:授予普通用户创建用户,并修改用户密码的权限,但是禁止该用户修改 root 用户密码在 /etc/sudoers 文件中添加以下内容:user1 ALL=(ALL) /usr/sbin/useradd, /usr/bin/passwd, !/usr/bin/passwd "", !/usr/bin/passwd root配置说明:/usr/bin/useradd :允许 user1 用户执行 useradd USER 命令创建普通用户/usr/bin/passwd :允许 user1 用户执行 passwd USER 命令修改用户密码!/usr/bin/passwd root :禁止 user1 用户执行 passwd root 命令修改 root 用户密码!/usr/bin/passwd "" :禁止 user1 用户执行 passwd 命令修改 root 用户密码,因为 passwd 命令后边为空则默认为 root 用户效果演示:2.2 案例二目标:授予普通用户执行任何命令的权限方法一:可以将普通用户加入 wheel 组$ usermod -a -G wheel user1 $ id user1 uid=1000(user1) gid=1000(user1) groups=1000(user1),10(wheel)方法二:在 /etc/sudoers 文件添加以下内容user1 ALL=(ALL) ALL这两种方法的授权结果是有差异的,例如使用 su 命令的权限不同:将普通用户加入 wheel 组后,在该用户密码强度足够的前提下,该用户可以直接使用 su - 或 su - root 命令切换到 root 用户,而不必使用 sudo su - 或 sudo su - root 命令直接在 /etc/sudoers 文件中授予普通用户执行所有命令的权限后,该用户并不能直接使用 su - 或 su - root 命令切换到 root 用户,而必须要使用 sudo su - 或 sudo su - root 命令之所以出现这两种差异,是因为 /etc/pam.d/su 文件中有以下配置:auth required pam_wheel.so use_uid这一行配置的意思是:只允许只允许 root 用户和 wheel 群组的帐户使用 su 命令,限制其他帐户使用。openEuler 默认开启此配置,因此导致普通用户即使拥有执行所有命令的权限,也不能使用 su 命令2.3 案例三目标:授予普通用户执行任何命令的权限,但是禁止该用户切换到 root 用户在 /etc/sudoers 文件中添加以下内容:user1 ALL=(ALL) ALL, !/usr/bin/su - root, !/usr/bin/su - , !/usr/bin/bash配置说明:ALL :允许 user1 用户执行所有命令!/usr/bin/su - root :禁止 user1 用户执行 sudo su - root 命令切换到 root 用户!/usr/bin/su - :禁止 user1 用户执行 sudo su - 命令切换到 root 用户,因为 su - 命令后边为空则默认为 root 用户!/usr/bin/bash :禁止 user1 用户执行 sudo -i 、 sudo -i root 、 sudo /bin/bash 等方式切换到 root 用户效果演示:
2024年08月12日
426 阅读
0 评论
0 点赞
2024-03-30
xfs、ext4 文件系统都支持 LVM 逻辑卷缩容吗?如何对根分区缩容?
1 文件系统对缩容有无限制此节主要验证当前主流的 xfs 文件系统和 ext4 文件系统是否都支持 LVM 逻辑卷的缩容:验证按照目前众所周知的操作规范,缩容前先要卸载对应分区基于 openEuler 22.03 LTS SP1 操作系统进行验证(1)准备工作创建大小约为 25G 的卷组,后续基于此卷组创建逻辑卷# 创建大小约为 25G 的卷组(VG) $ vgcreate vg0 /dev/sdb Physical volume "/dev/sdb" successfully created. Volume group "vg0" successfully created # 查看创建的 VG 的详细信息 $ vgdisplay vg0 --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size <25.00 GiB PE Size 4.00 MiB Total PE 6399 Alloc PE / Size 0 / 0 Free PE / Size 6399 / <25.00 GiB VG UUID PhStrz-y8do-kZAl-a9hq-dkdj-mqZl-TTqDMX1.1 xfs 文件系统 LVM 逻辑卷缩容(1)创建大小约为 10G 的逻辑卷,并格式化为 xfs 文件系统,进行挂载测试# 创建大小为 10G 的逻辑卷 lv_xfs $ lvcreate -L +10G -n lv_xfs vg0 Logical volume "lv_xfs" created. # 查看创建的逻辑卷的详细信息 $ lvdisplay /dev/vg0/lv_xfs --- Logical volume --- LV Path /dev/vg0/lv_xfs LV Name lv_xfs VG Name vg0 LV UUID W5YEDp-9kx3-JChe-MxLJ-1P06-yfF3-KTtlzD LV Write Access read/write LV Creation host, time localhost.localdomain, 2024-03-13 09:20:51 +0800 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3 # 将此逻辑卷格式化为 xfs 文件系统 $ mkfs.xfs /dev/vg0/lv_xfs meta-data=/dev/vg0/lv_xfs isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 bigtime=1 inobtcount=1 data = bsize=4096 blocks=2621440, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 # 挂载此逻辑卷,并查看挂载情况 $ mkdir /lv_xfs $ mount /dev/vg0/lv_xfs /lv_xfs/ $ df -Th /dev/vg0/lv_xfs Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg0-lv_xfs xfs 10G 104M 9.9G 2% /lv_xfs(2)将以上逻辑卷缩容至 5G,查看分区是否正常# 卸载分区挂载 $ umount /dev/vg0/lv_xfs # 将逻辑卷缩容 5G $ lvreduce -L 5G /dev/vg0/lv_xfs WARNING: Reducing active logical volume to 5.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg0/lv_xfs? [y/n]: y Size of logical volume vg0/lv_xfs changed from 10.00 GiB (2560 extents) to 5.00 GiB (1280 extents). Logical volume vg0/lv_xfs successfully resized. # 重新格式化,出现报错 $ xfs_growfs /dev/vg0/lv_xfs xfs_growfs: /dev/vg0/lv_xfs is not a mounted XFS filesystem # 强制挂载,出现报错 $ mount /dev/vg0/lv_xfs /lv_xfs/ mount: /lv_xfs: can't read superblock on /dev/mapper/vg0-lv_xfs.出现报错,不能重新格式化,不能强制挂载,说明 xfs 文件系统的缩容存在问题如果使用 mkfs.xfs -f 命令进行强制格式化,则可以正常缩容,但是分区上的所有数据也会丢失,这种操作显然是不行的# 使用 mkfs.xfs -f 命令进行强制格式化 $ mkfs.xfs -f /dev/vg0/lv_xfs meta-data=/dev/vg0/lv_xfs isize=512 agcount=4, agsize=327680 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 bigtime=1 inobtcount=1 data = bsize=4096 blocks=1310720, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 # 挂载,并查看分区大小 $ mount /dev/vg0/lv_xfs /lv_xfs/ $ df -Th /dev/vg0/lv_xfs Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg0-lv_xfs xfs 5.0G 68M 5.0G 2% /lv_xfs(3)结论xfs 文件系统不能进行 LVM 逻辑卷的缩容操作1.2 ext4 文件系统 LVM 逻辑卷缩容(1)创建大小约为 10G 的逻辑卷,并格式化为 ext4 文件系统,进行挂载测试# 创建大小为 10G 的逻辑卷 lv_xfs $ lvcreate -L +10G -n lv_ext4 vg0 Logical volume "lv_ext4" created. # 查看创建的逻辑卷的详细信息 $ lvdisplay /dev/vg0/lv_ext4 --- Logical volume --- LV Path /dev/vg0/lv_ext4 LV Name lv_ext4 VG Name vg0 LV UUID 0yVn8J-OiP7-M0SB-GWZG-qHTa-YOC4-k8JVEK LV Write Access read/write LV Creation host, time localhost.localdomain, 2024-03-13 10:36:01 +0800 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:4 # 将此逻辑卷格式化为 xfs 文件系统 $ mkfs.ext4 /dev/vg0/lv_ext4 mke2fs 1.46.4 (18-Aug-2021) Creating filesystem with 2621440 4k blocks and 655360 inodes Filesystem UUID: 3794e4d4-4cbf-4aaa-921c-1e7159edef07 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done # 挂载此逻辑卷,并查看挂载情况 $ mkdir /lv_ext4 $ mount /dev/vg0/lv_ext4 /lv_ext4/ $ df -Th /dev/vg0/lv_ext4 Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg0-lv_ext4 ext4 9.8G 24K 9.3G 1% /lv_ext4(2)将以上逻辑卷缩容至 5G,查看分区是否正常# 卸载分区挂载 $ umount /dev/vg0/lv_ext4 # 进行磁盘检查(必须步骤) $ e2fsck -f /dev/vg0/lv_ext4 e2fsck 1.46.4 (18-Aug-2021) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg0/lv_ext4: 11/655360 files (0.0% non-contiguous), 66753/2621440 blocks # 缩容文件系统 $ resize2fs /dev/vg0/lv_ext4 5G resize2fs 1.46.4 (18-Aug-2021) Resizing the filesystem on /dev/vg0/lv_ext4 to 1310720 (4k) blocks. The filesystem on /dev/vg0/lv_ext4 is now 1310720 (4k) blocks long. # 回收逻辑卷空闲空间 $ lvreduce -L 5G /dev/vg0/lv_ext4 WARNING: Reducing active logical volume to 5.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg0/lv_ext4? [y/n]: y Size of logical volume vg0/lv_ext4 changed from 10.00 GiB (2560 extents) to 5.00 GiB (1280 extents). Logical volume vg0/lv_ext4 successfully resized. # 重新挂载,并查看挂载情况 $ mount /dev/vg0/lv_ext4 /lv_ext4/ $ df -Th /dev/vg0/lv_ext4 Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg0-lv_ext4 ext4 4.9G 24K 4.6G 1% /lv_ext4(3)结论ext4 文件系统可以进行 LVM 逻辑卷的缩容操作1.3 结论经过以上测试,得出结论:xfs 文件系统不能进行 LVM 逻辑卷的缩容操作,ext4 文件系统可以进行 LVM 逻辑卷的缩容操作另外,也可以通过另外一种缩容方式明确得出这一结论。即使用 lvreduce 命令的 -r 参数,此参数表示在缩容时同时使用 fsadm 调整底层文件系统的大小:$ man lvreduce ...... -r|--resizefs Resize underlying filesystem together with the LV using fsadm(8). ......(1)xfs 文件系统 LVM 逻辑卷缩容# 执行以下命令对 xfs 文件系统的 LVM 逻辑卷缩容 $ lvreduce -r -L 5G /dev/vg0/lv_xfs输出内容如下图所示:报错显示:Xfs filesystem shrinking is unsuppored(Xfs 文件系统收缩不被支持)(2)ext4 文件系统 LVM 逻辑卷缩容# 执行以下命令对 ext4 文件系统的 LVM 逻辑卷缩容 $ lvreduce -r -L 5G /dev/vg0/lv_ext4输出内容如下图所示: 信息显示逻辑卷缩容成功2 能否挂载状态缩容现有处于挂载状态的文件系统为 ext4 的逻辑卷:直接对其进行缩容操作,命令执行过程中会询问是否卸载分区:缩容后,会自动挂载分区:综上,不能对处于挂载状态的逻辑卷分区进行缩容操作,工具会自动卸载、挂载3 如何对根分区进行缩容由 2.2 得出结论,在对逻辑卷缩容时必须要先卸载分区。正常系统中,根分区显然是不能卸载的,那么想对根分区进行缩容该如何操作呢?进单用户模式进行操作,发现单用户模式并没有 lvm 相关命令正确的根分区缩容操作如下:(1)使用光盘进入救援模式,选择 “ 3) Skip to shell ”,这样可以不去挂载 /mnt/sysroot 或 /mnt/sysimage(2)执行 lsblk 命令查看逻辑卷是否处于激活状态,即是否有 /dev/mapper/... 相关路径,若没有则需要先激活逻辑卷(3)执行 vgchange -ay 命令激活所有卷组及其逻辑卷,之后再次执行 lsblk 命令查看逻辑卷路径(4)执行 lvreduce -r -L -20G /dev/mapper/openeuler-root 命令进行缩容操作,并验证缩容结果(5)退出救援模式,进入系统,验证缩容结果及系统有无异常至此,根分区成功缩容!
2024年03月30日
105 阅读
0 评论
0 点赞
2023-08-20
如何免费签发 HTTPS 证书
1 背景在网站服务中,使用 HTTPS 协议可以有效提高安全性,但是需要进行证书的签发。对于大型的网站服务是非常容易的,但对于如个人博客网站等,需要承担一定的证书签发费用。本文主要提供两种免费签发 HTTPS 证书的方法,供大家学习交流。2 使用 certbot 生成证书2.1 生成证书(1)安装 certbot# 安装 epel-release 源 $ yum -y install epel-release # 安装 certbot $ yum -y install certbot(2)生成泛域名 *.ecsy.top 证书# 执行以下命令 $ certbot certonly -d *.ecsy.top --manual --preferred-challenges dns 参数释义: -d 指定您的泛域名 --manual 表示手动生成证书 --pfeferred-challeges dns 使用 DNS 验证域名归属(3)此处输入您的邮箱地址Saving debug log to /var/log/letsencrypt/letsencrypt.log Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): xxxxxx@126.com(4)输入 Y 同意Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must agree in order to register with the ACME server. Do you agree? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y(5)输入 N 不允许共享电子邮件地址Would you be willing, once your first certificate is successfully issued, to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: N(6)根据提示进行域名归属认证Account registered. Requesting a certificate for *.ecsy.top - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name: _acme-challenge.ecsy.top. with the following value: aQyGqKJecDh9ud-TuQlH-N70DW_RF6KtBRx_EZ0vhLI Before continuing, verify the TXT record has been deployed. Depending on the DNS provider, this may take some time, from a few seconds to multiple minutes. You can check if it has finished deploying with aid of online tools, such as the Google Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.ecsy.top. Look for one or more bolded line(s) below the line ';ANSWER'. It should show the value(s) you've just added. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue根据返回信息提示,在您的域名提供商控制台,添加一条 DNS TXT 解析记录:注意:添加 DNS 解析记录后,需要等待一段时间进行同步,才能解析成功,可以使用 nslookup -q=TXT _acme-challenge.test.com. 尝试解析,或在域名提供商控制台进行生效检测。检测成功后,按 Enter 键继续。(7)成功签发证书Successfully received certificate. Certificate is saved at: /etc/letsencrypt/live/ecsy.top/fullchain.pem Key is saved at: /etc/letsencrypt/live/ecsy.top/privkey.pem This certificate expires on 2024-01-06. These files will be updated when the certificate renews.# 查看证书文件 $ ls /etc/letsencrypt/live/ecsy.top/ fullchain.pem # 证书 privkey.pem # 私钥2.2 将证书添加到 Web 服务配置文件中# 此处使用 nginx $ vim /etc/nginx/nginx.conf server { listen 443 ssl http2; ssl_certificate "/etc/letsencrypt/live/ecsy.top/fullchain.pem"; ssl_certificate_key "/etc/letsencrypt/live/ecsy.top/privkey.pem"; ...... }2.3 常见问题2.3.1 仍然提示连接不安全在配置好证书后访问网站时,可能仍然出现连接不安全的提示,如下图所示:原因已经说的非常清楚了,此处我使用 escy.top 这个域名来访问,并没有使用泛域名,因此提示:“此服务器无法证明它是 ecsy.top;它的安全证书来自 *.ecsy.top。这可能是由错误配置或者有攻击者截获你的连接而导致的。”为此,我们需要再次为 ecsy.top 生成证书,重新执行上文所述的证书生成步骤并配置到 Web 服务中即可,此时的生成证书命令将变为:# 执行以下命令 $ certbot certonly -d ecsy.top --manual --preferred-challenges dns2.3.2 证书有效期证书有效期为 3 个月,证书到期前您可以手动按以上步骤重新签发,也可以使用官方提供的自动续期方案。NEXT STEPS: - This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.3 使用图形化界面生成证书如果您觉得使用 certbot 命令行工具生成证书比较繁琐,且不直观,可以使用网页来生成证书。比较推荐这个网站:来此加密 - Let's Encrypt 在线免费申请SSL证书 (osfipin.com):此网站有如下特点:提供了直观的操作界面,引导流程也非常详细易懂。其原理与 certbot 命令行工具类似,都需要使用 DNS TXT 记录来验证域名的归属。在证书生成后,可以进行下载使用。证书有效期仍然是 3 个月,可以选择到期前通过短信提醒,重新续期。可以在账户中方便管理自己的证书。由于操作难度不大,在此不作流程演示。
2023年08月20日
57 阅读
0 评论
3 点赞
1
2