Bala's Blog

JOY OF PROGRAMMING

Category: Uncategorized

Nginx Config for load balancing ( using UPStream module)

Upstream module in nginx gives the way for load balancing.

The below is the nginx config for load balancing two redis slaves

upstream app_cluster_1 {
server 127.0.0.1:6379;
server 127.0.0.1:6380;
}

server {
listen 0.0.0.0:8001;
server_name nodetest.local nodetest;
access_log /var/log/nginx/nodetest.log;
error_log /var/log/nginx/nodetesterrot.log;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;

proxy_pass http://app_cluster_1/;
proxy_redirect off;
}

}

Advertisements

HAProxy Config for Load balancing the servers

I tried using HAPRoxy for load balancing between the app servers as well as the database slaves.

The generic config for the HAPRoxy is

global
pidfile /tmp/haproxy-queue.pid

defaults
mode tcp
balance roundrobin
option httpclose
option forwardfor

listen redis 0.0.0.0:8011
server server5 127.0.0.1:6379 maxconn 1 check
server server6 127.0.0.1:6380 maxconn 1 check

 

For getting realtime statistics

the below config is used and the port can be used to get the statistics

listen stats :1936
mode http
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /

Supervisord utility – 1

The supervisord utility is very much useful for starting , restarting and stopping the process even from remote machines without given the access previlages to the machine.

The supervisord can be installed by using the following steps in the Installation of Supervisord

This can be done when we have python installed in our machine.

 

 

More on this will be on the upcoming posts…

Restore Panels In Ubuntu Back To Their Default Settings

Messed up your panels in Gnome? Maybe your new to Ubuntu and accidentally deleted items or the panel itself and now you can’t figure out how to get it back.

Sure, you can add a new panel and rebuild it by adding the items back on the panel.

Instead of going through the trouble, there is an easy fix that will restore your panels back to their default settings quickly.

Open up a Terminal window, by clicking on Applications \ Accessories \ Terminal. Or, if you deleted the top panel and cannot access the menus, just press ALT+F2 and in the run dialog box, type gnome-terminal then click on Run.

You can also browse for applications, such as Terminal from the Run window, by clicking on the arrow icon next to ‘Show list of known applications” and browse for Terminal.

gnomedefaultpanel.png

Once the Terminal window opens, enter the following command at the prompt:

gconftool-2 – -shutdown

(Note: There should be no spaces between the two dashes before shutdown.)

EDIT – Reader nickrud has suggested a better method instead of shutting down gconfd. Instead use the following command (thanks nickrud!)

gconftool – -recursive-unset /apps/panel

(Remember: There should be no spaces between the two dashes before shutdown.)

Then enter the next command:

rm -rf ~/.gconf/apps/panel

And enter one more command:

pkill gnome-panel

That’s it!

Both top and bottom panels will appear (if missing) with their default settings. Now you can customize them to your preference and get on with using Ubuntu.

Shell Script for Reading the properties file of Java type

sed ‘/^\#/d’ property_file_name | grep ‘property_name’ | tail -n 1 | cut -d “=” -f2- | sed ‘s/^[[:space:]]*//;s/[[:space:]]*$//’

This command gives the property value from the properties file .

# gres.sh
pattern=$1
replacement=$2
propvalue=`sed ‘/^\#/d’ $3 | grep $1 | tail -n 1 | sed ‘s/^.*=//;s/^[[:space:]]*//;s/[[:space:]]*$//’`
A=”`echo | tr ’12’ ’01’ `”
sed -i -e “s$A$pattern=$propvalue$A$pattern=$replacement$A” $3
# end script

This replaces a property value within a given property file:

./gres.sh

KeywordTokenizerFactory vs StandardTokenizerFactory in solr

KeywordTokenizer does no actual tokenizing, so the entire
input string is preserved as a single token

StandardTokenizerFactory :-
It tokenizes on whitespace, as well as strips characters

Documentation :-
Splits words at punctuation characters, removing punctuations. However, a dot that’s not followed by whitespace is considered part of a token.
Splits words at hyphens, unless there’s a number in the token. In that case, the whole token is interpreted as a product number and is not split.
Recognizes email addresses and Internet hostnames as one token.

Would use this for fields where you want to search on the field data.

e.g. –

http://example.com/I-am+example?Text=-Hello

would generate 7 tokens (separated by comma) –

http,example.com,I,am,example,Text,Hello

KeywordTokenizerFactory :-

Keyword Tokenizer does not split the input at all.
No processing in performed on the string, and the whole string is treated as a single entity.
This doesn’t actually do any tokenization. It returns the original text as one term.

Mainly used for sorting or faceting requirements, where you want to match the exact facet when filtering on multiple words and sorting as sorting does not work on tokenized fields.

e.g.

http://example.com/I-am+example?Text=-Hello

would generate a single token –

http://example.com/I-am+example?Text=-Hello

Customized Stemming Dictionary in solr Porter stemmer

The simple way to use a lot of custom stemming words in solr we can implement the StemmerOverrideFilterFactory and the schema of the field using that will look like the following
< filter class="solr.StemmerOverrideFilterFactory" dictionary="stemdict.txt" />
< filter class="solr.PorterStemFilterFactory" />

The dictionary stemdict.txt must look like
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#———————————————————————–
# test that we can override the stemming algorithm with our own mappings
# these must be tab-separated
monkeys monkey
otters otter
# some crazy ones that a stemmer would never do
dogs cat

Note:while giving the stem substitute words it must be separated by a tab space

USAGE OF PING AND IFCONFIG COMMANDS IN LINUX

Hi ….

Today I am going to say some of the usages of the ping and the ifconfig command in linux systems…..

1)ifconfig

The ifconfig command is used to find the ip address of the system which we are working and has many

options in it which can be used to change the ip address or to connect to a network etc………

2)ping

The ping command is used to check whether the ip address specified as a argument of the ping command

is connected to the network in which our system works ….

If it is connected to the network then it receives packets from the system………………

That’s it for today

with regards………….

JKBS……………..

MOGRIFY COMMAND FOR IMAGE RESIZING IN LINUX

If you need  to just resize  images in a folder

1)Open terminal

2)By using cd command to respective folder

3)And then type following:

mogrify -resize 800×600 -verbose *.JPG

This will resize all the JPG files in the folder in a single go.

jkbs………………….

INSTALLING GRUB

Hai . I wish all of them had a nice sunday….
Today I like to post something about installation procedure of GRUB….
This situation of installing GRUB occurs when we have already installed linux operating system and
after that we have installed any windows OSes…….
So we have to install the GRUB manually to get on to the linux OS during the boot time…
For this we have to follow the following steps………..
1)First insert the live CD of ubuntu(any of its version)
2)Then open the terminal and type the following commands
i)sudo grub
after typing this command you get a sudo prompt in the terminal
ii)find /boot/grub/stage1
This shows the partition number where you have installed the linux operating system.
iii)root(hd0,4)
Here you have to specify the partition number as the second argument.
iv)setup(hd0)

This installs the GRUB in your system….
3)Then you can reboot the system and can select the OS from the GRUB that is installed………..

I think this will be useful for the linux geeks probably…………..

JKBS………………