TencentCloud Manager

👤 ugpoor 📦 v1.2.0 ⭐ 4.2 ⬇️ 771 下載
🔒 IT運維與安全 免費 🔑 需 API Key

📖 技能介紹

TencentCloud-Manager - 騰訊雲資源統一管理技能

📋 技能說明

騰訊雲資源統一管理入口,提供 CVM 雲伺服器、Lighthouse 輕量應用伺服器、COS 物件儲存的建立、配置和運維管理。

入口元件

本技能是騰訊雲管理的統一入口。你也可以直接使用各分支技能:

技能 說明 引用
tencentcloud-cvm CVM 雲伺服器管理 from tencentcloud_cvm import CVMManager
tencentcloud-lighthouse Lighthouse 輕量伺服器管理 from tencentcloud_lighthouse import LighthouseManager
tencentcloud-cos COS 物件儲存管理 from tencentcloud_cos import COSManager
tencentcloud-ops CVM + COS 運維工具包 from tencentcloud_ops import CVMManager, COSManager

核心功能

資源建立與配置 - CVM 雲伺服器例項管理 - Lighthouse 輕量伺服器管理 - COS 儲存桶與檔案管理

運維管理 - 例項啟停與重啟 - 監控與狀態查詢 - 生命週期管理 - 批次操作

成本最佳化 - 促銷方案查詢與對比 - 儲存型別成本估算 - 資源配置建議

安全管理 - 子使用者許可權配置 - 憑證外部化管理 - 操作審計日誌


💰 價格參考

⚠️ 注意: 以下價格為參考區間(更新於 2026-03-29),實際價格以騰訊雲官網即時查詢為準。

CVM 雲伺服器

方案型別 2 核 4G 參考 特點
新人特惠 ~¥150-200/年 限新使用者
按量付費 ~¥120-150/月 靈活
競價例項 ~¥30-50/月 最高 90% OFF

Lighthouse 輕量伺服器

方案型別 2 核 2G 參考 特點
新人特惠 ~¥80-120/年 限新使用者
包年包月 ~¥400-500/年 價格穩定

COS 物件儲存

儲存型別 參考價格 適用
標準儲存 ~¥0.12-0.15/GB/月 頻繁訪問
低頻儲存 ~¥0.07-0.09/GB/月 不常訪問
歸檔儲存 ~¥0.02-0.04/GB/月 長期儲存

查詢即時價格

from tencentcloud_manager import TencentCloudManager

tcm = TencentCloudManager()

# 查詢 CVM 促銷
tcm.show_promotions(service='cvm')

# 查詢 Lighthouse 促銷
tcm.show_promotions(service='lighthouse')

⚠️ 前置配置 (必須完成)

步驟 1: 建立騰訊雲子使用者

  1. 訪問 https://console.cloud.tencent.com/cam/capi
  2. 登入騰訊雲賬號
  3. 建立子使用者(如:resource-manager
  4. 複製 SecretId 和 SecretKey

步驟 2: 配置子使用者許可權

推薦策略: 建立自定義策略,授予最小必要許可權

CVM 管理許可權

{
  "version": "2.0",
  "statement": [
    {
      "effect": "allow",
      "action": [
        "cvm:Describe*", "cvm:RunInstances", "cvm:StartInstances",
        "cvm:StopInstances", "cvm:RestartInstances", "cvm:ModifyInstancesAttribute",
        "cvm:RenewInstances", "vpc:DescribeSecurityGroups", "vpc:CreateSecurityGroup"
      ],
      "resource": "*"
    }
  ]
}

Lighthouse 管理許可權

{
  "version": "2.0",
  "statement": [
    {
      "effect": "allow",
      "action": [
        "lighthouse:Describe*", "lighthouse:CreateInstance",
        "lighthouse:StartInstances", "lighthouse:StopInstances",
        "lighthouse:RestartInstances", "lighthouse:ModifyInstancesAttribute",
        "lighthouse:RenewInstance"
      ],
      "resource": "*"
    }
  ]
}

COS 管理許可權

{
  "version": "2.0",
  "statement": [
    {
      "effect": "allow",
      "action": [
        "name/cos:GetBucket", "name/cos:PutBucket", "name/cos:ListBucket",
        "name/cos:GetObject", "name/cos:PutObject", "name/cos:DeleteObject",
        "name/cos:PutBucketLifecycle", "name/cos:GetBucketLifecycle"
      ],
      "resource": "*"
    }
  ]
}

步驟 3: 配置憑證到.env 檔案

cp skills/tencentcloud-manager/config/.env.example \
   skills/tencentcloud-manager/config/.env

vim skills/tencentcloud-manager/config/.env
TENCENT_SECRET_ID=AKIDxxxxxxxxxxxxxxxxxxxxxxxxxx
TENCENT_SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxx
TENCENT_REGION=ap-singapore
RESOURCE_PREFIX=resource
BUDGET_ALERT=100

步驟 4: 安裝依賴

pip3 install --break-system-packages \
  tencentcloud-sdk-python \
  cos-python-sdk-v5 \
  python-dotenv

🚀 快速開始

方式 1: 使用統一入口

from tencentcloud_manager import TencentCloudManager

tcm = TencentCloudManager()

# 檢視所有可用服務
tcm.show_services()

# 查詢促銷方案
tcm.show_promotions(service='lighthouse')

# 建立資源
instance = tcm.create_resource(
    service='lighthouse',
    plan_id='new-2c4g',
    instance_name='my-server'
)

方式 2: 直接使用各服務管理器

from tencentcloud_cvm import CVMManager
cvm = CVMManager()
cvm.show_promotions()

from tencentcloud_lighthouse import LighthouseManager
lh = LighthouseManager()
lh.show_blueprints()

from tencentcloud_cos import COSManager
cos = COSManager()
cos.create_bucket(bucket_name='my-bucket')

📚 Cookbook - 常用場景

場景 1: 建立個人部落格伺服器

from tencentcloud_manager import TencentCloudManager

tcm = TencentCloudManager()

# 檢視促銷方案
tcm.show_promotions(service='lighthouse')

# 建立輕量伺服器(使用 WordPress 映象)
instance = tcm.create_resource(
    service='lighthouse',
    plan_id='new-1c1g',
    blueprint_id='bp-wordpress',
    instance_name='my-blog',
    period=12
)

print(f"伺服器已建立:{instance['PublicAddress']}")

預估成本: ~¥60-80/年(新人特惠)


場景 2: 建立資料採集伺服器

tcm = TencentCloudManager()

# 建立 CVM 例項(按量付費)
instance = tcm.create_resource(
    service='cvm',
    plan_id='payg-2c4g',
    image_id='img-ubuntu-2204',
    instance_name='data-collector',
    system_disk_size=100,
    bandwidth=5
)

# 設定定時關機
tcm.schedule_shutdown(
    service='cvm',
    instance_id=instance['InstanceId'],
    shutdown_time='23:00',
    timezone='Asia/Shanghai'
)

預估成本: ~¥130-180/月(按實際使用計費)


場景 3: 配置物件儲存並設定生命週期

# 建立儲存桶
bucket = tcm.create_cos_bucket(
    bucket_name='my-data-bucket',
    region='ap-singapore',
    storage_class='STANDARD'
)

# 上傳檔案
tcm.upload_to_cos(
    bucket=bucket['bucket'],
    local_path='/tmp/data.parquet',
    key='data/2024/03/29/data.parquet'
)

# 設定生命週期
tcm.set_cos_lifecycle(
    bucket=bucket['bucket'],
    rules=[
        {
            'id': 'data-lifecycle',
            'prefix': 'data/',
            'transitions': [
                {'days': 7, 'storage_class': 'STANDARD_IA'},
                {'days': 30, 'storage_class': 'ARCHIVE'}
            ]
        }
    ]
)

預估成本: ~¥35-50/月(生命週期最佳化後)


場景 4: 批次管理伺服器

小蔥技能站7w4.net發現了升級外掛。

# 查詢所有例項
instances = tcm.list_all_instances()

# 批次開機
for inst in instances:
    if inst['state'] == 'STOPPED':
        tcm.start_resource(inst['service'], inst['id'])

# 批次關機
for inst in instances:
    if inst['state'] == 'RUNNING':
        tcm.stop_resource(inst['service'], inst['id'])

場景 5: 監控資源成本

# 查詢所有資源成本
cost_report = tcm.get_cost_report()

print(f"總月成本:¥{cost_report['total_monthly_cost']}")

# 成本最佳化建議
suggestions = tcm.get_cost_optimization_suggestions()
for suggestion in suggestions:
    print(f"💡 {suggestion}")

🔒 安全最佳實踐

1. 使用子使用者憑證

不要使用主賬號金鑰:

SECRET_ID = "AKID 主賬號金鑰"  # 危險!

使用子使用者金鑰

from dotenv import load_dotenv
load_dotenv('config/.env')
SECRET_ID = os.getenv('TENCENT_SECRET_ID')

2. 最小許可權原則

只授予必要的許可權: - 開發環境:只讀許可權 + 建立許可權 - 生產環境:只讀許可權 + 啟停許可權 - 避免:財務許可權、使用者管理許可權

3. 定期輪換金鑰

每 90 天輪換一次金鑰。

4. 啟用操作審計

tcm = TencentCloudManager(enable_audit=True)

📈 運維管理

日常巡檢

# 檢查所有例項狀態
instances = tcm.list_all_instances()
for inst in instances:
    status = tcm.get_resource_status(inst['service'], inst['id'])
    if status['state'] != 'RUNNING':
        print(f"⚠️  例項異常:{inst['name']}")

# 檢查即將到期的資源
expiring = tcm.get_expiring_resources(days=30)
for resource in expiring:
    print(f"⏰ 即將到期:{resource['name']}")

📚 相關文件


🆘 故障排除

問題 1: 憑證驗證失敗

cat config/.env
python3 src/verify_config.py

問題 2: 許可權不足

tccli cam ListAttachedUserPolicies --AttachUin <UIN>

問題 3: 建立失敗

tccli cvm DescribeAccountQuota

🤖 AI 評測

這個Skill的文件寫得非常詳細,中英文都有,對於新手友好,場景示例覆蓋面廣,從建部落格到資料採集都有指導。安全方面考慮了子使用者許可權配置,比直接用主賬號金鑰更安全。不足之處是實際使用前需要額外安裝依賴,而且價格資訊是參考值,可能會與實際有出入。總體質量不錯,但更適合有一定技術基礎的使用者。

📊 多維度評分

適應性4.3
規範性4.4
有效性3.8
可靠性3.9
可信度5

📁 包含檔案 (6 個)

📄 SKILL.md 9.2 KB
📄 _meta.json 139 B
📄 docs/permission-policy.md 3.5 KB
📄 docs/quick-reference.md 2.6 KB
📄 src/__init__.py 226 B
📄 src/tencentcloud_manager.py 21.9 KB