Ubuntu keeps resetting the Laptop brightness

Atleast some of you might have noticed that Ubuntu keeps resetting the brightness level of our laptops whenever we reboot. I have found a simple solution that could atleast help you to start with a particular brightness level each time you restart. The solution is as follows:

1. First set your brightness level to the desired one and see the actual value

gopu@goputec:~$ cat /sys/class/backlight/intel_backlight/brightness
247

2. Add this value to the bottom of rc.local file (above ‘exit 0’) so that each time Ubuntu start, it will set the brightness to the value we specified in the same config file:

gopu@goputec:~$ cat /etc/rc.local 
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo 247 > /sys/class/backlight/intel_backlight/brightness
exit 0

3.Test yourself restarting the laptop.

Enjoy 🙂

Loadbalancing apache webservers using haproxy

Here I am discussing about setting up a loadbalancer using haproxy to load balance two apache

web servers.

ubuntu1 : 192.168.56.101
ubuntu2 : 192.168.56.102
ubuntu2 : 192.168.56.103

I have setup the first two servers as loadbalancer and installed haproxy on the third one. You

can use

tasksel

to setup the lamp servers easily.

To install haproxy on ubuntu3:

apt-get install haproxy

To start the haproxy at boot time, set ENABLED=1 in /etc/default/haproxy

Configuration :

1. Backup the existing configuration file

cp -pr /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bk

2. Edit the haproxy.cfg as below :

root@ubuntu3:~# more /etc/haproxy/haproxy.cfg

global
    log 127.0.0.1 local0 notice
    maxconn 2000
    user haproxy
    group haproxy

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    option redispatch
    timeout connect  5000
    timeout client  10000
    timeout server  10000


listen appname 0.0.0.0:80
    mode http
    stats enable
    stats uri /haproxy?stats
    stats realm Strictly\ Private
    stats auth Myusername1:mypassword1
    stats auth myusername2:mypassword2
    balance roundrobin
    option httpclose
    option forwardfor
    server ubuntu1 192.168.56.101:80 check
    server ubuntu2 192.168.56.102:80 check

where,
log defines syslog server where the logs should be sent to
maxconn defines the max connection loadbalancer can accept
retries specifies the max number of connection try on a back-end server
timeout connect specifies the max time LB wait for an connection to succeed
option redispatch enables session redistribution
timeout client and server specifies the send and ack time during tcp handshake process.

You can see the haproxy status through the link http://loadbalancer_ip/haproxy?stats
which we have set in uri section. The username/password that can be used is set in the next two
lines. Both of them will work.
In my case the link is

http://192.168.56.103/haproxy?stats

proxy_status

You can use different algorithm for the loadbalancing. Here we are using roundrobin. options

available are static-rr,leastconn,source,uri,url_param etc

ubuntu1 and ubuntu2 are the backend webservers we are forwarding the traffic to

Once the configurations are done, restart the services

service haproxy restart

Testing:

Create a file test.php with the web-server name as content in both the lamp servers.
Try to access the loadbalancer IP from browser and you can see the content are just changing
continuously each time you access via the browser.

To troubleshoot, check the log file : /var/log/haproxy.log

Whenever a host is not available, you can see logs similar to below :

Feb 24 16:23:31 localhost haproxy[2400]: Server appname/ubuntu2 is DOWN, reason: Layer4 

connection problem, info: "Connection refused", check duration: 1ms. 1 active and 0 backup 

servers left. 0 sessions active, 0 requeued, 0 remaining in queue.

and when it come back online :

Feb 24 16:23:31 localhost haproxy[2400]: Server appname/ubuntu2 is DOWN, reason: Layer4 

connection problem, info: "Connection refused", check duration: 1ms. 1 active and 0 backup 

servers left. 0 sessions active, 0 requeued, 0 remaining in queue.

Thanks 🙂

Ubuntu resolv.conf file keep getting reset

For the time being, you might have noticed that the manual entry inside the file resolv.conf is getting reset and you can’t ping to the public domains. For the latest ubuntu releases, we should use resolvconf to edit the dns entries and all the manual entries added directly inside resolv.conf will be overwritten when resovconf triggers the service check

To edit the entries,
vi /etc/resolvconf/resolv.conf.d/base
Add the entries (here I am using google dns) as below :

nameserver 8.8.8.8
nameserver 8.8.4.4

Restart the service as below :

service resolvconf restart

Now you can check your resolv.conf file and you would be able to see the manual entries replicated there.

root@test:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4

Thanks 🙂

Import certificate and key into jks

1. First create a p12 file and import both the certificate and key into it using openssl.

openssl pkcs12 -export -name theg -in /etc/ssl/certs/theg.crt -inkey /etc/ssl/private/theg.key -out theg.p12

2.Convert the p12 format into jks format using keytool :

keytool -importkeystore -destkeystore theg.jks -srckeystore theg.p12 -srcstoretype pkcs12 -alias theg

Note : Here I used the name theg for my certificates and alias, change it accordingly.

Install Skype in Ubuntu 14.04

A new update of Skype version (Skype 4.2) is available for Ubuntu distributions. Use the below method to install :

1. Remove the existing ones ”

$ sudo apt-get remove skype skype-bin

2. Download the debian package from the skype website :

$ sudo wget http://download.skype.com/linux/skype-ubuntu-precise_4.2.0.11-1_i386.deb

3. Install :

$ sudo dpkg -i skype-ubuntu*.deb; sudo apt-get -f install

4. Install the below necessary packages if not already installed :

In 32 bit :

$ sudo apt-get install sni-qt

In 64 bit :

sudo apt-get install sni-qt sni-qt:i386

That’s it! 🙂

MySQL Master-Master Replication

For MySQL servers above 5.5, use the below method :

Suppose servers are

server1=0.0.0.1
Server2=0.0.0.2

In Server1, change the /etc/mysql/my.cnf

server-id               = 1
log_bin                 = /var/log/mysql/mysql-bin.log
#bind-address           = 127.0.0.1

Server2, change the /etc/mysql/my.cnf

server-id               = 2
log_bin                 = /var/log/mysql/mysql-bin.log
#bind-address           = 127.0.0.1

In server1,

mysql> CREATE USER 'slave1'@'0.0.0.2' IDENTIFIED BY 'mypassword';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave1'@'0.0.0.2';

FLUSH TABLES WITH READ LOCK;

mysqldump -u root -p --all-databases --master-data > /data_dump.sql
show master status\G

note down the master values that we need to enter in the slave.

copy the bakcup to server2 and run

CHANGE MASTER TO   MASTER_HOST='0.0.0.1',   MASTER_USER='slave1',   MASTER_PASSWORD='mypassword',   MASTER_PORT=3306,   MASTER_LOG_FILE='mysql-bin.000002',   MASTER_LOG_POS=107;

start slave;

In server1,

unlock tables;

In server2,

mysql> CREATE USER 'slave2'@'0.0.0.1' IDENTIFIED BY 'mypassword';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave2'@'0.0.0.1';

FLUSH TABLES WITH READ LOCK;

show master status\G

Note down the master values that we need to enter in the next command

In server1,

mysql> CHANGE MASTER TO   MASTER_HOST='0.0.0.2',   MASTER_USER='slave2',   MASTER_PASSWORD='mypassword',   MASTER_PORT=3306,   MASTER_LOG_FILE='mysql-bin.000001',   MASTER_LOG_POS=537678;

In server2,

unlock tables;

Now create a database in server1 and check whether it is replicated in server2. If so, drop the database from server2 and confirm that it is removed from the server1 as well.

To create test database :

create database gtest;

To create test table :

CREATE TABLE gtest(id INT, name VARCHAR(20), email VARCHAR(20));

To Delete database :

drop database gtest;

To delete table

drop table gtest

Thanks 🙂