首页
Search
1
安装docker时报错container-selinux >= 2:2.74
126 阅读
2
rsync命令(可替代rm删除巨量文件)
102 阅读
3
docker 镜像加速器配置,daemon.json文件详解
91 阅读
4
使用国内镜像地址拉取k8s安装需要的images
79 阅读
5
Redhat 8版本安装ansible步骤
75 阅读
运维
自动化运维
数据库
容器与k8s
环境
云计算
脚本
登录
Search
标签搜索
命令
nginx
Mingrui
累计撰写
64
篇文章
累计收到
0
条评论
首页
栏目
运维
自动化运维
数据库
容器与k8s
环境
云计算
脚本
页面
搜索到
56
篇与
的结果
2025-03-26
containerd安装与配置
新版本的kubernetes不在使用docker作为容器运行时,而是直接使用containerd。因此在安装kubernetes时需要安装containerd。安装安装containerd非常简单,配置好yum仓库,一条yum命令即可安装成功。#containerd网络仓库配置 dnf install -y yum-utils yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 添加仓库自:https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum -y install containerd安装完成之后需要修改配置文件。containerd安装完成后会默认在/etc/containerd/目录下生成一个配置文件config.toml,但是该文件缺少很多信息,因此我们需要重新生成一个配置文件,然后对新生成的配置文件进行修改。#生成新配置文件 containerd config default > /etc/containerd/config.toml修改配置信息修改Cgroup为systemd在[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] 下找到SystemdCgroup,将false改为true修改sandbox镜像地址把配置文件中的 sandbox_image = "registry.k8s.io/pause:3.6" 改为阿里云的地址 sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.8"sandbox_image 是容器运行时(如 containerd、CRI-O 等)或容器编排系统(如 Kubernetes)中一个关键配置参数,用于指定 沙箱容器(Sandbox Container) 的基础镜像。沙箱容器是一个特殊的容器,用于为其他容器提供共享的底层环境(如网络、IPC 命名空间等)。例如:在 Kubernetes 中,每个 Pod 的第一个容器就是沙箱容器(称为 pause 容器),它负责维持 Pod 的网络命名空间。配置镜像加速# 修改配置文件,添加配置镜像加速相关信息的配置文件的路径 vim /etc/containerd/config.toml [plugins."io.containerd.grpc.v1.cri".registry] config_path = "/etc/containerd/certs.d" # 创建文件夹 mkdir -p /etc/containerd/certs.d/docker.io #创建配置文件 cat > /etc/containerd/certs.d/docker.io/hosts.toml << EOF server = "https://docker.io" [host."https://docker.1ms.run"] capabilities = ["pull", "resolve"] EOF说明:该配置方式对crictl命令有效,对ctr命令无效,使用ctr下载镜像时,需要指定镜像的地址和版本,如: ctr --debug=true image pull docker.1ms.run/busybox:latest{alert type="info"}特别提醒:在/etc/containerd/certs.d目录下,每个镜像加速地址都要放在单独的文件夹中,且这个文件夹必须以.io结尾,镜像加速地址的文件名称必须为hosts.toml{/alert}tree containerd/ containerd/ ├── certs.d │ └── docker.io │ └── hosts.toml └── config.toml 2 directories, 2 files 安装crictl工具#下载源码包 wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.29.0/crictl-v1.29.0-linux-amd64.tar.gz #解压缩 tar zxvf crictl-v1.29.0-linux-amd64.tar.gz -C /usr/local/bin # -C:指定解压缩后文件存放的位置修改配置文件cat > /etc/crictl.yaml <<EOF runtime-endpoint: unix:///run/containerd/containerd.sock image-endpoint: unix:///run/containerd/containerd.sock timeout: 10 debug: false EOF # 重启containerd systemctl restart containerd或者通过命令行工具修改crictl config runtime-endpoint unix:///run/containerd/containerd.sock crictl config image-endpoint unix:///run/containerd/containerd.sock安装cni插件在没有安装cni插件时,containerd会报错缺少cni插件。#下载安装包 wget https://github.com/containernetworking/plugins/releases/download/v1.4.0/cni-plugins-linux-amd64-v1.4.0.tgz #创建目录 mkdir -p /opt/cni/bin/ #解压缩 tar xzvf cni-plugins-linux-amd64-v1.4.0.tgz -C /opt/cni/bin/修改配置文件mkdir -p /etc/cni/net.d/ cat > /etc/cni/net.d/10-containerd-net.conflist <<EOF { "cniVersion": "1.0.0", "name": "containerd-net", "plugins": [ { "type": "bridge", "bridge": "cni0", "isGateway": true, "ipMasq": true, "promiscMode": true, "ipam": { "type": "host-local", "ranges": [ [{ "subnet": "10.88.0.0/16" }], [{ "subnet": "2001:4860:4860::/64" }] ], "routes": [ { "dst": "0.0.0.0/0" }, { "dst": "::/0" } ] } }, { "type": "portmap", "capabilities": {"portMappings": true} } ] } EOF [root@rocky9 ~]# systemctl restart containerd [root@rocky9 ~]# crictl info …… #重启containerd即可下载镜像示例[root@node-001 docker.io]# crictl pull httpd Image is up to date for sha256:83d938198316505b3aebd52bed1e54e5f2a49591cc41e09a30f480e5c00ea0cf [root@node-001 docker.io]# crictl pull nginx Image is up to date for sha256:53a18edff8091d5faff1e42b4d885bc5f0f897873b0b8f0ace236cd5930819b0 [root@node-001 docker.io]# crictl pull bitnami/php-fpm Image is up to date for sha256:0fdfdfd1cd46d5ef32ed47af20e8ae3ad58b0f4d62516519994bf74b8f6611a5 [root@node-001 docker.io]# crictl images ls IMAGE TAG IMAGE ID SIZE docker.1ms.run/calico/cni v3.25.0 d70a5947d57e5 88MB docker.1ms.run/calico/node v3.25.0 08616d26b8e74 87.2MB docker.io/bitnami/php-fpm latest 0fdfdfd1cd46d 115MB docker.io/library/httpd latest 83d9381983165 58.5MB docker.io/library/nginx latest 53a18edff8091 72.2MB registry.aliyuncs.com/google_containers/kube-proxy v1.28.0 ea1030da44aa1 24.6MB registry.aliyuncs.com/google_containers/pause 3.9 e6f1816883972 322kB
2025年03月26日
66 阅读
0 评论
0 点赞
2025-03-06
docker search命令提示i/o timeout的解决方案
配置好docker的镜像加速器后,会发现一个奇怪的现象。如果使用docker search命令搜索某个容器,会得到i/o timeout 的错误信息,但是用docker pull命令下载镜像时,却可以下载。示例[root@10-60-14-211 lnmp]# docker search nginx Error response from daemon: Get "https://index.docker.io/v1/search?q=nginx&n=25": dial tcp 69.30.25.21:443: i/o timeout [root@10-60-14-211 ~]# docker pull nginx:1.27.4-perl 1.27.4-perl: Pulling from library/nginx 7cf63256a31a: Already exists bf9acace214a: Pull complete 513c3649bb14: Pull complete d014f92d532d: Pull complete 9dd21ad5a4a6: Pull complete 943ea0f0c2e4: Pull complete 103f50cb3e9f: Pull complete d8dfdc7acfb3: Pull complete Digest: sha256:74edc8744a1080ccd9f9719e51e7d885b65dedaf2164a246f1cbd328f20f5d2e Status: Downloaded newer image for nginx:1.27.4-perl docker.io/library/nginx:1.27.4-perl原因解读docker search:直接查询Docker Hub API (https://index.docker.io/v1),而不是通过配置的镜像源。docker pull:优先使用配置的镜像源,如果镜像源失败,尝试从Docker Hub拉取。这种差异的原因在于Docker的设计理念:搜索功能主要面向Docker Hub官方仓库,而镜像源主要用于拉取(docker pull)操作。解决方案在搜索镜像时加上镜像加速器的地址。[root@10-60-14-211 lnmp]# docker search 1ms.run/nginx NAME DESCRIPTION STARS OFFICIAL nginx Official build of Nginx. 20633 [OK] nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 47 nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 100 nginx/unit This repository is retired, use the Docker o… 65 nginx/nginx-ingress-operator NGINX Ingress Operator for NGINX and NGINX P… 2 nginx/nginx-quic-qns NGINX QUIC interop 1 nginx/unit-preview Unit preview features 0 nginx/nginxaas-loadbalancer-kubernetes 0 bitnami/nginx Bitnami container image for NGINX 196 ubuntu/nginx Nginx, a high-performance reverse proxy & we… 127 bitnamicharts/nginx Bitnami Helm chart for NGINX Open Source 0 rancher/nginx 2 kasmweb/nginx An Nginx image based off nginx:alpine and in… 8 linuxserver/nginx An Nginx container, brought to you by LinuxS… 224 redash/nginx Pre-configured nginx to proxy linked contain… 3 dtagdevsec/nginx T-Pot Nginx 0 paketobuildpacks/nginx 0 vmware/nginx 2 chainguard/nginx Build, ship and run secure software with Cha… 4 gluufederation/nginx A customized NGINX image containing a consu… 1 droidwiki/nginx 0 intel/nginx 0 circleci/nginx This image is for internal use 2 corpusops/nginx https://github.com/corpusops/docker-images/ 1 antrea/nginx Nginx server used for Antrea e2e testing 0
2025年03月06日
68 阅读
0 评论
0 点赞
2025-03-06
php容器的时区设置问题
{callout color="#f0ad4e"}背景说明:如今国内开源可用的docker镜像站越发稀少,很多镜像站关闭或不在提供服务。而搭建一个网站只用到少数的几个容器如nginx、php-fpm、mysql,没必要浪费资源买一台香港服务器去拉取这些镜像。解决办法是使用了目前还算稳定的 毫秒镜像 提供的镜像服务。 在1ms.run上搜索php-fpm容器的最新版本时,发现没有官方版本,于是使用了bitnami开源组织上传的镜像bitnami/php-fpm:latest。{/callout}在bitnami提供的php-fpm镜像中,容器使用的是UTC时间,也就是协调世界时(全球时间的基准),但我们使用的CST时区(UTC+8),这里就会出现一个问题:博客的发布时间与我们所处的时区有8小时的差距。因此需要修改php-fpm的默认时区设置。进入php-fpm容器查看时区设置情况#创建一个临时容器 docker run -itd --rm docker.1ms.run/bitnami/php-fpm #进入容器查看时区设置 root@f7f574667670:/app# echo $TZ root@f7f574667670:/app# date Thu Mar 6 01:24:24 UTC 2025 #发现容器使用的是UTC时间,且没有设置TZ环境变量第一个思路,修改compose文件php-fpm容器的环境变量,设置TZ的值为Asia/Shanghaivim compose.yaml …… php8.2: container_name: php8.4 image: docker.1ms.run/bitnami/php-fpm:latest environment: - TZ=Asia/Shanghai volumes: ……为了方便验证,不用每次都去容器里面进行查看时区情况,让deepseek写了一个简单的php脚本,只要浏览器访问这个脚步就可以得到容器的时区信息。<?php // 获取当前时间和时区 $current_time = date('Y-m-d H:i:s'); // 格式化当前时间 $current_timezone = date_default_timezone_get(); // 获取当前时区 // 输出结果 echo "当前时间:$current_time\n"; echo "当前时区:$current_timezone\n"; ?> 修改完配置信息,使用浏览器验证时发现php-fpm返回的仍然是UTC时间,问题出在哪里?再次进入php容器,查看环境变量设置是否生效root@f7f574667670:/app# echo $TZ Asia/Shanghai这里发现我们设置的环境变量是生效了的,但是php-fpm返回的时间却又是UTC的,那么下一步我们就去php的配置文件中查看有没有相关设置。修改php配置,使时区设置生效查看php.ini文件时,可以发现如下默认配置项。[Date]; Defines the default timezone used by the date functions; http://php.net/date.timezone;date.timezone = UTC这里可以看到默认的时区设置,以及这个时区设置被用于date函数。因此这里的设置优先级高,可以影响到php中时间类函数获取的值。#使用php --ini命令可快速获取php配置文件的位置 #查找配置信息中含有timezone字段的配置文件 root@f7f574667670:/app# find / -maxdepth 8 -name '*.conf' -o -name '*.ini' | xargs grep timezone /opt/bitnami/php/etc/php.ini:; Defines the default timezone used by the date functions /opt/bitnami/php/etc/php.ini:; https://php.net/date.timezone /opt/bitnami/php/etc/php.ini:date.timezone = UTC /opt/bitnami/php/lib/php.ini:; Defines the default timezone used by the date functions /opt/bitnami/php/lib/php.ini:; https://php.net/date.timezone /opt/bitnami/php/lib/php.ini:date.timezone = UTC这里发现在php.ini中有一条生效的配置信息:date.timezone = UTC修改这个配置文件,把UTC修改成我们需要的时区。这里需要注意的是,如果直接把UTC改为CST,php会报错。#直接修改为CST sed -i /^date\.timezone/s/UTC/CST/ /opt/bitnami/php/lib/php.ini #让php重新加载配置 kill -USR2 $(pgrep php-fpm) #查看时区信息 php -r 'echo date_default_timezone_get();' PHP Warning: PHP Startup: Invalid date.timezone value 'CST', using 'UTC' instead in Unknown on line 0重新修改配置文件,把CST改为"Asia/Shanghai"sed -i '/^date\.timezone/s/CST/\"Asia\/Shanghai\"/' /opt/bitnami/php/lib/php.ini 或 sed -i /^date\.timezone/s%CST%\"Asia/Shanghai\"% /opt/bitnami/php/lib/php.ini #重新加载配置文件 root@f7f574667670:/app# kill -USR2 $(pgrep php-fpm) root@f7f574667670:/app# php -r 'echo date_default_timezone_get();' Asia/Shanghairoot@f7f574667670:/app# root@f7f574667670:/app# php -r "echo date('Y-m-d H:i:s');" 2025-03-06 10:44:58root@f7f574667670:/app#把php.ini文件拷贝出来,在compose文件中写入映射关系,重启php容器即可。{dotted startColor="#ff6c6c" endColor="#1989fa"/}关于php.ini-production和php.ini-development:这是php给的两个初始配置的模版,区别如下:开发环境:追求调试便利性,牺牲部分安全性。生产环境:追求安全与性能,牺牲调试信息。始终根据实际需求调整配置,两个模板文件只是起点。配置项php.ini-developmentphp.ini-production目标场景本地开发、调试环境线上生产环境错误报告显示所有错误(方便调试)隐藏错误(避免信息泄露)性能优化默认配置,无激进优化启用 opcache 等性能优化日志记录可选开启详细日志强制记录错误到日志文件安全限制较为宽松严格限制(如文件上传、执行权限)主要区别项目参数名称developmentproduction说明zend.exception_ignore_argsOffOn开启后,异常堆栈跟踪中不再显示参数的具体值,仅保留参数的类型和数量zend.exception_string_param_max_len150控制异常堆栈信息中 字符串类型参数的最大显示长度error_reportingE_ALLE_ALL & ~E_DEPRECATED前面报告所有错误,后面忽略部分警告display_errorsOnOff是否直接在页面上显示错误display_startup_errorsOnOff是否显示PHP启动过程中发生的错误mysqlnd.collect_memory_statisticsOnOff启用或禁用统计 MySQL 操作相关的内存使用数据zend.assertions1-1启用或禁用断言注:1 断言生效,检查条件并触发错误(如条件不满足)。0 生成断言代码,但不执行检查(类似注释,无性能损耗)。-1 不生成断言代码(完全忽略 assert(),性能最优,生产环境推荐)。断言(Assertion) 是开发阶段用于验证代码逻辑的调试工具
2025年03月06日
63 阅读
0 评论
0 点赞
2025-03-03
nginx根据php监听端口号不同分配不同版版的php-fpm服务
通过给两个php-fpm服务配置不同的监听端口号,实现了一个nginx与两个php-fpm服务的同时通信。
2025年03月03日
58 阅读
0 评论
0 点赞
2024-09-27
find命令详解
find命令可以找出符合要求的所有文件并执行额外的命令。find会遍历文件系统,将找到的文件名交给谓词测试。如果谓词返回真,就通过。如果谓词返回假,则不再继续往下进行,会接着处理下一个文件名。谓词:find命令的选项看起来像是简短的单词,事实上它们是find命令的表达式选项、测试条件或操作。这些单词依照逻辑顺序出现,并描述要查找哪些文件以及如何处理查找到的文件。这种像单词一样的选项通常被称为谓词。如:find . -name '*.mp3' -print -exec mv '{}' ~/songs \;find命令的第一个参数待搜索的目录。典型用法是用点号(.)代表当前目录,也可以根据需要提供其他目录。示例中的第一个选项(谓词-name)指定了要搜索的文件模式。匹配该模式的文件被认为返回的是真(true),接着将其交给下一个下一个谓词进行处理。谓词-print很简单,它总是返回真,同时会将文件名打印到标准输出。因此能在谓词测试中通过测试而达到这一步的文件都会输出其名称。-exec:达到这一步的文件名会变成接下来要执行的命令的一部分。剩下的一直到\;的这部分就是命令。其中的{}会被替换成已经查找到的文件名。-delete:删除查找到的文件{dotted startColor="#ff6c6c" endColor="#1989fa"/}-print0:可以与xargs -0 选项合用处理文件名中的怪异字符。-print0告诉find不要用空白字符,而是改用空字符(null character)(\0)作为输出的文件名之间的分隔符。xargs的-0选项告诉xargs输入分隔符是空字符。xargs从标准输入中接收以空白字符分割(指定-0时除外)的文件名,然后对尽可能多的文件(略少于系统ARG_MAX值)执行指定命令。由于调用其他命令会带来不小的开销,因此使用xargs可以显著提升操作速度。因为xargs能够尽量减少命令的调用次数,而不是每个文件都调用。因此,上面的例子可以用下面的方案来处理怪异字符: find . -name '*.mp3' -print0 | xargs -i -0 mv '{}' ~/songs关于xargs命令的-i参数:mv命令需要将目标目录作为最后一个参数,而传统的xargs只是简单的获取输入,然后将其附加到指定命令的尾部,直到达到上限或处理完输入。但这样一来,mv命令肯定会报错。因此这里可以使用-i选项来指定输入参数的位置,默认使用{}作为替换字符串。但加入-i选项会导致对每个参数都要执行一次命令(-i选项无法实现参数分组),此外不是所有的xargs版本都支持-i选项。-L:跟随符号链接查找文件(也可以使用-follow选项)find -L . -name '*.mp3' -print0 | xargs -i -0 mv '{}' ~/songs-iname:查找文件时不区分大小写find . -follow -iname '*.mp3' -print0 | xargs -i -0 mv '{}' ~/songs此外,find可以配合模式匹配来达到不区分大小写的目的,例:find . -name '*.Jj[Gg]' -print-mtime:按日期查找文件find . -name '*.jpg' -mtime +90 -print-mtime谓词接受一个参数用于指定要搜索的时间段。90代表90天。在数字前使用加号(+90)表明要搜索的文件是在90天已经修改的。使用减号(-90)表示文件是在90天内修改的。如果没有加减号,则表明正好是90天。-type:按类型查找find . -type d -name '*java' -print类型说明: b 块设备文件 c 字符设备文件 d 目录 p 管道(或fifo) f 普通文件 l 符号链接 s 套接字 D 门(door)(仅限于Solaris) -size:按大小查找文件find . -size -3000k -print-size谓词后面的数值参数前可以添加减号加号或者什么都不加,分别表示小于大于等于该数值。按内容查找文件:如果需要在含有众多子目录的目录中查找含有特定内容的文件,可以使用以下方法:find . -name '*.txt' -exec grep -Hi portend '{}' \;说明:-H选项会输出包含搜索内容的文件名逻辑运算:find还可以使用逻辑运算符AND、OR、NOT,如果知道文件的修改时间至少在一周前,但不超过14天,可以这样写查找语句:find . -mtime +7 -a -mtime -14 -print连续出现的两个谓词,其效果类似于逻辑AND,优先级高于OR。为了获得正确的优先级,可能还得使用括号。而括号在bash中有特殊含义,要在find中使用,需要对其转义。要么写作(和),要么放入单引号,写作'('和')'。find . -mtime +14 -name '.txt' -o ( -mtime -14 -name '.txt' ) -print说明:改语句查找的是修改时间在14天以前或14天以内的以txt结尾的文件。{dotted startColor="#ff6c6c" endColor="#1989fa"/}locate与slocate:快速查找locate与slocate会查询系统的数据库文件(通常由corn作业负责编译和更新),几乎瞬间就能找到文件或命令。(数据库的位置,会对什么对象进行索引、索引的频率都是由系统决定的。)slocate保存了权限信息(以及文件名和路径),因此不会列出用户无权访问的文件。在大多数Linux系统中,locate只不过是指向slocate的符号链接。-maxdepth:查找深度 距离当前目录最多X深度(层)的文件。find / -maxdepth 5 -name '*.conf' | xargs grep listen
2024年09月27日
57 阅读
0 评论
0 点赞
1
...
4
5
6
...
12