每月 Shaarli

一月内的所有链接,汇聚在一个页面上。

February, 2025

Note: 使用sea-orm-cli管理数据库的一般操作

使用sea-orm-cli管理数据库的一般操作:

安装sea-orm-cli

cargo install sea-orm-cli

rustup component add rustfmt

在项目文件夹下创建.env数据库连接配置文件:

DATABASE_URL=postgres://postgres:123456@localhost:5432/purchasing?options=-c%20search_path%3Ddev_001

使用 sea-orm-cli migrate init 进行初始化操作。

然后记得修改./migration/Cargo.toml
改成这样:

...
[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }

[dependencies.sea-orm-migration]
version = "1.1.0"
features = [
  # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
  # View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
  # e.g.
   "runtime-tokio-rustls",  # `ASYNC_RUNTIME` feature
   "sqlx-postgres",         # `DATABASE_DRIVER` feature
]

也就是去掉下面的"#"号注释。

   # "runtime-tokio-rustls",  # `ASYNC_RUNTIME` feature
   # "sqlx-postgres",         # `DATABASE_DRIVER` feature

生成或更新实体文件 →

使用 sea-orm-cli generate entity 生成或更新实体文件

sea-orm-cli generate entity --output-dir ./src/entity --database-schema dev_001 --database-url "postgres://postgres:123456@localhost:5432/purchasing"

创建新的数据库或修改数据库结构迁移 →

使用 sea-orm-cli migrate generate 生成当前状态的迁移文件

sea-orm-cli migrate generate status_name

这样会在./migration/src文件夹下生成指定的status_name.rs

然后设计你的数据库改动,以后改动一次就执行一次并设计一次。

应用数据库变更 →

使用 sea-orm-cli migrate up 或 sea-orm-cli migrate down

如果需要重新进行迁移重置 →

使用 sea-orm-cli migrate init 进行重置操作。
然后记得修改./migration/Cargo.toml
改成这样:

...
[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }

[dependencies.sea-orm-migration]
version = "1.1.0"
features = [
  # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
  # View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
  # e.g.
   "runtime-tokio-rustls",  # `ASYNC_RUNTIME` feature
   "sqlx-postgres",         # `DATABASE_DRIVER` feature
]

也就是去掉下面的"#"号注释。

   # "runtime-tokio-rustls",  # `ASYNC_RUNTIME` feature
   # "sqlx-postgres",         # `DATABASE_DRIVER` feature

通过实体文件进行数据库操作 →

在代码中通过实体文件执行 CRUD 操作

Note: CentOS7 更新华为镜像源

备份现有的 yum 源配置文件

sudo mkdir /etc/yum.repos.d/backup
sudo mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/

下载华为云的 CentOS 7 镜像源配置文件

sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo

清理并生成缓存

sudo yum clean all
sudo yum makecache

测试镜像源

sudo yum update
在线AES加密 | AES解密 - 在线工具

在线AES加密,AES解密,可以输入密钥后进行加密和解密,支持可逆加密解密。

Note: Linux给机子改主机名(CentOS7 Ubuntu Alpine)

CentOS7

hostname mynewhostname

vi /etc/hostname

vi /etc/sysconfig/network
→HOSTNAME=mynewhostname

sudo systemctl restart systemd-hostnamed

Ubuntu

hostname mynewhostname

vi /etc/hostname

vi /etc/hosts
→127.0.1.1    mynewhostname

sudo systemctl restart systemd-logind.service

Alpine

hostname mynewhostname

vi /etc/hostname

vi /etc/hosts
→127.0.1.1    mynewhostname

sudo service hostname restart

验证主机名修改

hostname
Note: 一些Docker启动命令记录
docker rm $(docker ps -aq)

docker pull alpine

mkdir -p /data1/docker_data/web_service_alpine

docker volume create --driver local -o type=none -o device=/data1/docker_data/web_service_alpine -o o=bind web_service_alpine

docker run -it --name web_apline -v web_service_alpine:/service --memory="256m" --cpus="1" -p 22001:22 alpine

cat <<EOF > /etc/apk/repositories
#/media/cdrom/apks
https://mirrors.nju.edu.cn/alpine/latest-stable/main/
https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/main/
https://mirrors.nju.edu.cn/alpine/latest-stable/community/
https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/community/

https://mirrors.nju.edu.cn/alpine/v3.21/main/
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.21/main/
https://mirrors.nju.edu.cn/alpine/v3.21/community/
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.21/community/

https://mirrors.nju.edu.cn/alpine/edge/main/
https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/main/
https://mirrors.nju.edu.cn/alpine/edge/community/
https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/community/

https://mirrors.nju.edu.cn/alpine/edge/testing/
https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/testing/
EOF

apk update

apk add shadow openssh openssl openrc

sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
cat /etc/ssh/sshd_config | grep "PermitRootLogin"
cat /etc/ssh/sshd_config | grep "PasswordAuthentication"

ssh-keygen -A

passwd

rc-update add sshd
rc-service sshd start

/usr/sbin/sshd -D &

ssh-keygen -f "/root/.ssh/known_hosts" -R "[127.0.0.1]:22001"

ssh root@127.0.0.1 -p 22001

docker volume create --driver local -o type=none -o device=/docker_data/web_service_alpine -o o=bind web_service_alpine
docker run -it --name web_apline -v web_service_alpine:/service --memory="512m" --cpus="1" -p 22001:22 -p 10080:80 -p 10443:443 v_alpine

docker run -it --name web_apline -v web_service_alpine:/service --memory="256m" --cpus="1" -p 22001:22 v_alpine

/docker_data/dockerfile# cat Dockerfile
FROM v_alpine:latest

# 配置 SSH 服务
RUN ssh-keygen -A

# 设置 root 密码
RUN echo 'root:zjf6617' | chpasswd

# 启动 sshd 服务
CMD ["/usr/sbin/sshd", "-D", "&"]
root@C20250126506523:/docker_data/dockerfile# docker build -t ssh_v_alpine .

docker run -it --name web_apline -v web_service_alpine:/service --memory="256m" --cpus="1" -p 22001:22 ssh_v_alpine

docker build -f ./docker_file_for_alpine -t ssh_v_alpine:latest .

docker build -f ./docker_file_for_alpine -t nginx_php_redis:latest .

docker run -it --name web_apline -v web_service_alpine:/service --memory="512m" --cpus="1" -p 22001:22 -p 10080:80 -p 10443:443 nginx_php_redis
docker run -it --name web_apline --memory="512m" --cpus="1" -p 22001:22 -p 10080:80 -p 10443:443 nginx_php_redis

docker run -it --name web_apline_lasting -v web_service_alpine:/service --memory="512m" --cpus="1" -p 22001:22 -p 25080:80 -p 25443:443 nginx_php_redis

docker run -it --name web_apline_template --memory="512m" --cpus="1" -p 22001:22 -p 25080:80 -p 25443:443 nginx_php_redis

docker run -it --name apline_template --hostname XBY-CD-VAPLINE-DOCKER --add-host XBY-CD:127.0.0.1 --memory="512m" --cpus="1" --privileged v_alpine
SiliconFlow, Accelerate AGI to Benefit Humanity

硅基流动致力于打造规模化、标准化、高效能 AI Infra 平台,提供高效能、低成本的多品类 AI 模型服务,助力开发者和企业聚焦产品创新。

Note: CentOS7安装Docker
yum remove docker  docker-common docker-selinux docker-engine

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
(中央仓库)

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
(阿里仓库)

yum list docker-ce --showduplicates | sort -r

yum -y install docker-ce-18.06.3.ce

systemctl start docker
systemctl enable docker
Note: Alpine最新最全国内源

vi /etc/apk/repositories

#/media/cdrom/apks
https://mirrors.nju.edu.cn/alpine/latest-stable/main/
https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/main/
https://mirrors.nju.edu.cn/alpine/latest-stable/community/
https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/community/

https://mirrors.nju.edu.cn/alpine/v3.21/main/
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.21/main/
https://mirrors.nju.edu.cn/alpine/v3.21/community/
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.21/community/

https://mirrors.nju.edu.cn/alpine/edge/main/
https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/main/
https://mirrors.nju.edu.cn/alpine/edge/community/
https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/community/

https://mirrors.nju.edu.cn/alpine/edge/testing/
https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/testing/
Note: Taskkill

taskkill /fi "username eq Administrator"

Xshell/Xftp/XshellPlus
GitCode - 全球开发者的开源社区,开源代码托管平台

GitCode是面向全球开发者的开源社区,包括原创博客,开源代码托管,代码协作,项目管理等。与开发者社区互动,提升您的研发效率和质量。

Note: CentOS7发送邮件给邮箱
yum install -y mailx
echo "Test mail" | mail -s "Test" admin@example.com
Note: CentOS7安装Rust环境

更新系统

sudo yum update -y

安装依赖

sudo yum install -y curl gcc

安装 Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

配置环境变量

source $HOME/.cargo/env

验证安装

rustc --version

更新 Rust(可选)

rustup update

卸载 Rust(可选)

rustup self uninstall