129 lines
2.9 KiB
Go
129 lines
2.9 KiB
Go
package config
|
|
|
|
// SunHPC 主配置
|
|
type SunHPCConfig struct {
|
|
Hostname string `yaml:"hostname"`
|
|
MOTD string `yaml:"motd"`
|
|
Sysctl map[string]string `yaml:"sysctl"`
|
|
SELinux string `yaml:"selinux"` // enforcing, permissive, disabled
|
|
SSH SSHConfig `yaml:"ssh"`
|
|
}
|
|
|
|
type SSHConfig struct {
|
|
PermitRootLogin string `yaml:"permit_root_login"`
|
|
PasswordAuth string `yaml:"password_authentication"`
|
|
}
|
|
|
|
func DefaultSunHPC() *SunHPCConfig {
|
|
return &SunHPCConfig{
|
|
Hostname: "sunhpc-master",
|
|
MOTD: "Welcome to SunHPC Cluster\n",
|
|
Sysctl: map[string]string{
|
|
"net.ipv4.ip_forward": "1",
|
|
"vm.swappiness": "10",
|
|
},
|
|
SELinux: "enforcing",
|
|
SSH: SSHConfig{
|
|
PermitRootLogin: "yes",
|
|
PasswordAuth: "yes",
|
|
},
|
|
}
|
|
}
|
|
|
|
// Nodes 节点配置
|
|
type NodesConfig struct {
|
|
Nodes []Node `yaml:"nodes"`
|
|
}
|
|
|
|
type Node struct {
|
|
Hostname string `yaml:"hostname"`
|
|
MAC string `yaml:"mac"`
|
|
IP string `yaml:"ip"`
|
|
Role string `yaml:"role"` // master, compute, login
|
|
}
|
|
|
|
func DefaultNodes() *NodesConfig {
|
|
return &NodesConfig{
|
|
Nodes: []Node{
|
|
{Hostname: "master", MAC: "00:11:22:33:44:55", IP: "192.168.1.1", Role: "master"},
|
|
},
|
|
}
|
|
}
|
|
|
|
// Network 网络配置
|
|
type NetworkConfig struct {
|
|
Interface string `yaml:"interface"`
|
|
Subnet string `yaml:"subnet"`
|
|
Netmask string `yaml:"netmask"`
|
|
Gateway string `yaml:"gateway"`
|
|
DNSServers []string `yaml:"dns_servers"`
|
|
}
|
|
|
|
func DefaultNetwork() *NetworkConfig {
|
|
return &NetworkConfig{
|
|
Interface: "eth0",
|
|
Subnet: "192.168.1.0",
|
|
Netmask: "255.255.255.0",
|
|
Gateway: "192.168.1.1",
|
|
DNSServers: []string{"8.8.8.8", "114.114.114.114"},
|
|
}
|
|
}
|
|
|
|
// Disks 磁盘配置
|
|
type DisksConfig struct {
|
|
Disks []Disk `yaml:"disks"`
|
|
}
|
|
|
|
type Disk struct {
|
|
Device string `yaml:"device"`
|
|
Mount string `yaml:"mount"`
|
|
FSType string `yaml:"fstype"`
|
|
Options string `yaml:"options"`
|
|
}
|
|
|
|
func DefaultDisks() *DisksConfig {
|
|
return &DisksConfig{
|
|
Disks: []Disk{
|
|
{Device: "/dev/sda1", Mount: "/", FSType: "ext4", Options: "defaults"},
|
|
},
|
|
}
|
|
}
|
|
|
|
// Services 服务配置
|
|
type ServicesConfig struct {
|
|
HTTPD Service `yaml:"httpd"`
|
|
TFTPD Service `yaml:"tftpd"`
|
|
DHCPD Service `yaml:"dhcpd"`
|
|
}
|
|
|
|
type Service struct {
|
|
Enabled bool `yaml:"enabled"`
|
|
Config string `yaml:"config,omitempty"`
|
|
}
|
|
|
|
func DefaultServices() *ServicesConfig {
|
|
return &ServicesConfig{
|
|
HTTPD: Service{Enabled: true},
|
|
TFTPD: Service{Enabled: true},
|
|
DHCPD: Service{Enabled: true},
|
|
}
|
|
}
|
|
|
|
// Firewall 防火墙配置
|
|
type FirewallConfig struct {
|
|
DefaultPolicy string `yaml:"default_policy"`
|
|
Rules []string `yaml:"rules"`
|
|
}
|
|
|
|
func DefaultFirewall() *FirewallConfig {
|
|
return &FirewallConfig{
|
|
DefaultPolicy: "DROP",
|
|
Rules: []string{
|
|
"-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT",
|
|
"-A INPUT -p icmp -j ACCEPT",
|
|
"-A INPUT -i lo -j ACCEPT",
|
|
"-A INPUT -p tcp --dport 22 -j ACCEPT",
|
|
},
|
|
}
|
|
}
|