騰訊雲資源統一管理入口,提供 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),實際價格以騰訊雲官網即時查詢為準。
| 方案型別 | 2 核 4G 參考 | 特點 |
|---|---|---|
| 新人特惠 | ~¥150-200/年 | 限新使用者 |
| 按量付費 | ~¥120-150/月 | 靈活 |
| 競價例項 | ~¥30-50/月 | 最高 90% OFF |
| 方案型別 | 2 核 2G 參考 | 特點 |
|---|---|---|
| 新人特惠 | ~¥80-120/年 | 限新使用者 |
| 包年包月 | ~¥400-500/年 | 價格穩定 |
| 儲存型別 | 參考價格 | 適用 |
|---|---|---|
| 標準儲存 | ~¥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')
resource-manager)推薦策略: 建立自定義策略,授予最小必要許可權
{
"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": "*"
}
]
}
{
"version": "2.0",
"statement": [
{
"effect": "allow",
"action": [
"lighthouse:Describe*", "lighthouse:CreateInstance",
"lighthouse:StartInstances", "lighthouse:StopInstances",
"lighthouse:RestartInstances", "lighthouse:ModifyInstancesAttribute",
"lighthouse:RenewInstance"
],
"resource": "*"
}
]
}
{
"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": "*"
}
]
}
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
pip3 install --break-system-packages \
tencentcloud-sdk-python \
cos-python-sdk-v5 \
python-dotenv
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'
)
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')
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/年(新人特惠)
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/月(按實際使用計費)
# 建立儲存桶
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/月(生命週期最佳化後)
小蔥技能站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'])
# 查詢所有資源成本
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}")
❌ 不要使用主賬號金鑰:
SECRET_ID = "AKID 主賬號金鑰" # 危險!
✅ 使用子使用者金鑰:
from dotenv import load_dotenv
load_dotenv('config/.env')
SECRET_ID = os.getenv('TENCENT_SECRET_ID')
只授予必要的許可權: - 開發環境:只讀許可權 + 建立許可權 - 生產環境:只讀許可權 + 啟停許可權 - 避免:財務許可權、使用者管理許可權
每 90 天輪換一次金鑰。
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']}")
cat config/.env
python3 src/verify_config.py
tccli cam ListAttachedUserPolicies --AttachUin <UIN>
tccli cvm DescribeAccountQuota
這個Skill的文件寫得非常詳細,中英文都有,對於新手友好,場景示例覆蓋面廣,從建部落格到資料採集都有指導。安全方面考慮了子使用者許可權配置,比直接用主賬號金鑰更安全。不足之處是實際使用前需要額外安裝依賴,而且價格資訊是參考值,可能會與實際有出入。總體質量不錯,但更適合有一定技術基礎的使用者。