Subversion Repositories havirt

Rev

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

Rev Author Line No. Line
47 rodolico 1
# havirt Installation Guide
24 rodolico 2
 
47 rodolico 3
## Overview
24 rodolico 4
 
47 rodolico 5
This guide covers the complete installation and initial setup of havirt for a KVM/libvirt cluster with shared storage. The process takes approximately 30-60 minutes for a typical 3-4 node cluster.
24 rodolico 6
 
47 rodolico 7
## Prerequisites
24 rodolico 8
 
47 rodolico 9
### Hardware Requirements
24 rodolico 10
 
47 rodolico 11
- **Multiple hypervisor nodes** (minimum 2, tested with up to 4)
12
- **Shared block storage** (iSCSI, Fiber Channel, or similar)
13
- **NFS server** for shared configuration and state files
14
- **Network connectivity** between all nodes
24 rodolico 15
 
47 rodolico 16
### Software Requirements
26 rodolico 17
 
47 rodolico 18
- **Operating System**: Debian-based Linux (tested on Devuan Chimaera, Debian, Ubuntu)
19
- **Virtualization**: KVM/QEMU with libvirt installed
20
- **Perl**: Version 5.x or later
21
- **Perl Modules**:
22
  - `Data::Dumper` (usually included with Perl)
23
  - `YAML::Tiny`
24
  - `FindBin` (usually included with Perl)
25
- **Utilities**: `ssh`, `svn` (for installation)
24 rodolico 26
 
47 rodolico 27
### Network Requirements
24 rodolico 28
 
47 rodolico 29
- All nodes must be able to SSH to each other (including themselves)
30
- DNS or `/etc/hosts` entries for all node names
31
- Consistent hostname resolution across all nodes
24 rodolico 32
 
47 rodolico 33
### Storage Requirements
24 rodolico 34
 
47 rodolico 35
- **NFS share** mounted at the **same path** on all nodes
36
- **File locking must be enabled** on the NFS server
37
- Recommended: Dedicated NFS share for havirt (minimum 100MB)
24 rodolico 38
 
47 rodolico 39
## Tested Environment
24 rodolico 40
 
47 rodolico 41
Havirt has been tested and deployed on:
24 rodolico 42
 
47 rodolico 43
- **Nodes**: 4 x Devuan Linux (Chimaera) hypervisors
44
- **Virtualization**: libvirt/KVM/QEMU
45
- **Storage**: NAS providing iSCSI targets
46
- **NFS**: Mounted at `/media/shared` on all nodes
47
- **Lock requirement**: NFS file locking enabled
24 rodolico 48
 
47 rodolico 49
## Installation Steps
24 rodolico 50
 
47 rodolico 51
### Step 1: Prepare NFS Share
24 rodolico 52
 
47 rodolico 53
On your NFS server, create and export a share:
24 rodolico 54
 
47 rodolico 55
```bash
56
# On NFS server
57
mkdir -p /exports/havirt
58
chown root:root /exports/havirt
59
chmod 755 /exports/havirt
60
```
24 rodolico 61
 
47 rodolico 62
Add to `/etc/exports`:
63
```
64
/exports/havirt  node1(rw,sync,no_subtree_check) node2(rw,sync,no_subtree_check) node3(rw,sync,no_subtree_check)
65
```
26 rodolico 66
 
47 rodolico 67
**Critical**: Ensure file locking is enabled (default in most NFS configurations).
26 rodolico 68
 
47 rodolico 69
Reload exports:
70
```bash
71
exportfs -ra
72
```
26 rodolico 73
 
47 rodolico 74
### Step 2: Mount NFS on All Nodes
24 rodolico 75
 
47 rodolico 76
On each hypervisor node:
24 rodolico 77
 
47 rodolico 78
```bash
79
# Create mount point
80
mkdir -p /media/shared
24 rodolico 81
 
47 rodolico 82
# Add to /etc/fstab for persistent mounting
83
echo "nfs-server:/exports/havirt  /media/shared  nfs  defaults  0  0" >> /etc/fstab
24 rodolico 84
 
47 rodolico 85
# Mount the share
86
mount /media/shared
24 rodolico 87
 
47 rodolico 88
# Verify
89
df -h | grep shared
90
touch /media/shared/test && rm /media/shared/test  # Test write access
91
```
24 rodolico 92
 
47 rodolico 93
### Step 3: Install Dependencies
24 rodolico 94
 
47 rodolico 95
On each node, install required packages:
26 rodolico 96
 
47 rodolico 97
**Debian/Ubuntu/Devuan:**
98
```bash
99
apt update
100
apt install -y libvirt-daemon-system qemu-kvm libdata-dump-perl libyaml-tiny-perl subversion
101
```
24 rodolico 102
 
47 rodolico 103
**RHEL/CentOS/Rocky:**
104
```bash
105
yum install -y libvirt qemu-kvm perl-Data-Dumper perl-YAML-Tiny subversion
106
```
107
 
108
Verify Perl modules:
109
```bash
110
perl -MData::Dumper -e 'print "Data::Dumper OK\n"'
111
perl -MYAML::Tiny -e 'print "YAML::Tiny OK\n"'
112
```
113
 
114
### Step 4: Install havirt
115
 
116
Install havirt to the NFS share (run on any node):
117
 
118
```bash
119
# Check out stable version
120
svn co http://svn.dailydata.net/svn/havirt/stable /media/shared/havirt
121
 
122
# Verify installation
123
ls -la /media/shared/havirt/
124
```
125
 
126
You should see:
127
```
128
havirt              # Main executable
129
*.pm                # Module files
130
config.sample.yaml  # Sample configuration
131
conf/               # Directory for VM configs
132
var/                # Directory for state files
133
```
134
 
135
### Step 5: Create Symlinks on All Nodes
136
 
137
On each node:
138
 
139
```bash
140
ln -s /media/shared/havirt/havirt /usr/local/bin/havirt
141
 
142
# Verify
143
which havirt
144
havirt --version
145
```
146
 
147
### Step 6: Generate Initial Configuration
148
 
149
On any node:
150
 
151
```bash
152
cd /media/shared/havirt
153
havirt
154
```
155
 
156
This creates `config.yaml` with safe defaults. By default, havirt runs in **dry-run mode** (commands are displayed but not executed).
157
 
158
Review and customize:
159
```bash
160
vi config.yaml
161
```
162
 
163
Key settings to review:
164
```yaml
165
flags:
166
  dryrun: 1                    # Keep at 1 until setup complete
167
  verbose: 1                   # Show detailed output
168
  debug: 0                     # Set to 1-3 for troubleshooting
169
 
170
node reserved memory: 8388608  # 8GB reserved per node (adjust as needed)
171
min scan time: 300             # Minimum 5 minutes between scans
172
```
173
 
174
### Step 7: Configure SSH Keys
175
 
176
All nodes must authenticate to each other without passwords.
177
 
178
**On each node, as root:**
179
 
180
```bash
181
# Generate SSH key (if not already present)
182
if [ ! -f /root/.ssh/id_rsa ]; then
183
    ssh-keygen -t rsa -b 4096 -N "" -f /root/.ssh/id_rsa
184
fi
185
 
186
# Append public key to shared collection
187
cat /root/.ssh/id_rsa.pub >> /media/shared/havirt/sshkeys
188
```
189
 
190
**After all nodes have added their keys:**
191
 
192
```bash
193
# On each node, deploy the collected keys
194
cat /media/shared/havirt/sshkeys >> /root/.ssh/authorized_keys
195
chown root:root /root/.ssh/authorized_keys
196
chmod 600 /root/.ssh/authorized_keys
197
```
198
 
199
**Test SSH connectivity from each node:**
200
 
201
```bash
202
# On node1, test connectivity to all nodes
203
for node in node1 node2 node3 node4; do
204
    echo "Testing $node..."
205
    ssh -o StrictHostKeyChecking=accept-new $node hostname
206
done
207
```
208
 
209
**Optional**: Create SSH config for convenience:
210
 
211
```bash
212
cat > /root/.ssh/config << 'EOF'
213
Host node1
214
    HostName node1.example.com
215
    User root
216
 
217
Host node2
218
    HostName node2.example.com
219
    User root
220
 
221
# Add entries for all nodes
222
EOF
223
 
224
chmod 600 /root/.ssh/config
225
```
226
 
227
### Step 8: Register Nodes
228
 
229
Register each hypervisor node in the cluster database.
230
 
231
**On any node:**
232
 
233
```bash
234
# Add each node
235
havirt node add node1
236
havirt node add node2
237
havirt node add node3
238
havirt node add node4
239
 
240
# Verify all nodes registered
241
havirt node list
242
```
243
 
244
Expected output:
245
```
246
     name     memory  cpu_count maintenance
247
    node1  67108864         16           0
248
    node2  67108864         16           0
249
    node3  67108864         16           0
250
```
251
 
252
For TSV output (useful for scripts):
253
```bash
254
havirt --format tsv node list
255
```
256
 
257
### Step 9: Configure iSCSI (Optional)
258
 
259
If using iSCSI shared storage, configure targets:
260
 
261
```bash
262
# Add iSCSI target to configuration
263
havirt cluster iscsi add 192.168.1.10
264
 
265
# Verify target added
266
havirt cluster iscsi
267
 
268
# Test on one node first
269
havirt cluster iscsi update node1
270
 
271
# If successful, update all nodes
272
havirt cluster iscsi update
273
 
274
# Verify iSCSI sessions
275
iscsiadm -m session
276
```
277
 
278
### Step 10: Import Existing VMs
279
 
280
Discover and register VMs already running on the cluster.
281
 
282
```bash
283
# Scan all nodes for running VMs
284
havirt node scan --force
285
 
286
# Import VM configurations
287
havirt domain update
288
 
289
# List all discovered VMs
290
havirt domain list
291
```
292
 
293
Expected output:
294
```
295
         name   memory vcpu  node maintenance
296
      webvm1  4194304    4 node1           0
297
       db01   8388608    8 node2           0
298
   testvm    2097152    2 node3           0
299
```
300
 
301
### Step 11: Enable Automated Scanning
302
 
303
Set up cron job to keep cluster database current:
304
 
305
```bash
306
# Copy sample cron file
307
cp /media/shared/havirt/havirt.sample.cron /etc/cron.d/havirt
308
 
309
# Edit if needed
310
vi /etc/cron.d/havirt
311
```
312
 
313
Default cron content:
314
```bash
315
# Scan cluster every 5 minutes
316
*/5 * * * * root /usr/local/bin/havirt node scan --quiet 2>&1 | logger -t havirt
317
```
318
 
319
Verify cron job:
320
```bash
321
systemctl restart cron
322
tail -f /var/log/syslog | grep havirt
323
```
324
 
325
### Step 12: Enable Production Mode
326
 
327
Once testing is complete, enable command execution:
328
 
329
```bash
330
# Edit configuration
331
vi /media/shared/havirt/config.yaml
332
```
333
 
334
Change:
335
```yaml
336
flags:
337
  dryrun: 0  # Changed from 1 to 0 if desired
338
```
339
 
340
**Test with a safe operation:**
341
```bash
342
# This should now actually execute
343
havirt node scan
344
havirt domain list
345
```
346
 
347
## Post-Installation
348
 
349
### Verify Installation
350
 
351
Run through this checklist:
352
 
353
```bash
354
# 1. Check NFS mount on all nodes
355
for node in node1 node2 node3; do
356
    ssh $node "df -h | grep shared"
357
done
358
 
359
# 2. Verify SSH connectivity
360
for node in node1 node2 node3; do
361
    ssh $node hostname
362
done
363
 
364
# 3. Check node registration
365
havirt node list
366
 
367
# 4. Verify VM discovery
368
havirt domain list
369
 
370
# 5. Check cluster statistics
371
havirt cluster stats
372
 
373
# 6. Test dry-run vs real execution
374
havirt --dryrun 1 domain list  # Shows command
375
havirt --dryrun 0 domain list  # Executes command
376
```
377
 
378
### Test Migration
379
 
380
Test VM migration between nodes:
381
 
382
```bash
383
# List VMs and their locations
384
havirt domain list
385
 
386
# In dry-run mode, test migration command
387
havirt --dryrun 1 domain migrate testvmname node2
388
 
389
# If output looks correct, execute
390
havirt --dryrun 0 domain migrate testvmname node2
391
 
392
# Verify migration
393
havirt node scan --force
394
havirt domain list
395
```
396
 
397
### Configure Logging (Recommended)
398
 
399
Set up dedicated logging:
400
 
401
```bash
402
# Create log directory
403
mkdir -p /var/log/havirt
404
 
405
# Add to rsyslog
406
cat > /etc/rsyslog.d/havirt.conf << 'EOF'
407
if $programname == 'havirt' then /var/log/havirt/havirt.log
408
& stop
409
EOF
410
 
411
# Restart rsyslog
412
systemctl restart rsyslog
413
 
414
# Add logrotate
415
cat > /etc/logrotate.d/havirt << 'EOF'
416
/var/log/havirt/*.log {
417
    daily
418
    rotate 30
419
    compress
420
    delaycompress
421
    notifempty
422
    create 640 root root
423
}
424
EOF
425
```
426
 
427
## Troubleshooting
428
 
429
### NFS Issues
430
 
431
**Problem**: "Permission denied" accessing `/media/shared/havirt`
432
 
433
```bash
434
# Check NFS mount
435
mount | grep shared
436
 
437
# Check permissions
438
ls -la /media/shared
439
 
440
# Test write access
441
touch /media/shared/test && rm /media/shared/test
442
 
443
# Check NFS server exports
444
showmount -e nfs-server
445
```
446
 
447
**Problem**: Lock file issues
448
 
449
```bash
450
# Remove stale lock
451
rm -f /media/shared/havirt/var/status.yaml.lock
452
 
453
# Verify NFS locking enabled on server
454
```
455
 
456
### SSH Connectivity Issues
457
 
458
**Problem**: "Permission denied (publickey)"
459
 
460
```bash
461
# Verify key in authorized_keys
462
cat /root/.ssh/authorized_keys
463
 
464
# Check SSH key permissions
465
chmod 700 /root/.ssh
466
chmod 600 /root/.ssh/id_rsa
467
chmod 644 /root/.ssh/id_rsa.pub
468
chmod 600 /root/.ssh/authorized_keys
469
 
470
# Test with verbose output
471
ssh -v node2
472
```
473
 
474
### Module Installation Issues
475
 
476
**Problem**: "Can't locate YAML/Tiny.pm"
477
 
478
```bash
479
# Debian/Ubuntu
480
apt install libyaml-tiny-perl
481
 
482
# RHEL/CentOS
483
yum install perl-YAML-Tiny
484
 
485
# Or use CPAN
486
cpan YAML::Tiny
487
```
488
 
489
### VM Not Found
490
 
491
**Problem**: havirt can't find running VM
492
 
493
```bash
494
# Force rescan
495
havirt node scan --force
496
 
497
# Check if VM actually running
498
virsh list --all
499
 
500
# Update VM database
501
havirt domain update vmname
502
 
503
# Check status database
504
cat /media/shared/havirt/var/status.yaml | grep vmname
505
```
506
 
507
### Debug Mode
508
 
509
Enable verbose debugging:
510
 
511
```bash
512
# Debug level 1: Basic info
513
havirt --debug 1 node scan
514
 
515
# Debug level 2: Detailed info
516
havirt --debug 2 domain list
517
 
518
# Debug level 3: Full command trace
519
havirt --debug 3 cluster stats
520
```
521
 
522
## Upgrading
523
 
524
To upgrade to a newer version:
525
 
526
```bash
527
cd /media/shared/havirt
528
 
529
# Backup current version
530
cp -a /media/shared/havirt /media/shared/havirt.backup
531
 
532
# Update from repository
533
svn update
534
 
535
# Check version
536
havirt --version
537
 
538
# Review changes
539
cat CHANGES.md
540
 
541
# Test with dry-run
542
havirt --dryrun 1 node scan
543
```
544
 
545
## Uninstallation
546
 
547
To remove havirt:
548
 
549
```bash
550
# Remove cron job
551
rm /etc/cron.d/havirt
552
 
553
# Remove symlink from all nodes
554
rm /usr/local/bin/havirt
555
 
556
# Remove installation (from NFS)
557
rm -rf /media/shared/havirt
558
 
559
# Unmount NFS if no longer needed
560
umount /media/shared
561
```
562
 
563
## Next Steps
564
 
565
After installation:
566
 
567
1. Review [USAGE.md](USAGE.md) for detailed command reference
568
2. Review [README.md](README.md) for operational guidelines
569
3. Set up monitoring/alerting for cluster health
570
4. Document your VM migration procedures
571
5. Test maintenance mode workflow
572
6. Test cluster balancing in dry-run mode
573
 
574
## Getting Help
575
 
576
- Check [USAGE.md](USAGE.md) for command syntax
577
- Review [README.md](README.md) for common tasks
578
- Enable `--debug 3` for detailed troubleshooting
579
- Check `/var/log/syslog` for cron job output
580
- Review `/media/shared/havirt/var/status.yaml` for cluster state