1Panel - 现代化Linux服务器运维管理面板
项目描述
1Panel是一款功能强大的基于Web的Linux服务器管理面板,被评为顶级VPS控制面板和最佳Linux服务器运维管理工具。项目采用GPL v3开源协议,提供完整的服务器运维解决方案,包括网站管理、数据库管理、容器管理、监控告警、备份恢复等核心功能。
功能特性
- 网站管理: 支持PHP网站、静态网站、反向代理等多种网站类型,提供SSL证书管理和域名绑定
- 数据库管理: 支持MySQL、PostgreSQL、Redis等数据库的创建、管理和监控
- 容器管理: 完整的Docker容器生命周期管理,支持Compose模板和镜像仓库
- 应用商店: 提供丰富的应用一键部署,支持应用更新和忽略管理
- 监控告警: 系统资源监控、自定义告警规则和多种通知方式
- 备份恢复: 支持本地和云端备份,提供完整的备份策略和恢复方案
- 安全防护: 内置防火墙、Fail2ban防护、病毒扫描等安全功能
- 文件管理: 完整的文件管理器,支持在线编辑、压缩解压和权限管理
安装指南
系统要求
- 操作系统: Linux (推荐 Ubuntu/CentOS)
- 内存: 至少1GB RAM
- 磁盘空间: 至少10GB可用空间
- 网络: 需要互联网连接以下载依赖
快速安装
# 使用官方安装脚本
curl -sSL https://resource.1panel.pro/install/install.sh | bash# 或者下载离线安装包
wget https://github.com/1Panel-dev/1Panel/releases/latest/download/1panel.linux.amd64.tar.gz
tar -zxvf 1panel.linux.amd64.tar.gz
cd 1panel
./install.sh
Docker安装
docker run -d --name 1panel \-p 8888:8888 \-v /var/run/docker.sock:/var/run/docker.sock \-v /opt/1panel:/app/data \1panel/1panel:latest
使用说明
基础使用示例
创建网站
# 通过API创建网站
curl -X POST http://localhost:8888/api/v1/websites \-H "Content-Type: application/json" \-d '{"type": "php","alias": "my-website","domains": [{"domain": "example.com"}],"runtimeID": 1}'
部署MySQL数据库
// 通过Go代码创建MySQL数据库
func CreateMySQLDatabase() error {req := dto.MysqlDBCreate{Name: "my_database",From: "local",Database: "mysql",Format: "utf8mb4",Username: "db_user",Password: "secure_password",}client := &http.Client{}data, _ := json.Marshal(req)request, _ := http.NewRequest("POST", "http://localhost:8888/api/v1/databases/mysql", bytes.NewBuffer(data))request.Header.Set("Content-Type", "application/json")resp, err := client.Do(request)if err != nil {return err}defer resp.Body.Close()return nil
}
容器管理示例
# docker-compose.yml示例
version: '3'
services:nginx:image: nginx:latestports:- "80:80"volumes:- ./nginx.conf:/etc/nginx/nginx.conf
API概览
1Panel提供完整的RESTful API接口,涵盖所有管理功能:
- 认证API: 用户登录、权限管理
- 网站API: 网站创建、域名管理、SSL证书
- 数据库API: 数据库管理、用户权限、备份恢复
- 容器API: Docker管理、镜像仓库、Compose模板
- 监控API: 系统监控、告警设置、日志查询
- 文件API: 文件管理、在线编辑、权限设置
核心代码
网站创建核心代码
// @Tags Website
// @Summary Create website
// @Accept json
// @Param request body request.WebsiteCreate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /websites [post]
func (b *BaseApi) CreateWebsite(c *gin.Context) {var req request.WebsiteCreateif err := helper.CheckBindAndValidate(&req, c); err != nil {return}if err := websiteService.Create(req); err != nil {helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrInternalServer, err)return}helper.Success(c)
}
数据库管理核心代码
// @Tags Database MySQL
// @Summary Create mysql database
// @Accept json
// @Param request body dto.MysqlDBCreate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /databases/mysql [post]
func (b *BaseApi) CreateMySQLDatabase(c *gin.Context) {var req dto.MysqlDBCreateif err := helper.CheckBindAndValidate(&req, c); err != nil {return}if len(req.Password) != 0 {password, err := base64.StdEncoding.DecodeString(req.Password)if err != nil {helper.BadRequest(c, err)return}req.Password = string(password)}if _, err := mysqlService.Create(context.Background(), req); err != nil {helper.InternalServer(c, err)return}helper.Success(c)
}
容器操作核心代码
// @Tags Container
// @Summary Page containers
// @Accept json
// @Param request body dto.PageContainer true "request"
// @Produce json
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /containers/search [post]
func (b *BaseApi) SearchContainer(c *gin.Context) {var req dto.PageContainerif err := helper.CheckBindAndValidate(&req, c); err != nil {return}total, list, err := containerService.Page(req)if err != nil {helper.InternalServer(c, err)return}helper.SuccessWithData(c, dto.PageResult{Items: list,Total: total,})
}
监控告警核心代码
// @Tags Monitor
// @Summary Load monitor data
// @Param request body dto.MonitorSearch true "request"
// @Success 200 {array} dto.MonitorData
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /monitor/data [post]
func (b *BaseApi) LoadMonitorData(c *gin.Context) {var req dto.MonitorSearchif err := helper.CheckBindAndValidate(&req, c); err != nil {return}data, err := monitorService.LoadMonitorData(req)if err != nil {helper.InternalServer(c, err)return}helper.SuccessWithData(c, data)
}
文件管理核心代码
// @Tags File
// @Summary List files
// @Accept json
// @Param request body request.FileOption true "request"
// @Success 200 {object} response.FileInfo
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /files/search [post]
func (b *BaseApi) ListFiles(c *gin.Context) {var req request.FileOptionif err := helper.CheckBindAndValidate(&req, c); err != nil {return}fileList, err := fileService.GetFileList(req)if err != nil {helper.InternalServer(c, err)return}helper.SuccessWithData(c, fileList)
}
这些核心代码展示了1Panel的主要功能模块实现,包括API路由定义、参数验证、服务调用和响应处理,体现了项目的高代码质量和良好的架构设计。
更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
公众号二维码