Category Archives: Linux

GIT basic commands

Check branch

git branch <name new branch>

Show changes after your last commit

git diff

rollback to previous change (specific file) to the latest commit

git checkout -- testfile

Delete branch

git branch -D <branch name>

Push new branch to the origin (my ‘git space’)

git push -u origin <branch name>

Restore file from upstream

git checkout upstream/master -- <filename>

Commit changes in one single line

git commit -a -m "comment"

If you want to merge the recent changes committed on the master branch into your dev branch

git checkout dev      # gets you "on branch dev"
git fetch origin        # gets you up to date with origin
git merge origin/master

If you want to reset ALL from the version ‘on the web’

git fetch origin
git reset --hard origin/<branch>

Source: http://rogerdudler.github.io/git-guide/

Docker basic commands

Check containers

# docker ps -a

Connect to a container

# docker start <ID>
# docker attach <ID>

Exit from a container

-> type 'exit'

Remove all of Docker containers:

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

NSCD – Cache DNS requests

DNS queries can be an issue on Cloud infrastructure, where SaaS are generally configured using FQDN instead of IP. This means that every time your application needs MySQL or Redis or any of the Platform/Software as a service, a DNS query will be issued.

Sometimes this could hammer the local DNS and service providers might block your DNS traffic.

To minimise this, you could use nscd to cache the DNS queries and reduce the traffic to the local DNS servers.

>> Test if port 53 has been blocked
tcpdump -vvv -s 0 -l -n port 53

>> Check what is currently cached
nscd -g (and check hosts cache)

>> Configuration file
grep -v "^#" /etc/nscd.conf (leaving only 'hosts' details)

	server-user		nscd
	debug-level		0
	paranoia		no

	enable-cache		hosts		yes
	positive-time-to-live	hosts		3600
	negative-time-to-live	hosts		20
	suggested-size		hosts		211
	check-files		hosts		yes
	persistent		hosts		yes
	shared			hosts		yes
	max-db-size		hosts		33554432

Improve/Ubuntu-like Font Rendering in Debian using Infinality Font

/etc/apt/sources.list

#Infinality Fonts
deb http://ppa.launchpad.net/no1wantdthisname/ppa/ubuntu saucy main

apt-get install fontconfig-infinality

cd /etc/fonts/infinality/
bash infctl.sh setstyle

chose 3 (i.e. linux).

In /etc/profile.d/infinality-settings.sh --> search for “USE_STYLE” or scroll (around line 710) till you see the option to set the style => USE_STYLE=”UBUNTU”


Settings -> Appearance.

    Tick the checkbox to Enable anti-aliasing
    Set Sub-pixel order to RGB
    Set Hinting to Slight


======================================

Personally installed before also: cabextract fonts-liberation ttf-mscorefonts-installer


======================================

Other fonts:

1) Install pretty fonts (you'll need non-free for mscorefonts): apt-get install ttf-dejavu ttf-liberation ttf-mscorefonts-installer xfonts-terminus
2) dpkg-reconfigure fontconfig-config, select Autohinter, Automatic and No
3) dpkg-reconfigure fontconfig
4) Restart Xorg
5) Gnome-specific (these are largely personal preferences): System -> Preferences -> Appearances -> Fonts: Enable 'Best Shapes', Details -> Dots per Inch: 110, Smoothing -> Grayscale

======================================

Source: http://linuxpanda.wordpress.com/2014/03/14/improve-ubuntu-like-font-rendering-in-debian-using-infinality-font/

Rackspace – Reinstall Nova-Agent

apt-get purge nova-client
apt-get update && apt-get upgrade

Used this script to re-install nova-agent: https://github.com/rackerlabs/openstack-guest-agents-unix/blob/master/tools/nova-agent-builder.sh

>> extract the tar and ./install.sh

sed '1i### BEGIN INIT INFO\n# Provides: Nova-Agent\n# Required-Start: $remote_fs $syslog\n# Required-Stop: $remote_fs $syslog\n# Default-Start: 2 3 4 5\n# Default-Stop: 0 1 6\n# Short-Description: Start daemon at boot time\n# Description: Enable service provided by daemon.\n### END INIT INFO\n' /usr/share/nova-agent/1.39.1/etc/generic/nova-agent > /usr/share/nova-agent/1.39.1/etc/generic/nova-agent.lsb

cp /usr/share/nova-agent/1.39.1/etc/generic/nova-agent.lsb /etc/init.d/nova-agent

chmod +x /etc/init.d/nova-agent

service xe-linux-distribution stop
service xe-linux-distribution start
service nova-agent start

# ps aux | grep nova
root      7874  0.0  0.7 143984  7464 ?        Ssl  09:02   0:00 /usr/sbin/nova-agent -q -p /var/run/nova-agent.pid -o /var/log/nova-agent.log -l debug /usr/share/nova-agent/nova-agent.py
root      7890  0.0  0.0  11980   928 pts/0    S+   09:03   0:00 grep --color=auto nova


Sources:
http://www.syntheticworks.com/rackspace-cloud/linux-rackspace-cloud/all-about-nova-agent-linux/
https://github.com/rackerlabs/openstack-guest-agents-unix/blob/master/tools/nova-agent-builder.sh
http://bootrackspacecom.readthedocs.org/en/latest/nova_agent/

Rackspace Cloud – .localdomain added in /etc/hosts after reboot

There is an agent called “nova-agent” which runs on all Rackspace cloud virtualised servers. This agent handles all communication between the hypervisor and guest OS, and is used for decloning.

Because it is used during decloning, it owns the /etc/hosts file and many files related to DNS and networking (/etc/resolv.conf , /etc/sysconfig/network-scripts/ifcfg-eth0 ,etc)

It is unlikely, but possible, that the host reboot triggered nova-agent to reset your hosts file.

To prevent nova-agent from overwriting your files, you can change the attributes of the file using the following command:

# chattr +i /etc/hosts

This will make the file unwriteable even to root! To remove this restriction, use the following:

# chattr -i /etc/hosts

Rackspace Cloud – Automatic delete orphan backup agent IDs

>> set your variables:
TOKEN=""
REGION="lon"
DDI=""  < this is the account number

>> Generate a list of backup agents
curl -sH  "X-Auth-Token: $TOKEN" -H "Content-type: application/json" -X GET https://$REGION.backup.api.rackspacecloud.com/v1.0/$DDI/user/agents | python -m json.tool | egrep "MachineName|MachineAgentId" | awk -F":" '{print $2}' | sed 's/ //g' | sed '{N;s/\n//}' > list.txt

>> Manually remove WANTED backup agents (leave only the ones you want to remove):
vim list.txt 

>> Generate remove list
awk -F, '{print $1}' list.txt > remove.txt


>> generate the exec file to review
for AGENTID in `cat remove.txt`; do echo curl -sH \"X-Auth-Token: $TOKEN\" -H \"Content-type: application/json\" -X POST https://$REGION.backup.api.rackspacecloud.com/v1.0/$DDI/agent/delete -d \'{\"MachineAgentId\": $AGENTID}\' ; done >> exec_me

>> exec the API calls
/bin/bash exec_me

PHP Sessions in Redis

If your php application requires sessions and it’s hosted on a scaled high available infrastructure, it’s required to have these sessions stored on a decentralised and HA platform as well, in order to avoid to rely on session persistent options on the load balancer or another Cloud Server.
Redis as a Service is a nice fit for this purpose.

Here an example using Rackspace Object Rocket http://www.rackspace.co.uk/objectrocket/redis

To achieve this it’s required to install the right package.

In Centos/RHEL, there is the IUS package available:

yum install php56u-pecl-redis

After that, the php.ini should be changed like this:

 session.save_handler = redis 
 session.save_path = "tcp://REDISOBJECTROCKETFQDN:PORT?auth=REDISPASSWORD"

To increase performance and reduce the “noise” for repetitive DNS queries (especially in case of SaaS which uses FQDN instead of an IP) it is also recommended to install nscd to cache the DNS queries.

Linux Cloud Server migration script

This script allows you to migrate a Linux Server from one server to another one. It uses rsync and it could be use when you need to resize down a server for example, or if you want to migrate onto another Cloud Provider.

git clone git://github.com/cloudnull/InstanceSync.git

Source:
http://cloudnull.io/2012/07/cloud-server-migration/
https://github.com/cloudnull/InstanceSync