MySQL 5.7 Active-Active replication on Ubuntu 16 Lts


For this recipe we got two identical (virtual) nodes, Both Ubuntu 16Lts, Quad CPU, 16G ram, OS on a 16G vda1, and a 2T data partition on vda2
Two network interfaces, 1st is public (192.168.32.x/24) and second in the replication network on 10Gbe (192.168.33.0/24)

DB01:
eth0 192.168.32.13
eth1 192.168.33.14
DB02:
eth0 192.168.32.23
eth1 192.168.33.23

First, set up both nodes for replication, Edit /etc/mysql/mysql.conf.d/mysqld.cnf
<snip>
bind-address            = 0.0.0.0
server-id               = 10 (20 for DB02)
log_slave_updates       = 1
log_bin                 = /var/log/mysql/mysql-bin.log
log_bin_index           = /var/log/mysql/mysql-bin.log.index
relay_log               = /var/log/mysql/mysql-relay-bin
relay_log_index         = /var/log/mysql/mysql-relay-bin.index
log-error = /var/log/mysql/error.log
auto_increment_increment = 2
auto_increment_offset = 1
expire_logs_days        = 10
max_binlog_size         = 100M
</snip>

Then restart Mysql: service mysql restart

On DB01 do mysql -u root -p and login

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000019 |      154 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

The file and position are needed for the master configuration on DB02, this is no longer done in the my.cnf file but in the DB, so open up mysql on DB02 and configure:

change master to master_host='192.168.33.13', master_user='slaveuser', master_password='somesupersecretpassword', master_log_file='mysql-bin.000019', master_log_pos=154, master_port=3306
grant replication slave on *.* to slaveuser@'db01.yourdomain.com' identified by 'somesupersecretpassword';
grant replication slave on *.* to slaveuser@'192.168.33.13' identified by 'somesupersecretpassword';
flush privileges;
start slave;
slave status \G;

Now you have one way replication, to make it two way, do a show master status on DB02, and do the same configuration on DB01, replacing .13 with .23 and db01 with db02 and of course the file and position values where applicable.

Now create some databases and see them appear on the other side.

Note, this does not replicate existing databases, this is meant for a CLEAN server. If you have existing databases,  you will first need to backup/restore them to the replica node before setting up the replication. If you do any action on a pre-existing DB the replication will halt, when this happens, just do a show master on the source and get the file and position values, then reset the replication on the slave DB (first stop the replication slave with stop slave, start it again when done.

InfluxDB IfHCInOctets Query


Some basic SQL for InfluxDB to fetch the SNMP ifHCInOctets from a table and show them as per minute Mbit/S, hope it helps you make beautiful graphs

select (8*derivative(mean(ifHCInOctets)) / 60)/1024 as value  from ifHCInOctets where time > now() - 1d and host = '172.16.1.13' and instance = 'pppoe0' GROUP BY time(1m)

172.16.1.13 is some router of course (we poll VyOS devices) and ‘pppoe0’ is an interface (could be eth0,eth1 etc etc)

Cheers

J

Screenshot from 2016-03-26 18:03:54

VyOS Backup


Want to make backups of your VyOS router/firewall, This little script might help, It takes the config and converts it into set commands for easy restore on another box. We push it to an RSYNC on a ZFS/Nexenta server, but you put it anywhere as you like. Schedule it through Cron or better through the system task scheduler.

Don’t forget to use the commit archive to record your changes for the audit trails, like so :

set system config-management commit-archive location 'scp://admin:<password>@x.x.x.x/volumes/pool1/backup/vyos'

VyOS backup.sh Script: (store in /config/scripts/backup/ and do not forget to make it executable : chmod +x /config/scripts/backup/backup.sh)

# Vyos (1.6) Backup Script (jkool@integrative.it)
# Fetch me with scp root@x.x.x.x:/volumes/pool1/backup/vyos/backup.sh /config/scripts/backup/backup.sh
# Keep 5 versions local 
#
# Schedule with:
#
# set system task-scheduler task backup executable path '/config/scripts/backup/backup.sh'
# set system task-scheduler task backup interval '8h'

h=$(hostname)
d=$(date +"%Y%m%d%H%M")
dest=192.168.1.200::pool1_backup/vyos
scripts=/config/scripts/backup

cd $scripts

tar -czf $scripts/backup-auth-$h-$d.tar.gz /config/auth
/opt/vyatta/sbin/vyatta-config-gen-sets.pl > $scripts"/backup-config-"$h"-"$d".txt"

ls -F backup-config-$h*.txt | head -n -5 | xargs rm
ls -F backup-auth-$h*.tar.gz | head -n -5 | xargs rm

rsync $scripts/backup-config-$h-$d.txt $dest/$h
rsync $scripts/backup-auth-$h-$d.tar.gz $dest/$h



VMware tools on Ubuntu 12.04 LTS from Repository


Task for today, equip a couple of dozen VM’s with VMware Tools. I hate manual labor so I hacked up this little script.

Make sure current VMware tools or open-vm tools are uninstalled and purged otherwise this will crap out.

# Fetch the key

apt-get install python-software-properties –yes
wget http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-RSA-KEY.pub
apt-key add VMWARE-PACKAGING-GPG-RSA-KEY.pub
rm VMWARE-PACKAGING-GPG-RSA-KEY.pub

# Add the Repo to APT, and remove sources (we remove all sources, but you can specify to remove only
# VMware sources (since they are not published and will end up in an error)

apt-add-repository ‘deb http://packages.vmware.com/tools/esx/5.0latest/ubuntu precise main’ && wait
# We dont want any sources by default
sed -i ‘s/deb-src/#deb-src/g’ /etc/apt/sources.list

 

# Install the tools

apt-get update &&
# Check Kernel version, we use 12.04 LTS ONLY, esx-nox is NO GFX support, as it should be
apt-get install vmware-tools-esx-kmods-3.2.0-23-generic vmware-tools-esx-nox –yes &&
apt-get upgrade –yes && wait

 

Ce’st ca, all done.

How to install ESXi on those darn cheap-ass SanDisk Cruzer fit sticks


It took me some time to figure out, but for my next batch of ESXi hosts for our cloud platform I simply refused to go to the WanChai computer center again to buy new USB sticks, as I still had a batch of those SanDisk Cruzer Fit sticks lying around from my previous attempt. Last time, because of time constraints, I had to take the easy route and go and buy HP branded stuff for our army of BL495. But today we received another 16 or so 495’ers to fill up another enclosure, and as said, I refused to go out to the computer-center to buy sticks again, it bloody pouring out there 🙂

So I dug in to this and with a little help from google and the syslog logs, I figured it out, It seems that ESXi wan’t to format the USB stick with a GPT partition, which some sticks like these SanDisk Cruzers, won’t take. Now to force the installed to use classic MBR, upon install, on the boot screen press SHIFT-O for the boot options of runweasel.

Remove whatever you see there and just replace it with runweasel formatwithmbr press enter, and voila, your install will proceed, format the stick, install the binaries, and most important, boot from it on next reboot.

Paraprosdokians


A paraprosdokian is a figure of speech in which the latter part of a sentence or phrase is surprising or unexpected in a way that causes the reader or listener to reframe or reinterpret the first part. It is frequently used for humorous or dramatic effect, sometimes producing an anticlimax. e.g. “Where there’s a will, I want to be in it.” (Wikipedia)

1. Do not argue with an idiot. He will drag you down to his level and beat you with experience.
2. The last thing I want to do is hurt you. But it’s still on my list.
3. Light travels faster than sound. This is why some people appear bright until you hear them speak.
4. If I agreed with you, we’d both be wrong.
5. We never really grow up, we only learn how to act in public.
6. War does not determine who is right – only who is left.
7. Knowledge is knowing a tomato is a fruit. Wisdom is not putting it in a fruit salad.
8. Evening news is where they begin with ‘Good Evening,’ and then proceed to tell you why it isn’t.
9. To steal ideas from one person is plagiarism. To steal from many is research.
10. A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
11. I thought I wanted a career. Turns out I just wanted a salary.
12. Whenever I fill out an application, in the part that says, ‘In case of emergency, notify:’ I put ‘DOCTOR.’
13. I didn’t say it was your fault, I said I was blaming you.
14. Women will never be equal to men until they can walk down the street with a bald head and a beer gut, and still think they are sexy.

15. Behind every successful man is his woman. Behind the fall of a successful man is usually another woman.
16. A clear conscience is the sign of a fuzzy memory.
17. I asked God for a bike, but I know God doesn’t work that way. So I stole a bike and asked for forgiveness.
18. You do not need a parachute to skydive. You only need a parachute to skydive again.
19. Money can’t buy happiness, but it makes misery easier to live with.
20. There’s a fine line between cuddling and holding someone down so they can’t get away.
21. I used to be indecisive. Now I’m not so sure.
22. You’re never too old to learn something stupid.
23. To be sure of hitting the target, shoot first and call whatever you hit the target.
24. Nostalgia isn’t what it used to be.
25. Change is inevitable, except from a vending machine.
26. Going to church doesn’t make you a Christian any more than standing in a garage makes you a car.
27. A diplomat is someone who tells you to go to hell in such a way that you look forward to the trip.
28. Hospitality is making your guests feel at home even when you wish they were.
29. I always take life with a grain of salt…. plus a slice of lemon, and a shot of tequila.
30. When tempted to fight fire with fire, remember that the Firemen usually use water.

“I have come to the conclusion that politics is too serious a matter to be left to politicians.” Charles de Gaulle (1890 – 1970)

“Crime does not pay as well as politics.” – Alfred E Neuman(IN CASE YOU DON’T KNOW, HE IS THE CHARACTER IN THE “MAD MAGAZINE”!)

Letter from the Queen


To the citizens of the United States of America from Her Sovereign Majesty Queen Elizabeth II:

In light of your immediate failure to financially manage yourselves and also in recent years your tendency to elect incompetent Presidents of the USA and therefore not able to govern yourselves, we hereby give notice of the revocation of your independence, effective immediately. (You should look up ‘revocation’ in the Oxford English Dictionary.)

Her Sovereign Majesty Queen Elizabeth II will resume monarchical duties over all states, commonwealths, and territories (except Kansas , which she does not fancy).

Your new Prime Minister, David Cameron, will appoint a Governor for America without the need for further elections.

Congress and the Senate will be disbanded. A questionnaire may be circulated sometime next year to determine whether any of you noticed.

To aid in the transition to a British Crown dependency, the following rules are introduced with immediate effect:

1. The letter ‘U’ will be reinstated in words such as ‘colour,’ ‘favour,’ ‘labour’ and ‘neighbour.’ Likewise, you will learn to spell ‘doughnut’ without skipping half the letters, and the suffix ‘-ize’ will be replaced by the suffix ‘-ise.’Generally, you will be expected to raise your vocabulary to acceptable levels. (look up ‘vocabulary’). (I love that one)

Using the same twenty-seven words interspersed with filler noises such as ”like’ and ‘you know’ is an unacceptable and inefficient form of communication. There is no such thing as U.S. English. We will let Microsoft know on your behalf. The Microsoft spell-checker will be adjusted to take into account the reinstated letter ‘u” and the elimination of ‘-ize.’ ‘ (I love that one too)

3. July 4th will no longer be celebrated as a holiday.

4. You will learn to resolve personal issues without using guns, lawyers, or therapists. The fact that you need so many lawyers and therapists shows that you’re not quite ready to be independent. Guns should only be used for shooting grouse. If you can’t sort things out without suing someone or speaking to a therapist, then you’re not ready to shoot grouse.

5. Therefore, you will no longer be allowed to own or carry anything more dangerous than a vegetable peeler. Although a permit will be required if you wish to carry a vegetable peeler in public.

6. All intersections will be replaced with roundabouts, and you will start driving on the left side with immediate effect. At the same time, you will go metric with immediate effect and without the benefit of conversion tables. Both roundabouts and metrication will help you understand the British sense of humour.

7. The former USA will adopt UK prices on petrol (which you have been calling gasoline) of roughly $10/US gallon. Get used to it.)

8.You will learn to make real chips. Those things you call French fries are not real chips, and those things you insist on calling potato chips are properly called crisps. Real chips are thick cut, fried in animal fat, and dressed not with catsup but with vinegar.

9. The cold, tasteless stuff you insist on calling beer is not actually beer at all. Henceforth, only proper British Bitter will be referred to as beer, and European brews of known and accepted provenance will be referred to as Lager. New Zealand beer is also acceptable, as New Zealand is pound for pound the greatest sporting nation on earth and it can only be due to the beer. They are also part of the British Commonwealth – see what it did for them. American brands will be referred to as Near-Frozen Gnat’s Urine, so that all can be sold without risk of further confusion.

10. Hollywood will be required occasionally to cast English actors as good guys. Hollywood will also be required to cast English actors to play English characters. Watching Andie Macdowell attempt English dialogue in Four Weddings and a Funeral was an experience akin to having one’s ears removed with a cheese grater.

11. You will cease playing American football. There are only two kinds of proper football; one you call soccer, and rugby (dominated by the New Zealanders). Those of you brave enough will, in time, be allowed to play rugby (which has some similarities to American football, but does not involve stopping for a rest every twenty seconds or wearing full kevlar body armour like a bunch of nancies).

12. Further, you will stop playing baseball. It is not reasonable to host an event called the World Series for a game which is not played outside of America . Since only 2.1% of you are aware there is a world beyond your borders, your error is understandable. You will learn cricket, and we will let you face the Australians (World dominators) first to take the sting out of their deliveries.

13. You must tell us who killed JFK. It’s been driving us mad.

14. An internal revenue agent (i.e. tax collector) from Her Majesty’s Government will be with you shortly to ensure the acquisition of all monies due (backdated to 1776).

15. Daily Tea Time begins promptly at 4 p.m. with proper cups, with saucers, and never mugs, with high quality biscuits (cookies) and cakes; plus strawberries (with cream) when in season.

God Save the Queen!