HAPROXY, The easy load balancer

Posted Leave a comment

Load balancing the easy way, with haproxy. I use this all the time with docker. This example will balance 53, across 6 DNS backends. To tweak for your use, you can change the stats port, username and password, and backend servers to your setup.

port 1936 will show the cluster health page. port 53 will round-robin balance across the 6 hosts, and will also pull them out if not healthy, adding them back once health checks pass!

        log   local0
        log   local1 notice
        maxconn 4096
        chroot /var/lib/haproxy
        user haproxy
        group haproxy

        log     global
        mode    http
        option  httplog
        option  dontlognull
        option redispatch
        retries 3
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen stats :1936  
        mode http
        stats enable
        stats auth username:password

listen myservice :53  
        mode tcp
        option tcplog
        balance roundrobin

        server dns0 check
        server dns1 check
        server dns2 check
        server dns3 check
        server dns4 check
        server dns5 check

Restoring mssql .bak file Linux mssql server

Posted Leave a comment

To restore a mssql database backup to a linux host, using default microsoft install locations:

/opt/mssql-tools/bin/sqlcmd -S hostname -U user -P Password! -Q "RESTORE DATABASE [mydatabase] FROM DISK = N'/tmp/backupStandard.bak' WITH FILE = 1, NOUNLOAD, REPLACE, NORECOVERY, STATS = 5"

If you see an error like this

The backup set holds a backup of a database other than the existing 'mydatabase' database.  
Msg 3013, Level 16, State 1, Server ms-sql, Line 1  
RESTORE DATABASE is terminating abnormally.  

Use something like the following. It’s caused by creating an empty database to restore to, WITH REPLACE just makes tsql replace the table.

/opt/mssql-tools/bin/sqlcmd -S localhost -U user -P Hunter2! -Q "RESTORE DATABASE [database] FROM DISK='/path/to/backup.bak' WITH REPLACE.

Installing MS-SQL on CentOS 7

Posted Leave a comment

This setup is using an instance within Google Cloud Platform’s Compute Engine, but it should work about anywhere running CentOS 7+. I added this here because I needed to try mssql on Centos, an unsupported distro. Other howto’s online I found did not work, or did not completely set it up in a usable form. This worked great for me. Let me know if you have issues.

Installing mssql server in linux

gcloud compute ssh instancename

obtain root

sudo su -
cd /etc/yum.repos.d/

grab the repo file(s) with wget, and store it/them in /etc/yum.repos.d/

wget https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo 

you might want to grab the cli client for linux as well. You can grab the repo here:

wget https://packages.microsoft.com/config/centos/7/prod.repo

now we’ll install mssql-server-2017 and the cli-client

sudo yum install mssql-server-agent mssql-server

and install the command line client:

sudo yum install mssql-cli

At this point, ms-sql is installed. We need to set up the new server.

cd /opt/mssql/bin/
./mssql-conf setup

you should be greeting with the following screen to pick your license.

[root@ms-sql bin]# ./mssql-conf setup
Choose an edition of SQL Server:  
  1) Evaluation (free, no production use rights, 180-day limit)
  2) Developer (free, no production use rights)
  3) Express (free)
  4) Web (PAID)
  5) Standard (PAID)
  6) Enterprise (PAID)
  7) Enterprise Core (PAID)
  8) I bought a license through a retail sales channel and have a product key to enter.

Details about editions can be found at  

Use of PAID editions of this software requires separate licensing through a  
Microsoft Volume Licensing program.  
By choosing a PAID edition, you are verifying that you have the appropriate  
number of licenses in place to install and run this software.

Enter your edition(1-8): 3  
The license terms for this product can be found in  
/usr/share/doc/mssql-server or downloaded from:

The privacy statement can be viewed at:  

Enter the SQL Server system administrator password:  
Confirm the SQL Server system administrator password:  
Configuring SQL Server...

The licensing PID was successfully processed. The new edition is [Express Edition].  
ForceFlush is enabled for this instance.  
ForceFlush feature is enabled for log durability.  
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.  
Setup has completed successfully. SQL Server is now starting.  

The wizard will walk you though picking your licenses, and sa password. Once the password is set, SQL server will start, licensed

[root@ms-sql bin]# mssql-cli 
Username (press enter for sa):
Version: 0.13.0
Mail: sqlcli@microsoft.com
Home: http://github.com/dbcli/mssql-cli

Installing X2go Centos 7

Posted Leave a comment

For this we need to ad EPEL repo, add it as follows:

sudo yum install epel-release

Installing x2go

yum install -y x2goserver-xsession

Installing Xfce:

yum groupinstall -y "Xfce"

once the machine is restarted

Note: As much as I prefer the gnome-desktop or cinnamon-desktop environments, I could not make it work. If you find a way to make it work please feel free to leave a comment. Xfce is fine for basic remote desktop access.

If you need to open SSH

firewall-cmd --permanent --zone=public --add-service=ssh
firewall-cmd --reload


To install x2go client on fedora

sudo yum install epel-release x2go-client

Installing Xvfb in Centos 6-7

Posted Leave a comment

Xvfb, or X virtual frame buffer is needed by selenium and chromedriver or gekodriver, so it can srun via cron with your PC locked, or without your script taking focus from the user section

The Xvfb, or “X virtual frame buffer” will allow scripts and apps to run, within their own virtual x windows session. It allows you to write chromedriver scripts to do cool things on the web, and run them without them stealing focus in your local session.

# yum install -f chromedriver chromium xorg-x11-server-Xvfb
Example Python utilizing a virtual framebuffer:
from selenium import webdriver  
from pyvirtualdisplay import Display  
display = Display(visible=0, size=(800, 800))  
outputdir = "/tmp"  
options = webdriver.ChromeOptions()  
options.binary_location = '/bin/google-chrome'  
service_log_path = "{}/chromedriver.download_tax_rates.log".format(outputdir)  
service_args = ['--verbose']  
driver = webdriver.Chrome('/bin/chromedriver',  

#open connection
# driver = webdriver.Chrome()
#open chrome to first page