122 lines
3.4 KiB
JavaScript
122 lines
3.4 KiB
JavaScript
![]() |
#!/usr/bin/env node
|
|||
|
|
|||
|
/**
|
|||
|
* MinIO连接调试脚本
|
|||
|
*/
|
|||
|
|
|||
|
const { S3 } = require('@aws-sdk/client-s3');
|
|||
|
|
|||
|
async function debugMinIO() {
|
|||
|
console.log('🔍 MinIO连接调试开始...\n');
|
|||
|
|
|||
|
const config = {
|
|||
|
endpoint: 'http://localhost:9000',
|
|||
|
region: 'us-east-1',
|
|||
|
credentials: {
|
|||
|
accessKeyId: '7Nt7OyHkwIoo3zvSKdnc',
|
|||
|
secretAccessKey: 'EZ0cyrjJAsabTLNSqWcU47LURMppBW2kka3LuXzb',
|
|||
|
},
|
|||
|
forcePathStyle: true,
|
|||
|
};
|
|||
|
|
|||
|
console.log('配置信息:');
|
|||
|
console.log('- Endpoint:', config.endpoint);
|
|||
|
console.log('- Region:', config.region);
|
|||
|
console.log('- Access Key:', config.credentials.accessKeyId);
|
|||
|
console.log('- Force Path Style:', config.forcePathStyle);
|
|||
|
console.log();
|
|||
|
|
|||
|
const s3Client = new S3(config);
|
|||
|
|
|||
|
try {
|
|||
|
// 1. 测试基本连接
|
|||
|
console.log('📡 测试基本连接...');
|
|||
|
const buckets = await s3Client.listBuckets();
|
|||
|
console.log('✅ 连接成功!');
|
|||
|
console.log('📂 现有存储桶:', buckets.Buckets?.map((b) => b.Name) || []);
|
|||
|
console.log();
|
|||
|
|
|||
|
// 2. 检查test123存储桶
|
|||
|
const bucketName = 'test123';
|
|||
|
console.log(`🪣 检查存储桶 "${bucketName}"...`);
|
|||
|
|
|||
|
try {
|
|||
|
await s3Client.headBucket({ Bucket: bucketName });
|
|||
|
console.log(`✅ 存储桶 "${bucketName}" 存在`);
|
|||
|
} catch (error) {
|
|||
|
if (error.name === 'NotFound') {
|
|||
|
console.log(`❌ 存储桶 "${bucketName}" 不存在,正在创建...`);
|
|||
|
try {
|
|||
|
await s3Client.createBucket({ Bucket: bucketName });
|
|||
|
console.log(`✅ 存储桶 "${bucketName}" 创建成功`);
|
|||
|
} catch (createError) {
|
|||
|
console.log(`❌ 创建存储桶失败:`, createError.message);
|
|||
|
return;
|
|||
|
}
|
|||
|
} else {
|
|||
|
console.log(`❌ 检查存储桶失败:`, error.message);
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 3. 测试简单上传
|
|||
|
console.log('\n📤 测试简单上传...');
|
|||
|
const testKey = 'test-file.txt';
|
|||
|
const testContent = 'Hello MinIO!';
|
|||
|
|
|||
|
try {
|
|||
|
await s3Client.putObject({
|
|||
|
Bucket: bucketName,
|
|||
|
Key: testKey,
|
|||
|
Body: testContent,
|
|||
|
});
|
|||
|
console.log(`✅ 简单上传成功: ${testKey}`);
|
|||
|
} catch (error) {
|
|||
|
console.log(`❌ 简单上传失败:`, error.message);
|
|||
|
console.log('错误详情:', error);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// 4. 测试分片上传初始化
|
|||
|
console.log('\n🔄 测试分片上传初始化...');
|
|||
|
const multipartKey = 'test-multipart.txt';
|
|||
|
|
|||
|
try {
|
|||
|
const multipartUpload = await s3Client.createMultipartUpload({
|
|||
|
Bucket: bucketName,
|
|||
|
Key: multipartKey,
|
|||
|
});
|
|||
|
console.log(`✅ 分片上传初始化成功: ${multipartUpload.UploadId}`);
|
|||
|
|
|||
|
// 立即取消这个分片上传
|
|||
|
await s3Client.abortMultipartUpload({
|
|||
|
Bucket: bucketName,
|
|||
|
Key: multipartKey,
|
|||
|
UploadId: multipartUpload.UploadId,
|
|||
|
});
|
|||
|
console.log('✅ 分片上传取消成功');
|
|||
|
} catch (error) {
|
|||
|
console.log(`❌ 分片上传初始化失败:`, error.message);
|
|||
|
console.log('错误详情:', error);
|
|||
|
if (error.$metadata) {
|
|||
|
console.log('HTTP状态码:', error.$metadata.httpStatusCode);
|
|||
|
}
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
console.log('\n🎉 所有测试通过!MinIO配置正确。');
|
|||
|
} catch (error) {
|
|||
|
console.log('❌ 连接失败:', error.message);
|
|||
|
console.log('错误详情:', error);
|
|||
|
|
|||
|
if (error.message.includes('ECONNREFUSED')) {
|
|||
|
console.log('\n💡 提示:');
|
|||
|
console.log('- 确保MinIO正在端口9000运行');
|
|||
|
console.log('- 检查docker容器状态: docker ps');
|
|||
|
console.log('- 重启MinIO: docker restart minio-container-name');
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
debugMinIO().catch(console.error);
|