From: Ricardo Noriega Date: Fri, 3 May 2019 16:15:58 +0000 (+0200) Subject: Bash script to prepare host for Libvirt deploy X-Git-Tag: akraino_r1~15 X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F16%2F616%2F6;p=kni%2Finstaller.git Bash script to prepare host for Libvirt deploy Change-Id: I9e82f17587500f13f87be35dacacff90eb930ee6 Signed-off-by: Ricardo Noriega --- diff --git a/utils/prep_host.sh b/utils/prep_host.sh new file mode 100644 index 0000000..b890558 --- /dev/null +++ b/utils/prep_host.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +set +x + +prerequisites() +{ + # Check if virtualization is supported + ls /dev/kvm 2> /dev/null + if [ $? -ne 0 ] + then + echo "Your system doesn't support virtualization" + exit 1 + fi + + # Install required dependecies + sudo yum install -y libvirt libvirt-devel libvirt-daemon-kvm qemu-kvm + + # Enable IP forwarding + sudo sysctl net.ipv4.ip_forward=1 + + # Configure libvirt to accept TCP connections + sudo sed -i.bak -e 's/^[#]*\s*listen_tls.*/listen_tls = 0/' -e 's/^[#]*\s*listen_tcp.*/listen_tcp = 1/' -e 's/^[#]*\s*auth_tcp.*/auth_tcp = "none"/' -e 's/^[#]*\s*tcp_port.*/tcp_port = "16509"/' /etc/libvirt/libvirtd.conf + + # Configure the service runner to pass --listen to libvirtd + sudo sed -i.bak -e 's/^[#]*\s*LIBVIRTD_ARGS.*/LIBVIRTD_ARGS="--listen"/' /etc/sysconfig/libvirtd + + # Restart the libvirtd service + sudo systemctl restart libvirtd + + # Add Iptables rule + iptables -I INPUT -p tcp -s 192.168.126.0/24 -d 192.168.122.1 --dport 16509 -j ACCEPT -m comment --comment "Allow insecure libvirt clients" + + # Get active Firewall zone option + systemctl is-active firewalld + if [ $? -ne 0 ] + then + echo "Your system doesn't have firewalld service running" + exit 1 + fi + + activeZone=$(firewall-cmd --get-active-zones | head -n 1) + sudo firewall-cmd --zone=$activeZone --add-source=192.168.126.0/24 + sudo firewall-cmd --zone=$activeZone --add-port=16509/tcp + + # Configure default libvirt storage pool + sudo virsh --connect qemu:///system pool-list | grep -q 'default' + if [ $? -ne 0 ] + then + sudo virsh pool-define /dev/stdin < + default + + /var/lib/libvirt/images + + +EOF + sudo virsh pool-start default + sudo virsh pool-autostart default + fi + + # Set up NetworkManager DNS overlay + dnsconf=/etc/NetworkManager/conf.d/openshift.conf + local dnschanged="" + if ! [ -f "${dnsconf}" ]; then + echo -e "[main]\ndns=dnsmasq" | sudo tee "${dnsconf}" + dnschanged=1 + fi + dnsmasqconf=/etc/NetworkManager/dnsmasq.d/openshift.conf + if ! [ -f "${dnsmasqconf}" ]; then + echo server=/tt.testing/192.168.126.1 | sudo tee "${dnsmasqconf}" + echo address=/apps.tt.testing/192.168.126.51 | sudo tee -a "${dnsmasqconf}" + dnschanged=1 + fi + if [ -n "$dnschanged" ]; then + sudo systemctl restart NetworkManager + fi + + # Create an entry in the /etc/host + grep -q 'libvirt.default' /etc/hosts + if [ $? -ne 0 ] + then + echo '192.168.126.1 libvirt.default' | sudo tee --append /etc/hosts + fi +} + +prerequisites