Subversion Repositories havirt

Rev

Rev 28 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
47 rodolico 1
# havirt - High Availability Virtual Machine Cluster Manager
23 rodolico 2
 
47 rodolico 3
## Overview
9 rodolico 4
 
47 rodolico 5
**havirt** is a cluster management tool for KVM/libvirt hypervisors with shared storage. It provides safe, automated management of virtual machines across multiple nodes with resource validation, maintenance mode support, and automatic load balancing.
26 rodolico 6
 
47 rodolico 7
### Key Features
26 rodolico 8
 
47 rodolico 9
- **Cluster-wide VM management** - Start, stop, and migrate VMs across nodes
10
- **Resource validation** - Prevents over-allocation of CPU and memory
11
- **Safety controls** - Prevents running the same VM on multiple nodes (avoids data corruption)
12
- **Maintenance mode** - Automatically evacuate VMs from nodes requiring maintenance
13
- **Load balancing** - Automatically distribute VMs across nodes based on resource usage
14
- **Centralized configuration** - Share VM configs across all nodes via NFS
15
- **Testing mode** - Safe testing without affecting production systems
9 rodolico 16
 
47 rodolico 17
## Requirements
9 rodolico 18
 
47 rodolico 19
- **Multiple hypervisors** running KVM/libvirt (tested on Devuan/Debian Linux)
20
- **Shared block storage** (iSCSI or similar) accessible from all nodes
21
- **NFS share** mounted at the same path on all nodes (file locking required)
22
- **SSH public key authentication** between all nodes (passwordless)
23
- **Perl modules**: `Data::Dumper`, `YAML::Tiny`, `FindBin`
9 rodolico 24
 
47 rodolico 25
## Quick Start
9 rodolico 26
 
47 rodolico 27
### Installation
23 rodolico 28
 
47 rodolico 29
1. Check out from repository to shared NFS mount:
30
   ```bash
31
   svn co http://svn.dailydata.net/svn/havirt/stable /media/shared/havirt
32
   ```
9 rodolico 33
 
47 rodolico 34
2. Create symlink on each node:
35
   ```bash
36
   ln -s /media/shared/havirt/havirt /usr/local/bin/havirt
37
   ```
9 rodolico 38
 
47 rodolico 39
3. Install dependencies:
40
   ```bash
41
   apt install -y libdata-dump-perl libyaml-tiny-perl
42
   ```
26 rodolico 43
 
47 rodolico 44
4. Generate initial config:
45
   ```bash
46
   havirt
47
   ```
48
   This creates `config.yaml` with safe defaults (dry-run mode enabled)
28 rodolico 49
 
47 rodolico 50
### Initial Setup
51
 
52
See [INSTALL.md](INSTALL.md) for complete installation instructions including:
53
- SSH key setup for passwordless authentication
54
- NFS configuration requirements
55
- Node registration
56
- VM configuration storage
57
 
58
## Common Tasks
59
 
60
### Daily Operations
61
 
62
**Scan cluster for running VMs:**
63
```bash
64
havirt node scan --force
65
```
66
 
67
**List all nodes and their resources:**
68
```bash
69
havirt node list
70
```
71
 
72
**List all VMs:**
73
```bash
74
havirt domain list
75
```
76
 
77
**Start a VM on a specific node:**
78
```bash
79
havirt domain start vmname nodename
80
```
81
 
82
**Migrate VM to another node:**
83
```bash
84
havirt domain migrate vmname targetnode
85
```
86
 
87
**Shutdown a VM gracefully:**
88
```bash
89
havirt domain shutdown vmname
90
```
91
 
92
### Maintenance Operations
93
 
94
**Put node in maintenance mode (evacuates all VMs):**
95
```bash
96
havirt node maintenance nodename 1
97
```
98
 
99
**Take node out of maintenance:**
100
```bash
101
havirt node maintenance nodename 0
102
```
103
 
104
**Balance cluster (redistribute VMs):**
105
```bash
106
havirt cluster balance
107
```
108
 
109
**Check cluster statistics:**
110
```bash
111
havirt cluster stats
112
```
113
 
114
### Adding New VMs
115
 
116
1. Generate a virt-install template:
117
   ```bash
118
   havirt domain new myvm
119
   ```
120
 
121
2. Create the VM using the generated command
122
 
123
3. Scan to discover the new VM:
124
   ```bash
125
   havirt node scan --force
126
   ```
127
 
128
4. Update VM metadata:
129
   ```bash
130
   havirt domain update myvm
131
   ```
132
 
133
## Configuration
134
 
135
### config.yaml
136
 
137
The configuration file is auto-generated at first run. Key settings:
138
 
139
```yaml
140
flags:
141
  dryrun: 1          # Set to 0 to execute commands (default=1 for safety)
142
  verbose: 1         # Show detailed output
143
  debug: 0           # Debug level (0-3)
144
  testing: 0         # Use test data instead of live systems
145
 
146
node reserved memory: 8388608   # Reserve 8GB per node
147
min scan time: 300              # Minimum seconds between scans
148
```
149
 
150
### Directory Structure
151
 
152
```
153
havirt/
154
├── havirt              # Main executable
155
├── *.pm                # Module files (cluster, domain, node)
156
├── config.yaml         # Configuration (auto-generated)
157
├── conf/               # VM XML configurations (shared across nodes)
158
├── var/                # Runtime data
159
│   ├── status.yaml     # Cluster state database
160
│   └── lastscan        # Last scan timestamp
161
└── tests/              # Test suite
162
```
163
 
164
## Safety Features
165
 
166
### Dry-Run Mode (Default)
167
 
168
By default, havirt operates in dry-run mode and only displays commands without executing them. To execute commands:
169
 
170
- Edit `config.yaml` and set `dryrun: 0`, or
171
- Use `--dryrun 0` flag: `havirt --dryrun 0 domain start vmname node1`
172
 
173
### Resource Validation
174
 
175
Before starting or migrating VMs, havirt verifies:
176
- Target node has sufficient free memory
177
- Target node has sufficient CPU threads
178
- VM is not already running elsewhere
179
 
180
### Maintenance Mode
181
 
182
Nodes in maintenance mode:
183
- Cannot have VMs started on them
184
- Cannot be selected as migration targets
185
- Automatically evacuate all VMs during cluster balance
186
 
187
## Automation
188
 
189
### Cron Job Setup
190
 
191
Regular scanning keeps the cluster database current:
192
 
193
```bash
194
# /etc/cron.d/havirt
195
*/5 * * * * root /usr/local/bin/havirt node scan 2>&1 | logger -t havirt
196
```
197
 
198
See `havirt.sample.cron` for more examples.
199
 
200
## Testing
201
 
202
A comprehensive test suite is available in the `tests/` directory:
203
 
204
```bash
205
cd tests
206
./test_havirt_safe.sh     # Safe tests using --testing mode
207
./test_integration.pl     # Unit tests for modules
208
```
209
 
210
See [tests/TESTING.md](tests/TESTING.md) for details.
211
 
212
## Documentation
213
 
214
- **[INSTALL.md](INSTALL.md)** - Complete installation and setup guide
215
- **[USAGE.md](USAGE.md)** - Detailed command reference for all modules
216
- **[PROGRAMMING.md](PROGRAMMING.md)** - Development documentation
217
- **[CHANGES.md](CHANGES.md)** - Version history and changelog
218
- **[tests/TESTING.md](tests/TESTING.md)** - Testing documentation
219
 
220
## Architecture
221
 
222
havirt extends virsh with cluster awareness:
223
 
224
| Task | virsh | havirt |
225
|------|-------|--------|
226
| Start VM | Starts on current node | Validates resources, checks cluster-wide, starts safely |
227
| Config location | `/etc/libvirt/qemu/` | Shared `conf/` directory |
228
| Cluster awareness | None | Full cluster state tracking |
229
| Safety checks | None | Prevents duplicate VMs, validates resources |
230
 
231
## Troubleshooting
232
 
233
**Enable verbose output:**
234
```bash
235
havirt --verbose 1 [command]
236
```
237
 
238
**Enable debug output:**
239
```bash
240
havirt --debug 3 [command]
241
```
242
 
243
**Force rescan if status seems incorrect:**
244
```bash
245
havirt node scan --force
246
```
247
 
248
**Check cluster state:**
249
```bash
250
cat var/status.yaml
251
```
252
 
253
## Support and Development
254
 
255
- **Repository:** http://svn.dailydata.net/svn/havirt/
256
- **Stable branch:** Use `stable` for production
257
- **Development:** `trunk` contains latest development (may be unstable)
258
 
259
## License
260
 
261
Copyright 2024-2026 Daily Data, Inc.
262
 
263
Redistribution and use in source and binary forms, with or without modification, are permitted provided that redistributions retain the copyright notice and disclaimer. See source files for complete license text (BSD-style license).