安装开发环境
确保你的操作系统已经安装了必要的软件工具:
- Linux(推荐CentOS 7+或Ubuntu 20.04+)
yum update -y yum install -y gcc make autoconf libtool cmake build-essential yum install -y docker-compose docker yum install -y mysql-server yum install -y nodejs yum install -y python3
- Windows
- 安装Visual Studio Code或Notepad++等文本编辑器。
- 安装Node.js。
- 安装MySQL Community Server。
- MacOS
- 使用Homebrew安装工具。
- 安装Node.js。
- 安装MySQL Community Server。
配置MySQL数据库
创建一个新的数据库,命名为v2ray_node,并使用以下SQL语句创建表结构:
CREATE DATABASE v2ray_node;
USE v2ray_node;
CREATE TABLE nodes (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
port INT NOT NULL,
weight INT DEFAULT 1,
type VARCHAR(50) NOT NULL,
status VARCHAR(20) DEFAULT 'online' COMMENT '可选值:online, offline, blocked',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
role ENUM('admin', 'user') DEFAULT 'user',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE logs (
id INT PRIMARY KEY AUTO_INCREMENT,
node_id INT NOT NULL,
log_time DATETIME NOT NULL,
content TEXT NOT NULL,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP
);
编写管理系统代码
开发一个基于React的前端和Spring Boot的后端。
前端:React管理界面
// src/App.js
import React, { useState, useEffect } from 'react';
import axios from 'axios';
function App() {
const [nodes, setNodes] = useState([]);
const [users, setUsers] = useState([]);
const [newNode, setNewNode] = useState({
name: '',
address: 'localhost',
port: 108,
type: 'http'
});
useEffect(() => {
loadNodes();
loadUsers();
}, []);
const loadNodes = async () => {
try {
const response = await axios.get('http://localhost:808/api/nodes');
setNodes(response.data);
} catch (error) {
console.error('加载节点失败:', error);
}
};
const loadUsers = async () => {
try {
const response = await axios.get('http://localhost:808/api/users');
setUsers(response.data);
} catch (error) {
console.error('加载用户失败:', error);
}
};
const handleAddNode = async () => {
try {
const { name, address, port, type } = newNode;
const response = await axios.post('http://localhost:808/api/nodes', {
name,
address,
port,
type
});
setNodes([...nodes, response.data]);
setNewNode({
name: '',
address: 'localhost',
port: 108,
type: 'http'
});
} catch (error) {
console.error('添加节点失败:', error);
}
};
return (
<div>
<h1> V2Ray节点管理系统</h1>
<div>
<button onClick={handleAddNode}>添加节点</button>
</div>
<table>
<thead>
<tr>
<th>名称</th>
<th>地址</th>
<th>端口</th>
<th>类型</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{nodes.map(node => (
<tr key={node.id}>
<td>{node.name}</td>
<td>{node.address}</td>
<td>{node.port}</td>
<td>{node.type}</td>
<td>{node.status}</td>
<td>
<button onClick={() => handleEditNode(node.id)}>编辑</button>
<button onClick={() => handleDeleteNode(node.id)}>删除</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
function handleEditNode(id) {
// edit logic
}
function handleDeleteNode(id) {
// delete logic
}
export default App;
后端:Spring Boot服务
// MainApplication.java
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
// UserController.java
@RestController
public class UserController {
@Autowired
private UserRepository userRepository;
@GetMapping("/api/users")
public List<User> getUsers() {
return userRepository.findAll();
}
}
// NodeController.java
@RestController
public class NodeController {
@Autowired
private NodeRepository nodeRepository;
@GetMapping("/api/nodes")
public List<Node> getNodes() {
return nodeRepository.findAll();
}
@PostMapping("/api/nodes")
public Node addNode(@RequestBody Node node) {
nodeRepository.save(node);
return node;
}
}
// Repository classes
public class NodeRepository extends JpaRepository<Node, Long> {}
public class UserRepository extends JpaRepository<User, Long> {}
确保前后端的API端点正确配置,并且能够互相通信。
部署系统
使用Docker构建和部署:
Dockerfile
FROM java:8
VOLUME /data
WORKDIR /app
ADD . /app
RUN apt-get update && apt-get install -y --no-install-recommends \
mysql-client \
&& rm -rf /var/lib/apt/lists/*
EXPOSE 808
CMD ["java", "-jar", "target/main.jar"]
Nginx配置
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:808;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
运行命令:
docker build -t v2ray-node-manager . docker run -d -p 808:808 -p 80:80 v2ray-node-manager
测试和验证
使用Postman测试API:
- POST http://localhost:808/api/nodes - 添加节点
- GET http://localhost:808/api/nodes - 获取所有节点
- GET http://localhost:80 - 测试前端页面
性能测试使用JMeter:
java -jar jmeter.bin
维护和优化
- 定期备份数据库:
mysqldump -u root -p v2ray_node > v2ray_node.sql
- 使用日志工具(如ELK)处理日志
- 定期检查系统性能,优化数据库查询和API响应
- 定期清理旧节点和日志
扩展功能
- 节点监控:添加CPU、内存使用率的监控
- 告警系统:设置阈值触发警报
- 用户权限管理:实现分级权限控制
- 配置中心:使用配置中心存储敏感信息
通过以上步骤,你可以成功创建一个功能完善的V2Ray节点管理系统,满足日常的节点管理和监控需求。




