修改成redis
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
# ============================================
|
||||
# sese-engine 配置文件示例
|
||||
# ============================================
|
||||
|
||||
index:
|
||||
max_urls_per_key: 11000 # 每个关键词最大URL数量
|
||||
max_same_domain_per_key: 20 # 每个关键词同域名最大数量
|
||||
big_clean_threshold: 2000000 # 大清理阈值
|
||||
max_new_urls_per_key: 10000 # 每个关键词最大新增URL
|
||||
min_urls_for_new_key: 3 # 新关键词最小URL数量
|
||||
|
||||
crawler:
|
||||
spider_name: "Haibara_AI_spider" # 爬虫名称
|
||||
cooldown: 3 # 请求间隔(秒)
|
||||
workers: 22 # 并发数
|
||||
crawl_focus: 0.7 # 爬取聚焦系数
|
||||
max_keywords_per_page: 250 # 每页最大关键词数
|
||||
max_epoch: 100 # 最大轮数
|
||||
expected_prosper_ratio: 0.6 # 期望繁荣值比例
|
||||
entry_url: "https://haibara.ai/" # 入口URL
|
||||
max_page_size: 5242880 # 单页最大5MB
|
||||
recrawl_max_age: 2592000 # 重爬过期30天
|
||||
recrawl_check_interval: 3600 # 检查间隔1小时
|
||||
recrawl_batch_size: 500 # 每批500个
|
||||
max_priority_children: 100 # 优先队列子链接上限
|
||||
|
||||
search:
|
||||
use_online_snippet: true
|
||||
online_snippet_timeout: 3
|
||||
weight_daily_decay: 0.996
|
||||
language_weight: 0.5
|
||||
consecutive_key_weight: 1.3
|
||||
backlink_weight: 1.0
|
||||
server_port: 50082
|
||||
flush_interval_seconds: 300
|
||||
stats_refresh_interval: 30
|
||||
miss_penalty: 0.15
|
||||
unix_socket: "" # Unix Socket路径(可选)
|
||||
|
||||
backlink:
|
||||
baseline: 200000 # 反链基准值
|
||||
|
||||
storage:
|
||||
path: "./savedata" # 存储路径
|
||||
|
||||
# ============================================
|
||||
# MySQL 配置(默认关闭,启用时需设置 enabled: true)
|
||||
# ============================================
|
||||
# 支持两种连接方式:Unix Socket 和 TCP
|
||||
# 优先级:UnixSocket > TCP(如果UnixSocket非空则优先使用)
|
||||
mysql:
|
||||
# 是否启用 MySQL(默认 false,不启用则不连接、不刷盘)
|
||||
enabled: false
|
||||
|
||||
# 连接方式(可选,默认tcp,可设为 "socket" 或 "tcp")
|
||||
# network: "tcp"
|
||||
|
||||
# ----- Unix Socket 连接(推荐,本地MySQL性能更好)-----
|
||||
# 设置为 MySQL socket 路径即可,TCP配置将被忽略
|
||||
unix_socket: "/var/run/mysqld/mysqld.sock"
|
||||
# unix_socket: "/tmp/mysql.sock" # macOS 常见路径
|
||||
# unix_socket: "" # 留空则使用TCP连接
|
||||
|
||||
# ----- TCP 连接 -----
|
||||
host: "localhost"
|
||||
port: 3306
|
||||
|
||||
# ----- 认证信息 -----
|
||||
user: "root"
|
||||
password: "your_password_here"
|
||||
database: "sese_engine"
|
||||
|
||||
# ----- 连接池配置 -----
|
||||
conn_max_lifetime: 3600 # 连接最大生命周期(秒),默认1小时
|
||||
max_idle_conns: 10 # 最大空闲连接数
|
||||
max_open_conns: 100 # 最大打开连接数
|
||||
|
||||
# ============================================
|
||||
# Redis 配置
|
||||
# ============================================
|
||||
# 支持两种连接方式:Unix Socket 和 TCP
|
||||
# 优先级:UnixSocket > TCP(如果UnixSocket非空则优先使用)
|
||||
redis:
|
||||
# 连接方式(可选,默认tcp)
|
||||
# network: "tcp"
|
||||
|
||||
# ----- Unix Socket 连接(推荐,本地Redis性能更好)-----
|
||||
# 设置为 Redis socket 路径即可,TCP配置将被忽略
|
||||
unix_socket: "/var/run/redis/redis.sock"
|
||||
# unix_socket: "/tmp/redis.sock" # macOS 常见路径
|
||||
# unix_socket: "" # 留空则使用TCP连接
|
||||
|
||||
# ----- TCP 连接 -----
|
||||
host: "localhost"
|
||||
port: 6379
|
||||
|
||||
# ----- 认证信息(无密码则留空)-----
|
||||
password: ""
|
||||
|
||||
# ----- 数据库配置 -----
|
||||
# 数据库编号(0-15),默认使用15号数据库
|
||||
db: 15
|
||||
|
||||
# ----- 连接池配置 -----
|
||||
pool_size: 100 # 连接池最大连接数
|
||||
min_idle_conns: 10 # 最小空闲连接数
|
||||
|
||||
# ----- 超时配置(毫秒)-----
|
||||
read_timeout: 500 # 读超时
|
||||
write_timeout: 500 # 写超时
|
||||
|
||||
prometheus:
|
||||
crawler_port: 14950
|
||||
backlink_port: 14952
|
||||
search_port: 14953
|
||||
@@ -23,6 +23,8 @@ type Config struct {
|
||||
Search SearchConfig `yaml:"search"`
|
||||
Backlink BacklinkConfig `yaml:"backlink"`
|
||||
Storage StorageConfig `yaml:"storage"`
|
||||
MySQL MySQLConfig `yaml:"mysql"`
|
||||
Redis RedisConfig `yaml:"redis"`
|
||||
Prometheus PrometheusConfig `yaml:"prometheus"`
|
||||
}
|
||||
|
||||
@@ -77,6 +79,62 @@ type StorageConfig struct {
|
||||
Path string `yaml:"path"`
|
||||
}
|
||||
|
||||
// MySQLConfig MySQL数据库连接配置
|
||||
// 支持两种连接方式:Unix Socket 和 TCP
|
||||
// 优先级:UnixSocket > TCP(如果UnixSocket非空则优先使用)
|
||||
type MySQLConfig struct {
|
||||
// 是否启用 MySQL(默认关闭)
|
||||
Enabled bool `yaml:"enabled"`
|
||||
// 连接方式: "socket" 或 "tcp"(自动推断,可不填)
|
||||
Network string `yaml:"network"`
|
||||
// Unix Socket 路径(Linux/macOS),优先使用
|
||||
// 示例: "/var/run/mysqld/mysqld.sock" 或 "/tmp/mysql.sock"
|
||||
UnixSocket string `yaml:"unix_socket"`
|
||||
// TCP 连接方式:服务器地址
|
||||
Host string `yaml:"host"`
|
||||
// TCP 连接方式:端口号
|
||||
Port int `yaml:"port"`
|
||||
// 用户名
|
||||
User string `yaml:"user"`
|
||||
// 密码
|
||||
Password string `yaml:"password"`
|
||||
// 数据库名
|
||||
Database string `yaml:"database"`
|
||||
// 连接超时时间(秒)
|
||||
ConnMaxLifetime int `yaml:"conn_max_lifetime"` // 秒
|
||||
// 最大空闲连接数
|
||||
MaxIdleConns int `yaml:"max_idle_conns"`
|
||||
// 最大打开连接数
|
||||
MaxOpenConns int `yaml:"max_open_conns"`
|
||||
}
|
||||
|
||||
// RedisConfig Redis连接配置
|
||||
// 支持两种连接方式:Unix Socket 和 TCP
|
||||
// 优先级:UnixSocket > TCP(如果UnixSocket非空则优先使用)
|
||||
type RedisConfig struct {
|
||||
// 连接方式: "socket" 或 "tcp"(自动推断,可不填)
|
||||
Network string `yaml:"network"`
|
||||
// Unix Socket 路径,优先使用
|
||||
// 示例: "/var/run/redis/redis.sock" 或 "/tmp/redis.sock"
|
||||
UnixSocket string `yaml:"unix_socket"`
|
||||
// TCP 连接方式:服务器地址
|
||||
Host string `yaml:"host"`
|
||||
// TCP 连接方式:端口号
|
||||
Port int `yaml:"port"`
|
||||
// 密码(无密码则留空)
|
||||
Password string `yaml:"password"`
|
||||
// 数据库编号(0-15),默认 15
|
||||
DB int `yaml:"db"`
|
||||
// 池大小(最大连接数)
|
||||
PoolSize int `yaml:"pool_size"`
|
||||
// 最小空闲连接数
|
||||
MinIdleConns int `yaml:"min_idle_conns"`
|
||||
// 读超时时间(毫秒)
|
||||
ReadTimeout int `yaml:"read_timeout"` // 毫秒
|
||||
// 写超时时间(毫秒)
|
||||
WriteTimeout int `yaml:"write_timeout"` // 毫秒
|
||||
}
|
||||
|
||||
// PrometheusConfig Prometheus监控端口配置
|
||||
type PrometheusConfig struct {
|
||||
CrawlerPort int `yaml:"crawler_port"`
|
||||
@@ -217,6 +275,31 @@ func GetDefaultConfig() Config {
|
||||
Storage: StorageConfig{
|
||||
Path: "./savedata",
|
||||
},
|
||||
MySQL: MySQLConfig{
|
||||
Enabled: false,
|
||||
Network: "tcp",
|
||||
UnixSocket: "",
|
||||
Host: "localhost",
|
||||
Port: 3306,
|
||||
User: "root",
|
||||
Password: "",
|
||||
Database: "sese_engine",
|
||||
ConnMaxLifetime: 3600, // 1小时
|
||||
MaxIdleConns: 10,
|
||||
MaxOpenConns: 100,
|
||||
},
|
||||
Redis: RedisConfig{
|
||||
Network: "tcp",
|
||||
UnixSocket: "",
|
||||
Host: "localhost",
|
||||
Port: 6379,
|
||||
Password: "",
|
||||
DB: 15, // 默认使用15号数据库
|
||||
PoolSize: 100,
|
||||
MinIdleConns: 10,
|
||||
ReadTimeout: 500, // 毫秒
|
||||
WriteTimeout: 500, // 毫秒
|
||||
},
|
||||
Prometheus: PrometheusConfig{
|
||||
CrawlerPort: 14950,
|
||||
BacklinkPort: 14952,
|
||||
@@ -357,3 +440,113 @@ func MaxPriorityChildren() int {
|
||||
|
||||
// 为了向后兼容,保留 StoragePath 常量
|
||||
const StoragePath = "./savedata"
|
||||
|
||||
// ---- MySQL 配置访问函数 ----
|
||||
|
||||
// MySQLEnabled 返回是否启用 MySQL(默认关闭)
|
||||
func MySQLEnabled() bool {
|
||||
return Global.MySQL.Enabled
|
||||
}
|
||||
|
||||
// MySQLDSN 返回 MySQL 连接字符串(DSN)
|
||||
// 根据配置自动选择 Unix Socket 或 TCP 方式
|
||||
func MySQLDSN() string {
|
||||
cfg := Global.MySQL
|
||||
if cfg.UnixSocket != "" {
|
||||
// 使用 Unix Socket 连接(推荐,本地连接性能更好)
|
||||
return cfg.User + ":" + cfg.Password + "@unix(" + cfg.UnixSocket + ")/" + cfg.Database + "?parseTime=true&loc=Local"
|
||||
}
|
||||
// 使用 TCP 连接
|
||||
return cfg.User + ":" + cfg.Password + "@tcp(" + cfg.Host + ":" + itoa(cfg.Port) + ")/" + cfg.Database + "?parseTime=true&loc=Local"
|
||||
}
|
||||
|
||||
// MySQLConnMaxLifetime 返回连接最大生命周期(秒)
|
||||
func MySQLConnMaxLifetime() int {
|
||||
if Global.MySQL.ConnMaxLifetime <= 0 {
|
||||
return 3600
|
||||
}
|
||||
return Global.MySQL.ConnMaxLifetime
|
||||
}
|
||||
|
||||
// MySQLMaxIdleConns 返回最大空闲连接数
|
||||
func MySQLMaxIdleConns() int {
|
||||
if Global.MySQL.MaxIdleConns <= 0 {
|
||||
return 10
|
||||
}
|
||||
return Global.MySQL.MaxIdleConns
|
||||
}
|
||||
|
||||
// MySQLMaxOpenConns 返回最大打开连接数
|
||||
func MySQLMaxOpenConns() int {
|
||||
if Global.MySQL.MaxOpenConns <= 0 {
|
||||
return 100
|
||||
}
|
||||
return Global.MySQL.MaxOpenConns
|
||||
}
|
||||
|
||||
// ---- Redis 配置访问函数 ----
|
||||
|
||||
// RedisAddr 返回 Redis 连接地址
|
||||
// 根据配置自动选择 Unix Socket 或 TCP 方式
|
||||
func RedisAddr() string {
|
||||
cfg := Global.Redis
|
||||
if cfg.UnixSocket != "" {
|
||||
return cfg.UnixSocket
|
||||
}
|
||||
return cfg.Host + ":" + itoa(cfg.Port)
|
||||
}
|
||||
|
||||
// RedisPoolSize 返回连接池大小
|
||||
func RedisPoolSize() int {
|
||||
if Global.Redis.PoolSize <= 0 {
|
||||
return 100
|
||||
}
|
||||
return Global.Redis.PoolSize
|
||||
}
|
||||
|
||||
// RedisMinIdleConns 返回最小空闲连接数
|
||||
func RedisMinIdleConns() int {
|
||||
if Global.Redis.MinIdleConns <= 0 {
|
||||
return 10
|
||||
}
|
||||
return Global.Redis.MinIdleConns
|
||||
}
|
||||
|
||||
// RedisDB 返回数据库编号
|
||||
func RedisDB() int {
|
||||
return Global.Redis.DB
|
||||
}
|
||||
|
||||
// RedisPassword 返回密码(空字符串表示无密码)
|
||||
func RedisPassword() string {
|
||||
return Global.Redis.Password
|
||||
}
|
||||
|
||||
// RedisReadTimeout 返回读超时时间(毫秒)
|
||||
func RedisReadTimeout() int {
|
||||
if Global.Redis.ReadTimeout <= 0 {
|
||||
return 500
|
||||
}
|
||||
return Global.Redis.ReadTimeout
|
||||
}
|
||||
|
||||
// RedisWriteTimeout 返回写超时时间(毫秒)
|
||||
func RedisWriteTimeout() int {
|
||||
if Global.Redis.WriteTimeout <= 0 {
|
||||
return 500
|
||||
}
|
||||
return Global.Redis.WriteTimeout
|
||||
}
|
||||
|
||||
// itoa 将 int 转换为字符串(避免导入 strconv)
|
||||
func itoa(n int) string {
|
||||
if n == 0 {
|
||||
return "0"
|
||||
}
|
||||
result := ""
|
||||
for n > 0 {
|
||||
result = string(rune('0'+n%10)) + result
|
||||
n /= 10
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user