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.

Add new line after some text

Today I face a problem related with editing in css file. I downloaded one css file but when I open it in my fedora 11, I find that all code are written in an single line. Its very difficult to understand that code. First i try to format it manually, but then I decide to find some script or use replace feature of my favourite vi editor. After 5 minute struggle I found the solution, here it is- sample css code:- ================================================ BODY{background-color:#70a5cc;font-family:verdana, arial, helvetica,sans-erif;font-size:10pt;color:#333;margin:0 0 10px}ul{margin-left:25px}dl{margin-top:0;padding-left:1px}dt{margin-top:.5em;color:#009;font-weight:700} ================================================ Note: all are in single line Step 1: open file in vi editor. Step 2: In command mode type: a) :%s/{/{\r /gi explanation:- above line break the line after every '{' tag and give two space in new line. syntax:- :%s/ / /gi ...

Repair Ntldr in Windows Xp

To resolve this behavior, replace the Windows XP Ntldr and Ntdetect.com files. Follow these steps: Start the Recovery Console, type fixboot at the prompt, and then press ENTER. If the Recovery Console does not appear, follow these steps: Use one of the following methods to start the computer so that you can access the file system of the boot partition: Specify another operating system on the Boot menu. Start from the Windows XP CD-ROM, and then at the Windows Setup screen, press "R" to use the Recovery Console to repair the Windows installation. Use a Windows NT 4.0 boot disk that also contains the Windows XP boot files. If your boot partition is a basic disk that is formatted with the FAT file system, use an MS-DOS boot disk. Copy the Ntldr and Ntdetect.com files from the I386 folder on the Windows XP CD-ROM to the root folder of your boot drive. The boot drive is typically drive C. If you are using MS-DOS to perform this file replacement, you may have to remove the ...

Prevent USB Drives from Spreading Viruses

Disable the autorun feature 1. Launch the Registry editor ( Start | Run | regedit ); 2. Navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\ CurrentVersion\Policies\Explorer; 3. Double-click NoDriveTypeAutoRun in the right-hand pane and set its value to hexadecimal FF .

Phpize give error

I'm trying to execute phpize: phpize: line 57: aclocal: command not found I've just installed: automake autoconf by using RPMs.

Apache:400 Bad request

Error message in Browser- Bad Request Your browser sent a request that this server could not understand. Apache/2.2.0 (Fedora) Server at 10.129.150.205 Port 80 Entry in Apache Error Log- [Wed Dec 17 13:15:23 2008] [error] [client 10.129.150.205] ModSecurity: Access denied with code 400 (phase 2). Pattern match "^[\\\\d\\\\.]+$" at REQUEST_HEADERS:Host. [id "960017"] [msg "Host header is a numeric IP address"] [severity "CRITICAL"] [hostname "10.129.150.205"] [uri "/"] [unique_id "Qi9cCgqBls0AACJ-VCgAAAAF"] Solution- Check "/etc/httpd/modsecurity.d" directory and modify file "modsecurity_crs_21_protocol_anomalies.conf " modsecurity_crs_21_protocol_anomalies.conf ---------------------------------------------------------------- # # Check that the host header is not an IP address # SecRule REQUEST_HEADERS:Host "^[\d\.]+$" "deny,log,auditlog,status:400,msg:'Host header is a numeric ...

Run SQL query from shell prompt

mysql -u user -p -e 'SQL Query' database Where, -u : Specify mysql database user name -p : Prompt for password -e : Execute sql query database : Specify database name To list all database, enter: $ mysql -u replicant -p -e 'show databases;' To list count all rows, enter: $ mysql -u replicant -p -e 'SELECT COUNT(*) FROM remote_logs' Sample output: Enter password: +----------+ | count(*) | +----------+ | 471 | +----------+ Tell mysql to display output a page at a time, by using more or less pager: $ mysql --pager=/usr/bin/less -u replicant -p -e 'SELECT COUNT(*) FROM remote_logs' Redirect out to a file: $ mysql -u replicant -p 'PassWord' -e 'SELECT COUNT(*) FROM quotes' remote_logs > sql.output.txta To avoid password prompt just create ~/my.cnf file: [client] # for local server #host=localhost host=10.128.150.205 user=replicant password=myPassword [mysql] pager=/usr/bin/less

Html performance

HTML is a very flexible language. It never generates errors, and often provides many different ways to accomplish a single task. For example, a list item can be specified as <LI>description or <LI>description</LI>. The only difference is the closing </LI> tag, but it might be biggest mistake. If these tags don't close, the browser renders pages just fine. But if tags are closed then it will render the pages even faster. Take a look at the following code segment: <P>Here is a list of names: <UL> <LI>Kanpur <LI>Jhanshi <LI>Lucknow <LI>Pune <LI>Bangalore </UL> In above example, the <P> and <LI> items are included without their closing counterparts. When parsing such HTML code, the browser needs to look ahead to find out where the paragraph or list item ends. The following code generates the same output in a more efficient method: <P>Here is a list of names :</P> <UL> <LI>Kanpu...

Mysql Prompts

You can change the prompt on the MySQL command-line tool to show user name, time, current database or many other useful facts. mysql> prompt \R:\m:\s> PROMPT set to '\R:\m:\s>' 11:46:16>show tables; +----------------------+ | Tables_in_wordpress | +----------------------+ | wp_categories | | wp_comments | | wp_linkcategories | +---------------------+ 9 rows in set (0.00 sec) 11:46:24> If you specify the prompt command with no argument, mysql resets the prompt to the default of mysql> . The prompt command reconfigures the default mysql> prompt. The string for defining the prompt can contain the following special sequences: Option Description \c A counter that increments for each statement you issue \D The full current date \d The default database \h The server host \l The current delimiter (new in 5.0.25) \m Minutes of the current...

isset for javascript

try{ if(variablename){ // If true // write your code here } }catch(e){ //If false // write your code here if false }

Mass Replace String in MySQL Database

Problem: I want to change url path or a string from mysql table. Solution: Do it manually? No way. There are hundreds of them! There are basically two ways - First, output the database table and use text editor's "search and replace" function. Second, use MySQL REPLACE function . Here is the SQL query to replace string in database table :- UPDATE table_name SET column_name = REPLACE ( column_name, "original_string" , "replace_string" );

Download multiple files from FTP

Problem : When we download multiple file from command line ftp, it prompt for every file. Solution: ftp> prompt ftp> mget *.* or ftp> mget

Mysql:Reset Auto increment No.

I have a database table with a auto increment column for primary key. As the records being add and delete many times, the auto increment value will keep increasing. Problem One: I want to delete all data from table. Solution: TRUNCATE table tbl_name this command will delete everything from the table and start again from 1.... DELETE just does the same but keeps the current auto_increment value.... Problem Two: If I have entered 10 records, and deleted 9th, 10th records. The next auto increment value will be 11, not 9. Solution: Run a query: ALTER TABLE tablename AUTO_INCREMENT = 1 This will reset the next auto increment value to current largest value in the auto increment column + 1. So, the auto increment value of next inserted record will start from 9. Problem Three: If I have entered 10 records, and deleted center records - 4th, 5th. I want to insert next record as 4th not 11th. Solution: Run the following query: SET insert_id = 4; INSERT INTO tablename VALUES (’blah’, ‘…’);...

Inbound connections limit in Windows XP

SYMPTOMS At a computer that is running Windows XP or Windows 2000, when you attempt to connect to another Windows XP computer, you may receive the following error message: No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept. CAUSE This behavior occurs if the computer reaches the maximum number of inbound connections that the computer can host. ALTERNATIVE SOLUTION You can configure the AutoDisconnect time by running the following command from a command prompt: net config server /autodisconnect: time_before_autodisconnect Specify the time in minutes. For more information- http://support.microsoft.com/kb/314882