Difference between revisions of "VALT Warm Standby"

From IVS Wiki
Jump to: navigation, search
(restore.sh)
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
The easiest way to achieve a highly available VALT server is by utilizing a VM on a Hypervisor with shared storage that supports HA. Both VMWare and Hyper-V have integrated HA capabilities. If there is a need to make the VALT server highly available, IVS strongly recommends deploying the VALT appliance in a virtual environment and leveraging the hypervisor's HA capabilities. If this is not an option, the procedure below will allow you to configure two VALT appliances with one as a primary server and the second as a warm standby. This procedure will configure the MYSQL databases in a master slave configuration and replicate all changes from the primary to the standby server. Video files can be syncronized periodically. The configuration given below will replicate video files on a daily basis, but this can be customized by adjusting the cronjob scheduling.
+
{{Aside | hue = 0 | icon = &#x26A0; | content = <b>DISCLAIMER:</b> This is not a step by step instruction. This article assumes the reader has a working understanding of the VALT application and how to modify the configuration files. This procedure should only be completed by an IVS support engineer. This may be incorporated into the command line menu in the future.}}
 +
__TOC__
 +
{{Section | content =
 +
=About=
 +
The easiest way to achieve a highly available VALT server is by utilizing a VM on a Hypervisor with shared storage that supports High Availability (HA). Both VMWare and Hyper-V have integrated HA capabilities. If there is a need to make the VALT server highly available, IVS strongly recommends deploying the VALT appliance in a virtual environment and leveraging the hypervisor's HA capabilities. If this is not an option, the procedure below will allow you to configure two VALT appliances with one as a primary server and the second as a warm standby. This procedure will configure the MYSQL databases in a master slave configuration and replicate all changes from the primary to the standby server. Video files can be synchronized periodically. The configuration given below will replicate video files on a daily basis, but this can be customized by adjusting the cronjob scheduling.
  
=Disclaimer=
+
<hr>
This is not a step by step instruction. This article assumes the reader has a working understanding of the VALT application and how to modify the configuration files. This procedure should only be completed by an IVS support engineer. This may be incorporated into the command line menu in the future.
 
  
 
=Prerequisites=
 
=Prerequisites=
Line 13: Line 16:
 
* /usr/local/WowzaStreamingEngine/conf/dustin/Application.xml should be configured to point to the shared DNS entry.
 
* /usr/local/WowzaStreamingEngine/conf/dustin/Application.xml should be configured to point to the shared DNS entry.
 
* The config files in /etc/apache2/sites-enabled/ should reference the shared DNS entry.
 
* The config files in /etc/apache2/sites-enabled/ should reference the shared DNS entry.
* The only config file in /etc/apache2/sites-enabled/ should be v3.conf. If default-ssl.conf is in this directory, delete it.
+
* The only config file in /etc/apache2/sites-enabled/ should be valt.conf. If default-ssl.conf is in this directory, delete it.
 
* If using https, the certificate should already be installed on the primary server
 
* If using https, the certificate should already be installed on the primary server
 +
 +
<hr>
  
 
=Script Package=
 
=Script Package=
# Download VALTRedundancy.tar.gz by running the following command: <code>wget --content-disposition https://ivs.box.com/shared/static/1062styfwr387efew51vt6mzqzsdd1m3.gz -O VALTRedundancy.tar.gz</code>
+
# Download VALTRedundancy.tar.gz by running the following command: {{Code Block - Mini | text = <span class="code_regex">wget</span> --content-disposition https://ivs.box.com/shared/static/1062styfwr387efew51vt6mzqzsdd1m3.gz <span class="code_option">-O</span> <span class="code_2">VALTRedundancy.tar.gz</span>}}
# Extract the file using the following command: <code>tar -xvf VALTRedundancy.tar.gz</code>
+
# Extract the file using the following command: {{Code Block - Mini | text = <span class="code_regex">tar</span> <span class="code_option">-xvf</span> <span class="code_2">VALTRedundancy.tar.gz</span>}}
 +
 
 +
<hr>
  
 
=Primary Server Config=
 
=Primary Server Config=
Run <code>PrimaryServerConfig.sh</code> on the primary server. Make sure to modify the variables at the top of the script to reflect your environment. Specifically the standbyip must be changed to the ip address of the standby server.
+
Run {{Code Block - Mini | text = <span class="code_file">PrimaryServerConfig.sh</span>}} on the primary server. Make sure to modify the variables at the top of the script to reflect your environment. Specifically the standbyip must be changed to the ip address of the standby server.
  
 
The script will complete by providing the log file name and position. Make a note of these values as they will be needed to configure the standby server.
 
The script will complete by providing the log file name and position. Make a note of these values as they will be needed to configure the standby server.
 +
 +
<hr>
  
 
=Standby Server Config=
 
=Standby Server Config=
#Run <code>sudo -i</code>
+
#Run {{Code Block - Mini | text = <span class="code_regex">sudo</span> <span class="code_option">-i</span>}}
 
#:If you do not use this specific command portions of the script will not execute properly.
 
#:If you do not use this specific command portions of the script will not execute properly.
#Run <code>VALTStandbyServerConfig.sh</code> on the standby server. Make sure to modify the variables at the top of the script to reflect your environment. Specifically the primaryip must be changed to the ip address of the primary server, the logfile and logpos variables must be set to the values output when running the script on the primary server.
+
#Run {{Code Block - Mini | text = <span class="code_file">VALTStandbyServerConfig.sh</span>}} on the standby server. Make sure to modify the variables at the top of the script to reflect your environment. Specifically the primaryip must be changed to the ip address of the primary server, the logfile and logpos variables must be set to the values output when running the script on the primary server.
  
If using the VALTRedundancy.tar.gz package, the failure.sh and restore.sh scripts should automatically be copied to the /usr/local/valt/bin/ directory and set to executable. These scripts are provided below if the VALTRedundancy.tar.gz package was not used. It is a good idea to update the variables in these scripts now so they are ready to be used in the event of a failover.
+
If using the VALTRedundancy.tar.gz package, the failure.sh and restore.sh scripts should automatically be copied to the {{Code Block - Mini | text = <span class="code_filepath">/usr/local/valt/bin/</span>}} directory and set to executable. These scripts are provided below if the {{Code Block - Mini | text = <span class="code_2">VALTRedundancy.tar.gz</span>}} package was not used. It is a good idea to update the variables in these scripts now so they are ready to be used in the event of a failover.
 +
 
 +
<hr>
  
 
=How to Initiate a Failover to the Standby Server=
 
=How to Initiate a Failover to the Standby Server=
 
# Update the shared DNS entry to reference the standby server.
 
# Update the shared DNS entry to reference the standby server.
 
# Run the script by typing the following command:
 
# Run the script by typing the following command:
#: <code>sudo /usr/local/valt/bin/failure.sh</code>
+
#: {{Code Block - Mini | text = <span class="code_regex">sudo</span> <span class="code_filepath">/usr/local/valt/bin/</span><span class="code_file">failure.sh</span>}}
 +
 
 +
<hr>
 +
 
 
=How to Return to the Primary Server=
 
=How to Return to the Primary Server=
 
# Update the shared DNS entry to reference the standby server.
 
# Update the shared DNS entry to reference the standby server.
# Update the variables in the script below to reflect the correct primary ip, slaveuser, and slavepassword. (If this was not done during initial setup)
+
# Update the variables in the script below to reflect the correct primary ip, slaveuser, and slavepassword. <em>(If this was not done during initial setup)</em>
 
# Run the script by typing the following command:
 
# Run the script by typing the following command:
#: <code>sudo /usr/local/valt/bin/restore.sh</code>
+
#: {{Code Block - Mini | text = <span class="code_regex">sudo</span> <span class="code_filepath">/usr/local/valt/bin/</span><span class="code_file">restore.sh</span>}}
=Scripts=
+
}}
===ValtPrimaryServerConfig.sh===
+
 
<nowiki>#!/bin/bash
+
{{Section | title = <h1>Scripts</h1> | content =  
 +
{{Section - Expand | color = #E6B8B8 | title = ValtPrimaryServerConfig.sh | content =  
 +
<pre>
 +
#!/bin/bash
 
# This script will configure an existing VALT server to function as a primary server.  
 
# This script will configure an existing VALT server to function as a primary server.  
 
# You will need to run VALTStandbyServerConfig.sh on the warm standby server.
 
# You will need to run VALTStandbyServerConfig.sh on the warm standby server.
standbyip="192.168.0.98"
+
standbyip="ENTER_STANDBY_SERVER_IP"
 
dbuser="ivsadmin"
 
dbuser="ivsadmin"
dbpass="password"
+
dbpass="admin51"
 
slaveuser="ivs_user"
 
slaveuser="ivs_user"
slavepassword="password"
+
slavepassword="admin51"
  
 
echo "WARNING: DO NOT RUN THIS SCRIPT MULTIPLE TIMES!!!"
 
echo "WARNING: DO NOT RUN THIS SCRIPT MULTIPLE TIMES!!!"
Line 64: Line 81:
 
echo -e "ivsadmin ALL=(ALL) NOPASSWD: /usr/bin/rsync,/usr/bin/systemd-resolve" >> /etc/sudoers
 
echo -e "ivsadmin ALL=(ALL) NOPASSWD: /usr/bin/rsync,/usr/bin/systemd-resolve" >> /etc/sudoers
  
# ************************************************************************************
+
if [ -s "/usr/local/valt/conf/valtconfig" ];
# The IP address may need to be overridden if the IP was not set through the menu
 
# or if the client interface is not used for replication.
 
        # ************************************************************************************
 
# ipaddress="192.168.0.99"
 
 
 
if [ -s "/usr/local/valt/conf/ipaddress" ];
 
 
then
 
then
ipaddress=$(</usr/local/valt/conf/ipaddress)
+
ipaddress=$(</usr/local/valt/conf/valtconfig)
 
fi
 
fi
 
sed -i "s|bind-address|#bind-address|g" /etc/mysql/mysql.conf.d/mysqld.cnf
 
sed -i "s|bind-address|#bind-address|g" /etc/mysql/mysql.conf.d/mysqld.cnf
Line 78: Line 89:
 
echo -e "server-id\t\t= 1" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
echo -e "server-id\t\t= 1" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
echo -e "log_bin\t\t\t= /var/log/mysql/mysql-bin.log" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
echo -e "log_bin\t\t\t= /var/log/mysql/mysql-bin.log" >> /etc/mysql/mysql.conf.d/mysqld.cnf
echo -e "binlog_do_db\t\t= v3" >> /etc/mysql/mysql.conf.d/mysqld.cnf
+
echo -e "binlog_do_db\t\t= valt" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
service mysql restart
 
service mysql restart
sed -i "s|database_host: localhost|database_host: $ipaddress|g" /var/www/v3/app/config/parameters.yml
+
######sed -i "s|HOST|HOST: $ipaddress|g" /var/www/valt/.env.local#####
 
iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
 
iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
 
iptables -A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT
 
iptables -A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT
Line 86: Line 97:
 
mysql --defaults-extra-file=/etc/mysql/debian.cnf -e "GRANT REPLICATION SLAVE ON *.* TO '$slaveuser'@'$standbyip' IDENTIFIED BY '$slavepassword';"
 
mysql --defaults-extra-file=/etc/mysql/debian.cnf -e "GRANT REPLICATION SLAVE ON *.* TO '$slaveuser'@'$standbyip' IDENTIFIED BY '$slavepassword';"
 
mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "FLUSH PRIVILEGES;"
 
mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "FLUSH PRIVILEGES;"
mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "USE v3;"
+
mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "USE valt;"
 
mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "FLUSH TABLES WITH READ LOCK;"
 
mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "FLUSH TABLES WITH READ LOCK;"
tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf v3 -e "SHOW MASTER STATUS\G;" | grep File)
+
tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf valt -e "SHOW MASTER STATUS\G;" | grep File)
 
sqlfile=${tmp1#*:}  
 
sqlfile=${tmp1#*:}  
tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf v3 -e "SHOW MASTER STATUS\G;" | grep Position)
+
tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf valt -e "SHOW MASTER STATUS\G;" | grep Position)
 
position=${tmp1#*:}
 
position=${tmp1#*:}
 
sqlfile=$(echo $sqlfile | xargs)
 
sqlfile=$(echo $sqlfile | xargs)
mysqldump --defaults-extra-file=/usr/local/valt/conf/sql.cnf --opt v3 > /usr/local/valt/backup/v3_sync.sql
+
mysqldump --defaults-extra-file=/usr/local/valt/conf/sql.cnf --opt valt > /usr/local/valt/backup/valt_sync.sql
 
mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "UNLOCK TABLES;"
 
mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "UNLOCK TABLES;"
 
netfilter-persistent save
 
netfilter-persistent save
 
echo -e "Master Log File: $sqlfile"
 
echo -e "Master Log File: $sqlfile"
 
echo -e "Master Log Position: $position"
 
echo -e "Master Log Position: $position"
fi</nowiki>
+
fi
 +
</pre>
 +
}}
  
===ValtStandbyServerConfig.sh===
+
{{Section - Expand | color = #E6CFB8 | title = ValtStandbyServerConfig.sh | content =  
<nowiki>
+
<pre>
 
#!/bin/bash
 
#!/bin/bash
 
# This script will configure an existing VALT server to function as a  
 
# This script will configure an existing VALT server to function as a  
Line 108: Line 121:
  
 
primaryuser="ivsadmin"  
 
primaryuser="ivsadmin"  
primarypass="password"  
+
primarypass="admin51"  
primaryip="192.168.0.99"  
+
primaryip="ENTER_PRIMARY_SERVER_IP"  
 
slaveuser="ivs_user"
 
slaveuser="ivs_user"
slavepassword="password"
+
slavepassword="admin51"
 
logfile=""
 
logfile=""
 
logpos=""
 
logpos=""
Line 129: Line 142:
 
ssh-keygen -t rsa -f /root/.ssh/id_rsa -q -N ""
 
ssh-keygen -t rsa -f /root/.ssh/id_rsa -q -N ""
 
ssh-copy-id -i /root/.ssh/id_rsa.pub ivsadmin@$primaryip
 
ssh-copy-id -i /root/.ssh/id_rsa.pub ivsadmin@$primaryip
rsync --rsync-path="sudo rsync" -avz ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/content/valt_recordings /usr/local/WowzaStreamingEngine/content/
+
rsync --rsync-path="sudo rsync" -avz ivsadmin@$primaryip:/usr/local/valt/records/* /usr/local/valt/records/
(crontab -l ; echo -e '00 11 * * * rsync --rsync-path="sudo rsync" -avz ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/content/valt_recordings /usr/local/WowzaStreamingEngine/content/') | crontab -
+
(crontab -l ; echo -e '00 11 * * * rsync --rsync-path="sudo rsync" -avz ivsadmin@$primaryip:/usr/local/valt/records/* /usr/local/valt/records/') | crontab -
 
service apache2 stop
 
service apache2 stop
 
service WowzaStreamingEngine stop
 
service WowzaStreamingEngine stop
Line 144: Line 157:
 
mkdir /etc/apache2/ssl
 
mkdir /etc/apache2/ssl
 
scp ivsadmin@$primaryip:/etc/apache2/ssl/* /etc/apache2/ssl
 
scp ivsadmin@$primaryip:/etc/apache2/ssl/* /etc/apache2/ssl
scp ivsadmin@$primaryip:/etc/apache2/sites-enabled/v3.conf /etc/apache2/sites-enabled/
+
scp ivsadmin@$primaryip:/etc/apache2/sites-enabled/valt.conf /etc/apache2/sites-enabled/
 
scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/conf/valtwowza.jks /usr/local/WowzaStreamingEngine/conf/
 
scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/conf/valtwowza.jks /usr/local/WowzaStreamingEngine/conf/
scp ivsadmin@$primaryip:/var/www/v3/nodejs/server.js /var/www/v3/nodejs/
+
scp ivsadmin@$primaryip:/var/www/valt/nodejs/* /var/www/valt/nodejs/
 
scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/java/lib/security/cacerts /usr/local/WowzaStreamingEngine/java/lib/security/
 
scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/java/lib/security/cacerts /usr/local/WowzaStreamingEngine/java/lib/security/
 
scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/conf/VHost.xml /usr/local/WowzaStreamingEngine/conf/
 
scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/conf/VHost.xml /usr/local/WowzaStreamingEngine/conf/
Line 167: Line 180:
 
echo -e "password=$primarypass" >> /usr/local/valt/conf/primary.cnf
 
echo -e "password=$primarypass" >> /usr/local/valt/conf/primary.cnf
 
 
mysqldump --defaults-extra-file=/usr/local/valt/conf/standby.cnf --opt v3 > /usr/local/valt/backup/v3_orig.sql
+
mysqldump --defaults-extra-file=/usr/local/valt/conf/standby.cnf --opt valt > /usr/local/valt/backup/valt_orig.sql
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "DROP DATABASE v3;"
+
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "DROP DATABASE valt;"
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CREATE DATABASE v3;"
+
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CREATE DATABASE valt;"
scp ivsadmin@$primaryip:/usr/local/valt/backup/v3_sync.sql /usr/local/valt/backup/v3_sync.sql
+
scp ivsadmin@$primaryip:/usr/local/valt/backup/valt_sync.sql /usr/local/valt/backup/valt_sync.sql
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf v3 < /usr/local/valt/backup/v3_sync.sql
+
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf valt < /usr/local/valt/backup/valt_sync.sql
 
echo -e "server-id\t\t= 2" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
echo -e "server-id\t\t= 2" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
echo -e "relay-log\t\t= /var/log/mysql/mysql-relay-bin.log" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
echo -e "relay-log\t\t= /var/log/mysql/mysql-relay-bin.log" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
echo -e "log_bin\t\t\t= /var/log/mysql/mysql-bin.log" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
echo -e "log_bin\t\t\t= /var/log/mysql/mysql-bin.log" >> /etc/mysql/mysql.conf.d/mysqld.cnf
echo -e "binlog_do_db\t\t= v3" >> /etc/mysql/mysql.conf.d/mysqld.cnf
+
echo -e "binlog_do_db\t\t= valt" >> /etc/mysql/mysql.conf.d/mysqld.cnf
 
service mysql restart
 
service mysql restart
 
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CHANGE MASTER TO MASTER_HOST='$primaryip',MASTER_USER='$slaveuser', MASTER_PASSWORD='$slavepassword', MASTER_LOG_FILE='$logfile', MASTER_LOG_POS=  $logpos;"
 
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CHANGE MASTER TO MASTER_HOST='$primaryip',MASTER_USER='$slaveuser', MASTER_PASSWORD='$slavepassword', MASTER_LOG_FILE='$logfile', MASTER_LOG_POS=  $logpos;"
Line 185: Line 198:
 
fi
 
fi
  
</nowiki>
+
</pre>
 +
}}
  
===failure.sh===
+
{{Section - Expand | color = #E6E6B8 | title = failure.sh | content =  
<nowiki>
+
<pre>
 
#!/bin/bash
 
#!/bin/bash
 
#This script will make the redundant VALT server the primary VALT server.  
 
#This script will make the redundant VALT server the primary VALT server.  
Line 213: Line 227:
 
service valtcontrols start
 
service valtcontrols start
 
fi
 
fi
 +
</pre>
 +
}}
  
</nowiki>
+
{{Section - Expand | color = #CFE6B8 | title = restore.sh | content =  
===restore.sh===
+
<pre>
<nowiki>
 
 
#!/bin/bash
 
#!/bin/bash
 
# This script will migrate the database and all recordings back to the primary VALT server.  
 
# This script will migrate the database and all recordings back to the primary VALT server.  
Line 241: Line 256:
 
systemctl disable valtcontrols
 
systemctl disable valtcontrols
 
systemctl disable WowzaStreamingEngine
 
systemctl disable WowzaStreamingEngine
rsync --rsync-path="sudo rsync" -avz /usr/local/WowzaStreamingEngine/content/valt_recordings ivsadmin@10.111.3.73:/usr/local/WowzaStreamingEngine/content/
+
rsync --rsync-path="sudo rsync" -avz /usr/local/valt/records/* ivsadmin@10.111.3.73:/usr/local/valt/records/
mysqldump --defaults-extra-file=/usr/local/valt/conf/standby.cnf --opt v3 > /usr/local/valt/backup/v3.sql
+
mysqldump --defaults-extra-file=/usr/local/valt/conf/standby.cnf --opt v3 > /usr/local/valt/backup/valt.sql
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf -e "DROP DATABASE v3;"
+
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf -e "DROP DATABASE valt;"
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf -e "CREATE DATABASE v3;"
+
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf -e "CREATE DATABASE valt;"
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf v3 < /usr/local/valt/backup/v3.sql
+
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt < /usr/local/valt/backup/valt.sql
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf v3 -e "FLUSH TABLES WITH READ LOCK;"
+
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt -e "FLUSH TABLES WITH READ LOCK;"
tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf v3 -e "SHOW MASTER STATUS\G;" | grep File)
+
tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt -e "SHOW MASTER STATUS\G;" | grep File)
 
sqlfile=${tmp1#*:}
 
sqlfile=${tmp1#*:}
tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf v3 -e "SHOW MASTER STATUS\G;" | grep Position)
+
tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt -e "SHOW MASTER STATUS\G;" | grep Position)
 
position=${tmp1#*:}
 
position=${tmp1#*:}
 
sqlfile=$(echo $sqlfile | xargs)
 
sqlfile=$(echo $sqlfile | xargs)
mysqldump --defaults-extra-file=/usr/local/valt/conf/primary.cnf --opt v3 > /usr/local/valt/backup/v3_sync.sql
+
mysqldump --defaults-extra-file=/usr/local/valt/conf/primary.cnf --opt valt > /usr/local/valt/backup/valt_sync.sql
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf v3 -e "UNLOCK TABLES;"
+
mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt -e "UNLOCK TABLES;"
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "DROP DATABASE v3;"
+
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "DROP DATABASE valt;"
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CREATE DATABASE v3;"
+
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CREATE DATABASE valt;"
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf v3 < /usr/local/valt/backup/v3_sync.sql
+
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf valt < /usr/local/valt/backup/valt_sync.sql
 
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CHANGE MASTER TO MASTER_HOST="\'"$primaryip"\'", MASTER_USER="\'"$slaveuser"\'", MASTER_PASSWORD="\'"$slavepassword"\'", MASTER_LOG_FILE="\'"$sqlfile"\'", MASTER_LOG_POS = $position;"
 
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CHANGE MASTER TO MASTER_HOST="\'"$primaryip"\'", MASTER_USER="\'"$slaveuser"\'", MASTER_PASSWORD="\'"$slavepassword"\'", MASTER_LOG_FILE="\'"$sqlfile"\'", MASTER_LOG_POS = $position;"
 
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "START SLAVE;"
 
mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "START SLAVE;"
 
fi
 
fi
 
+
</pre>
</nowiki>
+
}} }}

Latest revision as of 08:26, 24 October 2023

DISCLAIMER: This is not a step by step instruction. This article assumes the reader has a working understanding of the VALT application and how to modify the configuration files. This procedure should only be completed by an IVS support engineer. This may be incorporated into the command line menu in the future.

About

The easiest way to achieve a highly available VALT server is by utilizing a VM on a Hypervisor with shared storage that supports High Availability (HA). Both VMWare and Hyper-V have integrated HA capabilities. If there is a need to make the VALT server highly available, IVS strongly recommends deploying the VALT appliance in a virtual environment and leveraging the hypervisor's HA capabilities. If this is not an option, the procedure below will allow you to configure two VALT appliances with one as a primary server and the second as a warm standby. This procedure will configure the MYSQL databases in a master slave configuration and replicate all changes from the primary to the standby server. Video files can be synchronized periodically. The configuration given below will replicate video files on a daily basis, but this can be customized by adjusting the cronjob scheduling.


Prerequisites

  • A DNS entry (CNAME or A) resolving to the primary server.
    • This should not be the primary DNS entry for that server and will be changed in the event of a failure.
    • If https will be used this DNS entry should be used as the CN for the certificate
      • SANs should be included for the FQDN of each server in addition to the DNS entry
    • For this to work properly there must not be an entry in /etc/hosts for the DNS entry
    • Additionally both servers will need to be pointed at a DNS server that can properly resolve the shared DNS entry.
  • /usr/local/WowzaStreamingEngine/conf/dustin/Application.xml should be configured to point to the shared DNS entry.
  • The config files in /etc/apache2/sites-enabled/ should reference the shared DNS entry.
  • The only config file in /etc/apache2/sites-enabled/ should be valt.conf. If default-ssl.conf is in this directory, delete it.
  • If using https, the certificate should already be installed on the primary server

Script Package

  1. Download VALTRedundancy.tar.gz by running the following command: wget --content-disposition https://ivs.box.com/shared/static/1062styfwr387efew51vt6mzqzsdd1m3.gz -O VALTRedundancy.tar.gz
  2. Extract the file using the following command: tar -xvf VALTRedundancy.tar.gz

Primary Server Config

Run PrimaryServerConfig.sh on the primary server. Make sure to modify the variables at the top of the script to reflect your environment. Specifically the standbyip must be changed to the ip address of the standby server.

The script will complete by providing the log file name and position. Make a note of these values as they will be needed to configure the standby server.


Standby Server Config

  1. Run sudo -i
    If you do not use this specific command portions of the script will not execute properly.
  2. Run VALTStandbyServerConfig.sh on the standby server. Make sure to modify the variables at the top of the script to reflect your environment. Specifically the primaryip must be changed to the ip address of the primary server, the logfile and logpos variables must be set to the values output when running the script on the primary server.

If using the VALTRedundancy.tar.gz package, the failure.sh and restore.sh scripts should automatically be copied to the /usr/local/valt/bin/ directory and set to executable. These scripts are provided below if the VALTRedundancy.tar.gz package was not used. It is a good idea to update the variables in these scripts now so they are ready to be used in the event of a failover.


How to Initiate a Failover to the Standby Server

  1. Update the shared DNS entry to reference the standby server.
  2. Run the script by typing the following command:
    sudo /usr/local/valt/bin/failure.sh

How to Return to the Primary Server

  1. Update the shared DNS entry to reference the standby server.
  2. Update the variables in the script below to reflect the correct primary ip, slaveuser, and slavepassword. (If this was not done during initial setup)
  3. Run the script by typing the following command:
    sudo /usr/local/valt/bin/restore.sh

Scripts

ValtPrimaryServerConfig.sh
#!/bin/bash
# This script will configure an existing VALT server to function as a primary server. 
# You will need to run VALTStandbyServerConfig.sh on the warm standby server.
standbyip="ENTER_STANDBY_SERVER_IP"
dbuser="ivsadmin"
dbpass="admin51"
slaveuser="ivs_user"
slavepassword="admin51"

echo "WARNING: DO NOT RUN THIS SCRIPT MULTIPLE TIMES!!!"
echo "You will need to run VALTStandbyServerConfig.sh on the warm standby server."
echo "Press enter to continue."
read r

if [[ $EUID -ne 0 ]]; then
  	echo "You must run this script as root" 2>&1
  	exit 1
else
	apt install rsync
	echo -e "ivsadmin ALL=(ALL) NOPASSWD: /usr/bin/rsync,/usr/bin/systemd-resolve" >> /etc/sudoers

	if [ -s "/usr/local/valt/conf/valtconfig" ];
	then
		ipaddress=$(</usr/local/valt/conf/valtconfig)
	fi
	sed -i "s|bind-address|#bind-address|g" /etc/mysql/mysql.conf.d/mysqld.cnf
	echo -e "bind-address\t\t= $ipaddress" >> /etc/mysql/mysql.conf.d/mysqld.cnf
	echo -e "server-id\t\t= 1" >> /etc/mysql/mysql.conf.d/mysqld.cnf
	echo -e "log_bin\t\t\t= /var/log/mysql/mysql-bin.log" >> /etc/mysql/mysql.conf.d/mysqld.cnf
	echo -e "binlog_do_db\t\t= valt" >> /etc/mysql/mysql.conf.d/mysqld.cnf
	service mysql restart
	######sed -i "s|HOST|HOST: $ipaddress|g" /var/www/valt/.env.local#####
	iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
	iptables -A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT
	mysql --defaults-extra-file=/etc/mysql/debian.cnf -e "GRANT ALL PRIVILEGES ON *.* to '$dbuser'@'$standbyip' IDENTIFIED BY '$dbpass';"
	mysql --defaults-extra-file=/etc/mysql/debian.cnf -e "GRANT REPLICATION SLAVE ON *.* TO '$slaveuser'@'$standbyip' IDENTIFIED BY '$slavepassword';"
	mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "FLUSH PRIVILEGES;"
	mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "USE valt;"
	mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "FLUSH TABLES WITH READ LOCK;"
	tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf valt -e "SHOW MASTER STATUS\G;" | grep File)
	sqlfile=${tmp1#*:} 
	tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf valt -e "SHOW MASTER STATUS\G;" | grep Position)
	position=${tmp1#*:}
	sqlfile=$(echo $sqlfile | xargs)
	mysqldump --defaults-extra-file=/usr/local/valt/conf/sql.cnf --opt valt > /usr/local/valt/backup/valt_sync.sql
	mysql --defaults-extra-file=/usr/local/valt/conf/sql.cnf -e "UNLOCK TABLES;"
	netfilter-persistent save
	echo -e "Master Log File: $sqlfile"
	echo -e "Master Log Position: $position"
fi
ValtStandbyServerConfig.sh
#!/bin/bash
# This script will configure an existing VALT server to function as a 
# standby server.
# You will need to run VALTPrimaryServerConfig.sh on the primary server.

primaryuser="ivsadmin" 
primarypass="admin51" 
primaryip="ENTER_PRIMARY_SERVER_IP" 
slaveuser="ivs_user"
slavepassword="admin51"
logfile=""
logpos=""

echo "WARNING: DO NOT RUN THIS SCRIPT MULTIPLE TIMES!!!"
echo "MAKE SURE YOU HAVE UPDATED THE LOGFILE, LOGPOS, AND PRIMARYIP VARIABLES IN THIS SCRIPT!!"
echo "MAKE SURE YOU RAN sudo -i PRIOR TO EXECUTING THIS SCRIPT!!"
echo "Press CTRL-C to cancel or press enter to continue."

read r

if [[ $EUID -ne 0 ]]; then
  	echo "You must run this script as root" 2>&1
  	exit 1
else
	apt install rsync
	ssh-keygen -t rsa -f /root/.ssh/id_rsa -q -N ""
	ssh-copy-id -i /root/.ssh/id_rsa.pub ivsadmin@$primaryip
	rsync --rsync-path="sudo rsync" -avz ivsadmin@$primaryip:/usr/local/valt/records/* /usr/local/valt/records/
	(crontab -l ; echo -e '00 11 * * * rsync --rsync-path="sudo rsync" -avz ivsadmin@$primaryip:/usr/local/valt/records/* /usr/local/valt/records/') | crontab -
	service apache2 stop
	service WowzaStreamingEngine stop
	service valtcontrols stop
	systemctl disable apache2 
	systemctl disable valtcontrols
	systemctl disable WowzaStreamingEngine
	scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/conf/dustin/Application.xml /usr/local/WowzaStreamingEngine/conf/dustin/Application.xml
	
	#*********************************************************************
	# The section below is for HTTPS enabled environments only
	#*********************************************************************
	mkdir /etc/apache2/ssl
	scp ivsadmin@$primaryip:/etc/apache2/ssl/* /etc/apache2/ssl
	scp ivsadmin@$primaryip:/etc/apache2/sites-enabled/valt.conf /etc/apache2/sites-enabled/
	scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/conf/valtwowza.jks /usr/local/WowzaStreamingEngine/conf/
	scp ivsadmin@$primaryip:/var/www/valt/nodejs/* /var/www/valt/nodejs/
	scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/java/lib/security/cacerts /usr/local/WowzaStreamingEngine/java/lib/security/
	scp ivsadmin@$primaryip:/usr/local/WowzaStreamingEngine/conf/VHost.xml /usr/local/WowzaStreamingEngine/conf/
	if ! iptables -S | grep ACCEPT | grep INPUT | grep 443; then
		iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
	fi
	if ! iptables -S | grep ACCEPT | grep INPUT | grep 444; then
		iptables -A INPUT -p tcp -m tcp --dport 444 -j ACCEPT
	fi
	a2enmod ssl
	
	iptables -A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT
	iptables -A OUTPUT -p tcp -m tcp --dport 3306 -j ACCEPT
	netfilter-persistent save
	cp /usr/local/valt/conf/sql.cnf /usr/local/valt/conf/standby.cnf
	
	echo -e "[client]" > /usr/local/valt/conf/primary.cnf
	echo -e "host=$primaryip" >> /usr/local/valt/conf/primary.cnf
	echo -e "user=$primaryuser" >> /usr/local/valt/conf/primary.cnf
	echo -e "password=$primarypass" >> /usr/local/valt/conf/primary.cnf
	
	mysqldump --defaults-extra-file=/usr/local/valt/conf/standby.cnf --opt valt > /usr/local/valt/backup/valt_orig.sql
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "DROP DATABASE valt;"
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CREATE DATABASE valt;"
	scp ivsadmin@$primaryip:/usr/local/valt/backup/valt_sync.sql /usr/local/valt/backup/valt_sync.sql
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf valt < /usr/local/valt/backup/valt_sync.sql
	echo -e "server-id\t\t= 2" >> /etc/mysql/mysql.conf.d/mysqld.cnf
	echo -e "relay-log\t\t= /var/log/mysql/mysql-relay-bin.log" >> /etc/mysql/mysql.conf.d/mysqld.cnf
	echo -e "log_bin\t\t\t= /var/log/mysql/mysql-bin.log" >> /etc/mysql/mysql.conf.d/mysqld.cnf
	echo -e "binlog_do_db\t\t= valt" >> /etc/mysql/mysql.conf.d/mysqld.cnf
	service mysql restart
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CHANGE MASTER TO MASTER_HOST='$primaryip',MASTER_USER='$slaveuser', MASTER_PASSWORD='$slavepassword', MASTER_LOG_FILE='$logfile', MASTER_LOG_POS=  $logpos;"
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "START SLAVE;"
	cp failure.sh /usr/local/valt/bin/
	cp restore.sh /usr/local/valt/bin/
	chmod +x /usr/local/valt/bin/failure.sh
	chmod +x /usr/local/valt/bin/restore.sh
fi

failure.sh
#!/bin/bash
#This script will make the redundant VALT server the primary VALT server. 
#The DNS entry must be updated to point to this server.

echo "WARNING: DO NOT RUN THIS SCRIPT MULTIPLE TIMES!!!"
echo "MAKE SURE THE DNS ENTRY HAS BEEN UPDATED PRIOR TO EXECUTING THIS SCRIPT"
echo "Press enter to continue."
read r


if [[ $EUID -ne 0 ]]; then
        echo "You must run this script as root" 2>&1
        exit 1
else
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "STOP SLAVE;"
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "RESET SLAVE;"
	systemd-resolve --flush-caches
	systemctl enable apache2 
	systemctl enable valtcontrols
	systemctl enable WowzaStreamingEngine
	service apache2 start
	service WowzaStreamingEngine start
	service valtcontrols start
fi
restore.sh
#!/bin/bash
# This script will migrate the database and all recordings back to the primary VALT server. 
# The DNS entry must be updated to point to the primary VALT server.

primaryip="192.168.0.99"
slaveuser="ivs_user"
slavepassword="password"

echo "WARNING: DO NOT RUN THIS SCRIPT MULTIPLE TIMES!!!"
echo "MAKE SURE THE DNS ENTRY HAS BEEN UPDATED PRIOR TO EXECUTING THIS SCRIPT"
echo "Press enter to continue."
read r
export NCURSES_NO_UTF8_ACS=1 
if [[ $EUID -ne 0 ]]; then
  	echo "You must run this script as root" 2>&1
  	exit 1
else
	systemd-resolve --flush-caches
	service apache2 stop
	service WowzaStreamingEngine stop
	service valtcontrols stop
	systemctl disable apache2 
	systemctl disable valtcontrols
	systemctl disable WowzaStreamingEngine
	rsync --rsync-path="sudo rsync" -avz /usr/local/valt/records/* ivsadmin@10.111.3.73:/usr/local/valt/records/
	mysqldump --defaults-extra-file=/usr/local/valt/conf/standby.cnf --opt v3 > /usr/local/valt/backup/valt.sql
	mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf -e "DROP DATABASE valt;"
	mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf -e "CREATE DATABASE valt;"
	mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt < /usr/local/valt/backup/valt.sql
	mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt -e "FLUSH TABLES WITH READ LOCK;"
	tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt -e "SHOW MASTER STATUS\G;" | grep File)
	sqlfile=${tmp1#*:}
	tmp1=$(mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt -e "SHOW MASTER STATUS\G;" | grep Position)
	position=${tmp1#*:}
	sqlfile=$(echo $sqlfile | xargs)
	mysqldump --defaults-extra-file=/usr/local/valt/conf/primary.cnf --opt valt > /usr/local/valt/backup/valt_sync.sql
	mysql --defaults-extra-file=/usr/local/valt/conf/primary.cnf valt -e "UNLOCK TABLES;"
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "DROP DATABASE valt;"
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CREATE DATABASE valt;"
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf valt < /usr/local/valt/backup/valt_sync.sql
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "CHANGE MASTER TO MASTER_HOST="\'"$primaryip"\'", MASTER_USER="\'"$slaveuser"\'", MASTER_PASSWORD="\'"$slavepassword"\'", MASTER_LOG_FILE="\'"$sqlfile"\'", MASTER_LOG_POS = $position;"
	mysql --defaults-extra-file=/usr/local/valt/conf/standby.cnf -e "START SLAVE;"
fi