2023年9月17日星期日

使用docker pull 拉取特定架构amd64、arm64、aarch64的容器镜像

关于x86、x86_64、x64、amd64和arm64、aarch64














开启属性

docker cli支持manifest特性,这个特性默认是不开启的。

通过修改 dockerd 配置文件,并重载,可以在服务器上开启 dockerd 的实验属性。

为配置文件 /etc/docker/daemon.json

添加 “experimental”: true。

修改后的配置文件看起来和下面的比较像:

vim /etc/docker/daemon.json

{
  "experimental": true
}

修改完成后,使用以下命令重置服务:

systemctl daemon-reload
systemctl restart docker

拉取指定架构的镜像

在 docker pull 时指定参数,即可完成指定架构镜像的拉取。

docker pull --platform=arm64 镜像

–platform:该参数是用于拉取指定平台的镜像,也是实验性功能,在上面步骤中开启后就会出现。通过该参数可以手动指定需要的CPU平台镜像,而不用自动去识别。

拉取 arm64 架构镜像示例。

docker pull --platform linux/arm64 openjdk

通过以下命令,可以确定其架构信息:

$ docker image inspect openjdk | grep Architecture
"Architecture": "arm64",
  • 1
  • 2

而主机的架构,是 aarch64:

$ arch
aarch64



2023年7月21日星期五

极空间NAS使用Docker运行Ubuntu/Debian并添加自定义启动脚本

极空间Docker运行Ubuntu/Debian并添加自定义启动脚本

1、添加外部文件夹并装载到 /sh 路径
2、打开容器命令选项卡,Console 连接模式选择 Interacticve &TTV(-i-t )模式
3、其他默认,应用,首次运行系统
4、通过运行的容器的ssh连接至控制终端,命令选择:/bin/sh
5、创建st.sh文件

touch /sh/st.sh

5、设置脚本文件权限

chmod 777 /sh/st.sh

7、写入基本命令

echo "
#!/bin/sh
# vim:sw=4:ts=4:et
exec "$@"
" >> /sh/st.sh

或分别执行

echo " service ssh restart " >> /sh/st.sh
echo "# vim:sw=4:ts=4:et" >> /sh/st.sh
echo "exec "$@"" >> /sh/st.sh

检查写入文件内容,确认无误后继续下一步
8、停止容器,打开容器命令选项卡,编辑EntryPoint选项,选择自定义并输入内容 /sh/st.sh (执行脚本路径)
9、应用修改,容器重新启动
10、通过运行的容器的ssh连接至控制终端
11、执行初始化,替换国内源:
Ubuntu

sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list

Debian

sed -i "s@http://ftp.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list
sed -i "s@http://security.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list

如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装:

sudo apt install apt-transport-https ca-certificates

Debian 12 (bookworm) 源:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

# deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# # deb-src http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware

12、更新系统并安装基本软件

apt-get update &&
apt install -y sudo &&
sudo apt-get -y update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade &&
sudo apt install -y openssh-server &&
sudo apt install -y vim

13、允许root用户远程登陆,修改/etc/ssh/sshd_config文件:

sudo vim /etc/ssh/sshd_config

修改相关内容,

Port 22
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

14、刷新状态:

sudo service ssh restart

15、设定root用户密码
输入 sudo passwd 命令,输入一般用户密码并设定root用户密码

16、自动安装标准软件包(适用于最小安装)
unminimize

17、通过运行的容器的ssh连接至控制终端,命令选择:/bin/sh ,增加 ssh 的自动启动

echo " service ssh restart " >> /sh/st.sh

18、完成基本设定

2023年7月5日星期三

Windows系统常见的系统环境变量

 1.变量示意

%appdata%就代表了C:Users\用户名\AppData\Roaming这个文件夹。

“%”是系统变量的一种表示方法,在升级补丁或者软件需要将某些内容写入系统文件夹时,都是用的这种写法,可以准确的定位。

2.其他常见变量。

环境变量与对应的路径

%ALLUSERSPROFILE%                       C:\ProgramData

%APPDATA%                                         C:\Users\用户名\AppData\Roaming

%COMMONPROGRAMFILES%            C:\Program Files\Common Files

%COMMONPROGRAMFILES(x86)%    C:\Program Files (x86)\Common Files

%COMSPEC%                                       C:\Windows\System32\cmd.exe

%HOMEDRIVE%和%SystemDrive%     C:\

%HOMEPATH%                                     C:\Users\用户名

%LOCALAPPDATA%                            C:\Users\用户名\AppData\Local

%PROGRAMDATA%                            C:\ProgramData

%PROGRAMFILES%                           C:\Program Files

%PROGRAMFILES(X86)%                  C:\Program Files (x86)

%PUBLIC%                                          C:\UsersPublic

%SystemRoot%                                   C:\Windows

%TEMP%和%TMP%                           C:\Users\用户名\AppData\LocalTemp

%USERPROFILE%                             C:\Users用户名

%WINDIR%                                         C:\Windows

%LOCALAPPDATA%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets                   锁屏桌面目录



应用示例:

改变EDGE缓存位置
mklink /d "%HOMEPATH%\AppData\Local\Microsoft\Edge\User Data\Default\Cache" "A:\Cache"

2023年6月3日星期六

极空间NAS使用Docker 运行 CHFS

Docker仓库地址: https://hub.docker.com/r/jonnyan404/chfs

WEBUI基本启动命令配置( 极空间 示例 ):
'--path=/data' '--rule=:::Share:r|admin:admin:rwd' 
指定文件目录 /data  ; 其中,未登录时Share目录可读,登录时可读写根目录

EntryPoint命令:
'/usr/bin/chfs' 

Consale:
None


官网地址: http://iscute.cn/chfs

  • 支持arm64/amd64双平台
  • 下载链接格式:
文件: wget http://ip:port/chfs/shared/xxx.txt
目录: wget http://ip:port/chfs/downloaddir/xxx.zip

简单教程:

docker run --restart=on-failure:3 -d --name chfs -p 80:80 -v /path/you/dir:/data jonnyan404/chfs

  • 默认端口为80,权限为增删改.
  • /path/you/dir 请自行替换为你自己的目录

打开 http://ip 即可访问.

进阶教程:

自定义端口

docker run --restart=on-failure:3 -d --name chfs -p 80:80 -v /path/you/dir:/data jonnyan404/chfs --port=80 --path=/data

自定义配置文件

docker run --restart=on-failure:3 -d --name chfs -p 80:80 -v /path/you/dir:/data jonnyan404/chfs --file=/data/xxx.ini

同一个容器运行多个CHFS

  1. 指定一个端口范围

docker run --restart=on-failure:3 -d --name chfs -p 80-90:80-90 -v /path/you/dir:/data jonnyan404/chfs

  1. 执行程序

docker exec -it chfs nohup chfs --port=88 --path=/data/xxx &或docker exec -it chfs nohup chfs --file=/data/yyy.ini &

更多参数

//共享目录为D盘,监听端口号为8080
chfs --path="d:/" --port=8080

//共享目录为"d:\\projects"和"e:\\nsis",监听端口号为80
chfs --path="d:\\projects|e:\\nsis"

//白名单模式,允许192.168.1.2-192.168.1.100以及192.168.1.200进行访问
chfs --allow="192.168.1.2-192.168.1.100,192.168.1.200"

//黑名单模式,禁止192.168.1.2-192.168.1.100以及192.168.1.200进行访问
chfs --allow="not(192.168.1.2-192.168.1.100,192.168.1.200)"

//匿名用户具有只读权限(默认情况下匿名用户具有读写权限)
//账户ceshizu,密码为ceshizu123,对根目录的权限为只读,但对test目录具有读写权限
//账户yanfazu,密码为yanfazu123,对根目录的权限为只读,但对yanfa目录具有读写权限
chfs --rule="::r|ceshizu:ceshizu123:r:test:rw|yanfazu:yanfazu123:r:yanfa:rw"

//匿名用户什么权限都没有(默认情况下匿名用户具有读写权限)
//账户admin,密码为admin123,具有读写权限
//账户zhangsan,密码为zhangsan123,对根目录的权限为不可读写,但对zhangsanfiles目录具有读写权限
chfs --rule="::|admin:admin123:rw|zhangsan:zhangsan123::zhangsanfiles:rw"

//通过配置文件进行配置,该文件可以不存在,待以后需要更改配置时使用
chfs --file="d:\chfs\chfs.ini"


2023年5月29日星期一

2023年5月14日星期日

2023年4月9日星期日

Linux自动挂载磁盘的方法

 来自宝塔的自动挂载磁盘脚本:


#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
LANG=en_US.UTF-8
setup_path=/www
#if [ $1 != "" ];then
    #setup_path=$1;
#fi

#检测磁盘数量
sysDisk=`cat /proc/partitions|grep -v name|grep -v ram|awk '{print $4}'|grep -v '^$'|grep -v '[0-9]$'|grep -v 'vda'|grep -v 'xvda'|grep -v 'sda'|grep -e 'vd' -e 'sd' -e 'xvd'`
if [ "${sysDisk}" == "" ]; then
    echo -e "ERROR!This server has only one hard drive,exit"
    echo -e "此服务器只有一块磁盘,无法挂载"
    echo -e "Bye-bye"
    exit;
fi
#检测/www目录是否已挂载磁盘
mountDisk=`df -h | awk '{print $6}' |grep www`
if [ "${mountDisk}" != "" ]; then
    echo -e "www directory has been mounted,exit"
    echo -e "www目录已被挂载,不执行任何操作"
    echo -e "Bye-bye"
    exit;
fi
#检测是否有windows分区
winDisk=`fdisk -l |grep "NTFS\|FAT32"`
if [ "${winDisk}" != "" ];then
    echo 'Warning: The Windows partition was detected. For your data security, Mount manually.';
    echo "危险 数据盘为windwos分区,为了你的数据安全,请手动挂载,本脚本不执行任何操作。"
    exit;
fi
echo "
+----------------------------------------------------------------------
| Bt-WebPanel Automatic disk partitioning tool
+----------------------------------------------------------------------
| Copyright © 2015-2017 BT-SOFT(http://www.bt.cn) All rights reserved.
+----------------------------------------------------------------------
| Auto mount partition disk to $setup_path
+----------------------------------------------------------------------
"


#数据盘自动分区
fdiskP(){
    
    for i in `cat /proc/partitions|grep -v name|grep -v ram|awk '{print $4}'|grep -v '^$'|grep -v '[0-9]$'|grep -v 'vda'|grep -v 'xvda'|grep -v 'sda'|grep -e 'vd' -e 'sd' -e 'xvd'`;
    do
        #判断指定目录是否被挂载
        isR=`df -P|grep $setup_path`
        if [ "$isR" != "" ];then
            echo "Error: The $setup_path directory has been mounted."
            return;
        fi
        
        isM=`df -P|grep '/dev/${i}1'`
        if [ "$isM" != "" ];then
            echo "/dev/${i}1 has been mounted."
            continue;
        fi
            
        #判断是否存在未分区磁盘
        isP=`fdisk -l /dev/$i |grep -v 'bytes'|grep "$i[1-9]*"`
        if [ "$isP" = "" ];then
                #开始分区
                fdisk -S 56 /dev/$i << EOF
n
p
1


wq
EOF

            sleep 5
            #检查是否分区成功
            checkP=`fdisk -l /dev/$i|grep "/dev/${i}1"`
            if [ "$checkP" != "" ];then
                #格式化分区
                mkfs.ext4 /dev/${i}1
                mkdir $setup_path
                #挂载分区
                sed -i "/\/dev\/${i}1/d" /etc/fstab
                echo "/dev/${i}1    $setup_path    ext4    defaults    0 0" >> /etc/fstab
                mount -a
                df -h
            fi
        else
            #判断是否存在Windows磁盘分区
            isN=`fdisk -l /dev/$i|grep -v 'bytes'|grep -v "NTFS"|grep -v "FAT32"`
            if [ "$isN" = "" ];then
                echo 'Warning: The Windows partition was detected. For your data security, Mount manually.';
                return;
            fi
            
            #挂载已有分区
            checkR=`df -P|grep "/dev/$i"`
            if [ "$checkR" = "" ];then
                    mkdir $setup_path
                    sed -i "/\/dev\/${i}1/d" /etc/fstab
                    echo "/dev/${i}1    $setup_path    ext4    defaults    0 0" >> /etc/fstab
                    mount -a
                    df -h
            fi
            
            #清理不可写分区
            echo 'True' > $setup_path/checkD.pl
            if [ ! -f $setup_path/checkD.pl ];then
                    sed -i "/\/dev\/${i}1/d" /etc/fstab
                    mount -a
                    df -h
            else
                    rm -f $setup_path/checkD.pl
            fi
        fi
    done
}
stop_service(){

    /etc/init.d/bt stop

    if [ -f "/etc/init.d/nginx" ]; then
        /etc/init.d/nginx stop > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/httpd" ]; then
        /etc/init.d/httpd stop > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/mysqld" ]; then
        /etc/init.d/mysqld stop > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/pure-ftpd" ]; then
        /etc/init.d/pure-ftpd stop > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/tomcat" ]; then
        /etc/init.d/tomcat stop > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/redis" ]; then
        /etc/init.d/redis stop > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/memcached" ]; then
        /etc/init.d/memcached stop > /dev/null 2>&1
    fi

    if [ -f "/www/server/panel/data/502Task.pl" ]; then
        rm -f /www/server/panel/data/502Task.pl
        if [ -f "/etc/init.d/php-fpm-52" ]; then
            /etc/init.d/php-fpm-52 stop > /dev/null 2>&1
        fi

        if [ -f "/etc/init.d/php-fpm-53" ]; then
            /etc/init.d/php-fpm-53 stop > /dev/null 2>&1
        fi

        if [ -f "/etc/init.d/php-fpm-54" ]; then
            /etc/init.d/php-fpm-54 stop > /dev/null 2>&1
        fi

        if [ -f "/etc/init.d/php-fpm-55" ]; then
            /etc/init.d/php-fpm-55 stop > /dev/null 2>&1
        fi

        if [ -f "/etc/init.d/php-fpm-56" ]; then
            /etc/init.d/php-fpm-56 stop > /dev/null 2>&1
        fi

        if [ -f "/etc/init.d/php-fpm-70" ]; then
            /etc/init.d/php-fpm-70 stop > /dev/null 2>&1
        fi

        if [ -f "/etc/init.d/php-fpm-71" ]; then
            /etc/init.d/php-fpm-71 stop > /dev/null 2>&1
        fi
    fi
}

start_service()
{
    /etc/init.d/bt start

    if [ -f "/etc/init.d/nginx" ]; then
        /etc/init.d/nginx start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/httpd" ]; then
        /etc/init.d/httpd start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/mysqld" ]; then
        /etc/init.d/mysqld start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/pure-ftpd" ]; then
        /etc/init.d/pure-ftpd start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/tomcat" ]; then
        /etc/init.d/tomcat start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/redis" ]; then
        /etc/init.d/redis start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/memcached" ]; then
        /etc/init.d/memcached start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/php-fpm-52" ]; then
        /etc/init.d/php-fpm-52 start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/php-fpm-53" ]; then
        /etc/init.d/php-fpm-53 start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/php-fpm-54" ]; then
        /etc/init.d/php-fpm-54 start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/php-fpm-55" ]; then
        /etc/init.d/php-fpm-55 start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/php-fpm-56" ]; then
        /etc/init.d/php-fpm-56 start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/php-fpm-70" ]; then
        /etc/init.d/php-fpm-70 start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/php-fpm-71" ]; then
        /etc/init.d/php-fpm-71 start > /dev/null 2>&1
    fi

    if [ -f "/etc/init.d/php-fpm-72" ]; then
        /etc/init.d/php-fpm-71 start > /dev/null 2>&1
    fi
    
    if [ -f "/etc/init.d/php-fpm-73" ]; then
        /etc/init.d/php-fpm-71 start > /dev/null 2>&1
    fi

    echo "True" > /www/server/panel/data/502Task.pl
}

while [ "$go" != 'y' ] && [ "$go" != 'n' ]
do
    read -p "Do you want to try to mount the data disk to the $setup_path directory?(y/n): " go;
done

if [ "$go" = 'n' ];then
    echo -e "Bye-bye"
    exit;
fi

if [ -f "/etc/init.d/bt" ] && [ -f "/www/server/panel/data/port.pl" ]; then
    disk=`cat /proc/partitions|grep -v name|grep -v ram|awk '{print $4}'|grep -v '^$'|grep -v '[0-9]$'|grep -v 'vda'|grep -v 'xvda'|grep -v 'sda'|grep -e 'vd' -e 'sd' -e 'xvd'`
    diskFree=`cat /proc/partitions |grep ${disk}|awk '{print $3}'`
    wwwUse=`du -sh -k /www|awk '{print $1}'`

    if [ "${diskFree}" -lt "${wwwUse}" ]; then
        echo -e "Sorry,your data disk is too small,can't coxpy to the www."
        echo -e "对不起,你的数据盘太小,无法迁移www目录数据到此数据盘"
        exit;
    else
        echo -e ""
        echo -e "stop bt-service"
        echo -e "停止宝塔服务"
        echo -e ""
        sleep 3
        stop_service
        echo -e ""
        mv /www /bt-backup
        echo -e "disk partition..."
        echo -e "磁盘分区..."
        sleep 2
        echo -e ""
        fdiskP
        echo -e ""
        echo -e "move disk..."
        echo -e "迁移数据中..."
        \cp -r -p -a /bt-backup/* /www
        echo -e ""
        echo -e "Done"
        echo -e "迁移完成"
        echo -e ""
        echo -e "start bt-service"
        echo -e "启动宝塔服务"
        echo -e ""
        start_service
    fi
else
    fdiskP
    echo -e ""
    echo -e "Done"
    echo -e "挂载成功"
fi

使用方法:

1、复制代码,保存为 autodisk.sh
2、bash autodisk.sh 即可!