Posts

Secure server with Firewalld

Recently we have issue reported by development team that there one of the backend cache server went to production without firewall. Although server was not expose to internet but it can be accessible from every IP in intranet. We decided to use firewalld for this. Main problem was once we start service it stop all access other than ssh which can be impact service accessing to our server. Also we can't run firewall-cmd command to apply rule before staring service. Fortunately   firewalld provide option to apply rules by updating config xml files.  Its makes our task easy.  Steps to be perform task Generate xml rules in test machine. Copy xml rules file in target host  update rules in XML file then start service. ## Login to any test VM $ ssh ## Verify there is no custom added rule exist $ cat /etc/firewalld/zones/public.xml <?xml version="1.0" encoding="utf-8"?> <zone> <short>Public</short> <description>For use in public...

Setup K8s cluster via kubeadm

Kubernetes is an open source software tool for managing containerised workloads. It enables development teams to automate the deployment, scaling and management of applications. The kubeadm tool helps bootstrap a minimum viable Kubernetes cluster that conforms to best practices. This guide will walk you through how to install Kubernetes on Ubuntu 16.04. Prerequisites 3 Linux servers running Ubuntu 16.04 Access to a user account on each system with sudo or root privileges The apt package manager, included by default Command-line/terminal window (Ctrl-Alt-T) Steps to Install Kubernetes on Ubuntu Setup repository Get the Docker gpg key: $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - Add the Docker repository: $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" Get the Kubernetes gpg key: $ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - Add the...

Deploy LAMP with Vagrant and Fabric

Introduction Lets automate every thing using python and ssh. Fabric is python library and command-line tool, which use SSH for application deployment in remote servers. Install Fabric By default in all unix like machine Python is available. We can install fabric library by using utility 'pip' ## Install library for all users $ sudo pip install fabric python-vagrant ## OR Install library only for login user $ pip install fabric python-vagrant --user Create basic Vagrant file To start with fabric lets start our vagrant guest first. Please refer Vagrant Quickstart for more details on vagrant. Create directory ch2 and create basic Vagrantfile. $ mkdir ch2 ## Create Vagrant file similar to below $ cat Vagrantfile # -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure(2) do |config| config.vm.box = "bento/centos-6.7" config.vm.network "forwarded_port", guest: 80, host: 8080 end $ vagrant up Write first Fabric code Firstl...

Vagrant Quickstart

What is Vagrant? Vagrant is wrapper or collection of scripts for building and maintaining portable virtual development environment. We can say vagrant is command line script for VirtualBox (or any other individuals prefer VM environment). We will skip installation part of VirtualBox and Vagrant , as its very simple and easy, just follow instruction from there websites. When to use ? Basically vagrant is use to setup local development/testing environment. ex1) A developer 'A' written a code, he  want to check how it work with PHP5 and PHP6 .  Solution is simply deploy two guest machines (VM) with PHP5 and PHP6, Share same project dir with both VM and test it. A sysadmin 'B' written shell/python code to deploy LAMP environment, he want to test how it work with CentOS and how it work with Dabian. Lets release the kraken Assume vagrant is already installed. Search your favorite OS from here:- https://atlas.hashicorp.com/boxes/search . For example we use ...

How to delete git branch

To delete a local branch $ git branch -d the_local_branch_name To remove a remote branch (Caustion::if you know what you are doing!) $ git push origin :the_remote_branch_name

Change Input Element Type using JavaScript

You can change an input element's type, from text to password, or hidden to text for example, dynamically using JavaScript. There are a few reasons why one might need to change the type of an input element dynamically: To have a password box initially display 'type password here', but convert to a password element once it takes the focus. To make a hidden form field visible by converting it to a text element, or vice versa. Allow a user to only enter a value once by converting the element to hidden once text has been entered If you are designing a site that is intended only to run on Mozilla, Safari, or another non-Internet Explorer browser, the following code is sufficient to modify an input element's type: <script> document.getElementById('myElement').type = 'text'; </script> However, most of us find it necessary to submit to the demands of Internet Explorer. To meet these demands, we must: dynamically create a new element copy the p...

Mysql to CSV

Yesterday we have requirement to send report to our senior in excel format by retrieving data from database . Since there are only 10 rows so we can also manually create excel. But like other programmers, I am also very lazy, so that we create this script to export values from Mysql in csv format. mysql -u mysqlusername -p mysqlpass databsename -B -e "select * from \` tabalename \`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > mysql_exported_table.csv After that we fount that there are many other programming methods to perform this task.