0%

压缩文件

1
2
3
4
5
6
7
ls -hl laravel-2025-04-30.log
# -rw-r--r-- 1 op op 162M May 13 14:59 laravel-2025-04-30.log

zip laravel-2025-04-30.log.zip laravel-2025-04-30.log

ls -hl laravel-2025-04-30.log.zip
# -rw-rw-r-- 1 op op 48M May 13 15:04 laravel-2025-04-30.log.zip

上传文件

1
2
3
4
5
6
7
8
9
# 不推荐
./coscli cp laravel-2025-04-30.log.zip cos://tmp-1300481165/
# AvgSpeed: 42.26 MB/s
# cost 1.136000(s)

# 推荐使用限速
./coscli cp laravel-2025-04-30.log.zip cos://tmp-1300481165/ --rate-limiting 10
# AvgSpeed: 13.31 MB/s
# cost 3.604000(s)

Fabric is a high level Python (2.7, 3.4+) library designed to execute shell commands remotely over SSH, yielding useful Python objects in return

1
2
3
4
5
6
7
8
9
from fabric import Connection

host = "blog.nuozhilin.site"
user = "op"
conn = Connection(host=host, user=user)

result = conn.run("cd /opt/sites/blog && git pull origin coding-pages", hide=True)
print("Command output:")
print(result.stdout.strip())
1
2
3
pip install fabric

python main.py

类似方案pyinfra turns Python code into shell commands and runs them on your servers

释放空间

  • 修改collection名称 => 这样新数据会保存至新collection

  • 删除改名后的collection

TODO: 此方法待验证

TTL索引

1
2
3
4
db.myCollection.createIndex(
{ "createdAt": 1 },
{ expireAfterSeconds: 31536000 } // 1 年 = 365 天 * 24 小时 * 60 分钟 * 60 秒
)

无效字段

  • 存储文档时不包含”_class”字段

问题

failed to solve with frontend dockerfile.v0: failed to create LLB definition: unexpected status code [manifests alpine]: 403 Forbidden

  • 临时解决
1
2
export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0

本文基于Terraform 小记

TKE

  • provider.tf
1
2
3
4
5
6
7
8
9
10
11
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
}
}
}

provider "tencentcloud" {
region = "ap-nanjing"
}
1
2
3
4
5
terraform fmt

terraform init

curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/main/Terraform.gitignore
  • main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
resource "tencentcloud_vpc" "vpc_pve" {
name = "vpc-pve"
cidr_block = "10.1.0.0/16"
}

resource "tencentcloud_subnet" "subnet_pve" {
availability_zone = "ap-nanjing-1"
vpc_id = tencentcloud_vpc.vpc_pve.id
name = "subnet-pve"
cidr_block = "10.1.0.0/16"
}

resource "tencentcloud_security_group" "sg_pve" {
name = "sg-pve"
}

resource "tencentcloud_security_group_lite_rule" "sg_pve_rules" {
security_group_id = tencentcloud_security_group.sg_pve.id
ingress = [
"ACCEPT#10.1.0.0/16#ALL#ALL",
"ACCEPT#0.0.0.0/0#22#TCP",
]
egress = [
"ACCEPT#0.0.0.0/0#ALL#ALL"
]
}

resource "tencentcloud_key_pair" "key_pve" {
key_name = "key_pve"
public_key = file("~/.ssh/id_rsa.pub")
}

resource "tencentcloud_instance" "saas_pve01" {
availability_zone = "ap-nanjing-1"
instance_name = "saas-pve01"
instance_type = "SA2.MEDIUM2"
image_id = "img-pi0ii46r"
key_ids = [tencentcloud_key_pair.key_pve.id]
system_disk_size = 50
system_disk_type = "CLOUD_BSSD"
hostname = "saas-pve01"
vpc_id = tencentcloud_vpc.vpc_pve.id
subnet_id = tencentcloud_subnet.subnet_pve.id
orderly_security_groups = [tencentcloud_security_group.sg_pve.id]
allocate_public_ip = true
internet_max_bandwidth_out = 100
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
}

resource "tencentcloud_kubernetes_cluster" "k8s_pve" {
cluster_name = "k8-pve"
cluster_version = "1.26.1"
cluster_cidr = "172.16.0.0/22"
cluster_os = "tlinux3.1x86_64"
container_runtime = "containerd"
cluster_intranet = true
cluster_intranet_subnet_id = tencentcloud_subnet.subnet_pve.id
vpc_id = tencentcloud_vpc.vpc_pve.id

worker_config {
availability_zone = "ap-nanjing-1"
count = 1
instance_type = "SA5.MEDIUM2"
subnet_id = tencentcloud_subnet.subnet_pve.id
security_group_ids = [tencentcloud_security_group.sg_pve.id]
key_ids = [tencentcloud_key_pair.key_pve.id]
system_disk_size = 50
system_disk_type = "CLOUD_BSSD"
}
}

output "saas_pve01_public_ip" {
value = tencentcloud_instance.saas_pve01.public_ip
}
1
2
3
4
5
6
7
8
9
10
11
export TENCENTCLOUD_SECRET_ID="******"

export TENCENTCLOUD_SECRET_KEY="******"

terraform fmt

terraform plan
# Plan: 7 to add, 0 to change, 0 to destroy.

terraform apply
# 预计耗时7分钟
  • 登录 CVM
1
ssh ubuntu@cvm_public_ip
  • 下载 kubectl
1
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
  • 配置 Kubeconfig 查看 TKE
1
kubectl get pods
阅读全文 »

你的项目有哪些内容是基于 Git 管理的?

  1. 项目代码
  2. CI/CD

如何将你的项目从阿里云迁移到腾讯云?

  1. 开通腾讯云账号并充值
  2. 配置腾讯云子账号和权限管理
  3. 新建和配置网络
  4. 新建和配置 CVM 虚拟机、K8S
  5. 新建和配置 MySQL、Mongo、Redis、Kafka 等
  6. 部署项目代码
  7. 配置项目(包括:K8S 的 yaml 文件)
  8. 配置 CI/CD
  9. 以及上述所有的衔接部分

如何将上述所有(包括衔接部分)都纳入 Git 管理?

  1. 开通腾讯云账号并充值 人工控制
  2. 配置腾讯云子账号和权限管理 Terraform
  3. 新建和配置网络 Terraform
  4. 新建和配置 CVM 虚拟机、K8S Terraform
  5. 新建和配置 MySQL、Mongo、Redis、Kafka 等 Terraform+Ansible(测试环境)
  6. 部署项目代码 Git
  7. 配置项目(包括:K8S 的 yaml 文件)**Git**
  8. 配置 CI/CD GitLab CI&ArgoCD
  9. 以及上述所有的衔接部分 Python 等

拾遗信息:Manage secrets and protect sensitive data with Vault

Terraform 小记

Terraform Infrastructure automation to provision and manage resources in any cloud or data center

本文云服务使用腾讯云 需准备好凭证:SecretId 和 SecretKey

准备环境

1
2
3
4
5
6
brew tap hashicorp/tap

brew install hashicorp/tap/terraform

terraform -v
# Terraform v1.9.2

基本使用

新增 Provider

  • provider.tf
1
2
3
4
5
6
7
8
9
10
11
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
}
}
}

provider "tencentcloud" {
region = "ap-nanjing"
}
1
2
3
4
5
terraform fmt

terraform init

curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/main/Terraform.gitignore

预览

  • main.tf
1
2
3
4
5
6
7
8
9
10
11
resource "tencentcloud_vpc" "vpc_pve" {
name = "vpc-pve"
cidr_block = "10.1.0.0/16"
}

resource "tencentcloud_subnet" "subnet_pve" {
availability_zone = "ap-nanjing-1"
vpc_id = tencentcloud_vpc.vpc_pve.id
name = "subnet-pve"
cidr_block = "10.1.2.0/24"
}
1
2
3
4
5
6
7
8
export TENCENTCLOUD_SECRET_ID="******"

export TENCENTCLOUD_SECRET_KEY="******"

terraform fmt

terraform plan
# Plan: 2 to add, 0 to change, 0 to destroy.

快速入门

1
2
3
4
terraform fmt

terraform apply
# Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

terraform-01.png

terraform-02.png

阅读全文 »