Thursday, March 26, 2015

GREP COMMAND IN UNIX AND LINUX EXAMPLES

Grep is the frequently used command in Unix (or Linux). Most of us use grep just for finding the words in a file. The power of grep comes with using its options and regular expressions. You can analyze large sets of log files with the help of grep command.

Grep stands for Global search for Regular Expressions and Print.

The basic syntax of grep command is

grep [options] pattern [list of files]

Let see some practical examples on grep command.

1. Running the last executed grep command

This saves a lot of time if you are executing the same command again and again.

!grep
This displays the last executed grep command and also prints the result set of the command on the terminal.
2. Search for a string in a file
This is the basic usage of grep command. It searches for the given string in the specified file.
grep "Error" logfile.txt
This searches for the string "Error" in the log file and prints all the lines that has the word "Error".
3. Searching for a string in multiple files.
grep "string" file1 file2
grep "string" file_pattern
This is also the basic usage of the grep command. You can manually specify the list of files you want to search or you can specify a file pattern (use regular expressions) to search for.
4. Case insensitive search
The -i option enables to search for a string case insensitively in the give file. It matches the words like "UNIX", "Unix", "unix".
grep -i "UNix" file.txt

5. Specifying the search string as a regular expression pattern.
grep "^[0-9].*" file.txt
This will search for the lines which starts with a number. Regular expressions is huge topic and I am not covering it here. This example is just for providing the usage of regular expressions.
6. Checking for the whole words in a file.
By default, grep matches the given string/pattern even if it found as a substring in a file. The -w option to grep makes it match only the whole words.
grep -w "world" file.txt

7. Displaying the lines before the match.
Some times, if you are searching for an error in a log file; it is always good to know the lines around the error lines to know the cause of the error.
grep -B 2 "Error" file.txt
This will prints the matched lines along with the two lines before the matched lines.
8. Displaying the lines after the match.
grep -A 3 "Error" file.txt
This will display the matched lines along with the three lines after the matched lines.
9. Displaying the lines around the match
grep -C 5 "Error" file.txt
This will display the matched lines and also five lines before and after the matched lines.
10. Searching for a sting in all files recursively
You can search for a string in all the files under the current directory and sub-directories with the help -r option.
grep -r "string" *

11. Inverting the pattern match
You can display the lines that are not matched with the specified search sting pattern using the -v option.
grep -v "string" file.txt

12. Displaying the non-empty lines
You can remove the blank lines using the grep command.
grep -v "^$" file.txt

13. Displaying the count of number of matches.
We can find the number of lines that matches the given string/pattern
grep -c "sting" file.txt

14. Display the file names that matches the pattern.
We can just display the files that contains the given string/pattern.
grep -l "string" *

15. Display the file names that do not contain the pattern.
We can display the files which do not contain the matched string/pattern.
grep -L "string" *

16. Displaying only the matched pattern.
By default, grep displays the entire line which has the matched string. We can make the grep to display only the matched string by using the -o option.
grep -o "string" file.txt

17. Displaying the line numbers.
We can make the grep command to display the position of the line which contains the matched string in a file using the -n option
grep -n "string" file.txt

18. Displaying the position of the matched string in the line
The -b option allows the grep command to display the character position of the matched string in a file.
grep -o -b "string" file.txt

19. Matching the lines that start with a string
The ^ regular expression pattern specifies the start of a line. This can be used in grep to match the lines which start with the given string or pattern.
grep "^start" file.txt

20. Matching the lines that end with a string
The $ regular expression pattern specifies the end of a line. This can be used in grep to match the lines which end with the given string or pattern.
grep "end$" file.txt

SED COMMAND IN UNIX AND LINUX EXAMPLES

 

Sed is a Stream Editor used for modifying the files in unix (or linux). Whenever you want to make changes to the file automatically, sed comes in handy to do this. Most people never learn its power; they just simply use sed to replace text. You can do many things apart from replacing text with sed. Here I will describe the features of sed with examples.
Consider the below text file as an input.

>cat file.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
unixlinux which one you choose.

SED COMMAND EXAMPLES

1. Replacing or substituting string
Sed command is mostly used to replace the text in a file. The below simple sed command replaces the word "unix" with "linux" in the file.
>sed 's/unix/linux/' file.txt
linux is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.

Here the "s" specifies the substitution operation. The "/" are delimiters. The "unix" is the search pattern and the "linux" is the replacement string.
By default, the sed command replaces the first occurrence of the pattern in each line and it won't replace the second, third...occurrence in the line.
2. Replacing the nth occurrence of a pattern in a line.
Use the /1, /2 etc flags to replace the first, second occurrence of a pattern in a line. The below command replaces the second occurrence of the word "unix" with "linux" in a line.
>sed 's/unix/linux/2' file.txt
unix is great os. linux is opensource. unix is free os.
learn operating system.
unixlinux which one you choose.

3. Replacing all the occurrence of the pattern in a line.
The substitute flag /g (global replacement) specifies the sed command to replace all the occurrences of the string in the line.
>sed 's/unix/linux/g' file.txt
linux is great os. linux is opensource. linux is free os.
learn operating system.
linuxlinux which one you choose.

4. Replacing from nth occurrence to all occurrences in a line.
Use the combination of /1, /2 etc and /g to replace all the patterns from the nth occurrence of a pattern in a line. The following sed command replaces the third, fourth, fifth... "unix" word with "linux" word in a line.
>sed 's/unix/linux/3g' file.txt
unix is great os. unix is opensource. linux is free os.
learn operating system.
unixlinux which one you choose.

5. Changing the slash (/) delimiter
You can use any delimiter other than the slash. As an example if you want to change the web url to another url as
>sed 's/http:\/\//www/' file.txt

In this case the url consists the delimiter character which we used. In that case you have to escape the slash with backslash character, otherwise the substitution won't work.
Using too many backslashes makes the sed command look awkward. In this case we can change the delimiter to another character as shown in the below example.
>sed 's_http://_www_' file.txt
>sed 's|http://|www|' file.txt

6. Using & as the matched string
There might be cases where you want to search for the pattern and replace that pattern by adding some extra characters to it. In such cases & comes in handy. The & represents the matched string.
>sed 's/unix/{&}/' file.txt
{unix} is great os. unix is opensource. unix is free os.
learn operating system.
{unix}linux which one you choose.

>sed 's/unix/{&&}/' file.txt
{unixunix} is great os. unix is opensource. unix is free os.
learn operating system.
{unixunix}linux which one you choose.

7. Using \1,\2 and so on to \9
The first pair of parenthesis specified in the pattern represents the \1, the second represents the \2 and so on. The \1,\2 can be used in the replacement string to make changes to the source string. As an example, if you want to replace the word "unix" in a line with twice as the word like "unixunix" use the sed command as below.
>sed 's/\(unix\)/\1\1/' file.txt
unixunix is great os. unix is opensource. unix is free os.
learn operating system.
unixunixlinux which one you choose.

The parenthesis needs to be escaped with the backslash character. Another example is if you want to switch the words "unixlinux" as "linuxunix", the sed command is
>sed 's/\(unix\)\(linux\)/\2\1/' file.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
linuxunix which one you choose.

Another example is switching the first three characters in a line
>sed 's/^\(.\)\(.\)\(.\)/\3\2\1/' file.txt
inux is great os. unix is opensource. unix is free os.
aelrn operating system.
inuxlinux which one you choose.

8. Duplicating the replaced line with /p flag
The /p print flag prints the replaced line twice on the terminal. If a line does not have the search pattern and is not replaced, then the /p prints that line only once.
>sed 's/unix/linux/p' file.txt
linux is great os. unix is opensource. unix is free os.
linux is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.
linuxlinux which one you choose.

9. Printing only the replaced lines
Use the -n option along with the /p print flag to display only the replaced lines. Here the -n option suppresses the duplicate rows generated by the /p flag and prints the replaced lines only one time.
>sed -n 's/unix/linux/p' file.txt
linux is great os. unix is opensource. unix is free os.
linuxlinux which one you choose.

If you use -n alone without /p, then the sed does not print anything.
10. Running multiple sed commands.
You can run multiple sed commands by piping the output of one sed command as input to another sed command.
>sed 's/unix/linux/' file.txt| sed 's/os/system/'
linux is great system. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you chosysteme.

Sed provides -e option to run multiple sed commands in a single sed command. The above output can be achieved in a single sed command as shown below.
>sed -e 's/unix/linux/' -e 's/os/system/' file.txt
linux is great system. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you chosysteme.

11. Replacing string on a specific line number.
You can restrict the sed command to replace the string on a specific line number. An example is
>sed '3 s/unix/linux/' file.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.

The above sed command replaces the string only on the third line.
12. Replacing string on a range of lines.
You can specify a range of line numbers to the sed command for replacing a string.
>sed '1,3 s/unix/linux/' file.txt
linux is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.

Here the sed command replaces the lines with range from 1 to 3. Another example is
>sed '2,$ s/unix/linux/' file.txt
linux is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.

Here $ indicates the last line in the file. So the sed command replaces the text from second line to last line in the file.
13. Replace on a lines which matches a pattern.
You can specify a pattern to the sed command to match in a line. If the pattern match occurs, then only the sed command looks for the string to be replaced and if it finds, then the sed command replaces the string.
>sed '/linux/ s/unix/centos/' file.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
centoslinux which one you choose.

Here the sed command first looks for the lines which has the pattern "linux" and then replaces the word "unix" with "centos".
14. Deleting lines.
You can delete the lines a file by specifying the line number or a range or numbers.
>sed '2 d' file.txt
>sed '5,$ d' file.txt

15. Duplicating lines
You can make the sed command to print each line of a file two times.
>sed 'p' file.txt

16. Sed as grep command
You can make sed command to work as similar to grep command.
>grep 'unix' file.txt
>sed -n '/unix/ p' file.txt

Here the sed command looks for the pattern "unix" in each line of a file and prints those lines that has the pattern.
You can also make the sed command to work as grep -v, just by using the reversing the sed with NOT (!).
>grep -v 'unix' file.txt
>sed -n '/unix/ !p' file.txt

The ! here inverts the pattern match.
17. Add a line after a match.
The sed command can add a new line after a pattern match is found. The "a" command to sed tells it to add a new line after a match is found.
>sed '/unix/ a "Add a new line"' file.txt
unix is great os. unix is opensource. unix is free os.
"Add a new line"
learn operating system.
unixlinux which one you choose.
"Add a new line"

18. Add a line before a match
The sed command can add a new line before a pattern match is found. The "i" command to sed tells it to add a new line before a match is found.
>sed '/unix/ i "Add a new line"' file.txt
"Add a new line"
unix is great os. unix is opensource. unix is free os.
learn operating system.
"Add a new line"
unixlinux which one you choose.

19. Change a line
The sed command can be used to replace an entire line with a new line. The "c" command to sed tells it to change the line.
>sed '/unix/ c "Change line"' file.txt
"Change line"
learn operating system.
"Change line"

20. Transform like tr command
The sed command can be used to convert the lower case letters to upper case letters by using the transform "y" option.
>sed 'y/ul/UL/' file.txt
Unix is great os. Unix is opensoUrce. Unix is free os.
Learn operating system.
UnixLinUx which one yoU choose.

Here the sed command transforms the alphabets "ul" into their uppercase format "UL"

SED COMMAND TO PRINT MATCHING LINES - UNIX / LINUX


We use sed command mostly to do operations like search and replace. We can also use the sed command just like a grep to print only the matching lines.
The syntax of sed command to print matching lines is shown below:

sed -n '/pattern/p' filename

The syntax of sed command to print lines using line addresses is:
sed -n 'Np' filename

Examples:
Create the following file in your unix or linux machine:
unix virtual server
linux virtual hosting
fedora os

1. Display lines matching a pattern
The following examples prints the lines that contain the pattern virtual using sed and grep commands.
> grep 'virtual' filename
> sed -n '/virtual/p' filename

2. Print lines with specific line addresses.
The below sed command displays the line with number 2:
sed -n '2p' filename

SED COMMAND TO DELETE LINES - BASED ON POSITION IN FILE

In the following examples, the sed command removes the lines in file that are in a particular position in a file.

1. Delete first line or header line

The d option in sed command is used to delete a line. The syntax for deleting a line is:

> sed 'Nd' file

Here N indicates Nth line in a file. In the following example, the sed command removes the first line in a file.
> sed '1d' file
unix
fedora
debian
ubuntu

2. Delete last line or footer line or trailer line
The following sed command is used to remove the footer line in a file. The $ indicates the last line of a file.
> sed '$d' file
linux
unix
fedora
debian

3. Delete particular line
This is similar to the first example. The below sed command removes the second line in a file.
> sed '2d' file
linux
fedora
debian
ubuntu

4. Delete range of lines
The sed command can be used to delete a range of lines. The syntax is shown below:
> sed 'm,nd' file

Here m and n are min and max line numbers. The sed command removes the lines from m to n in the file. The following sed command deletes the lines ranging from 2 to 4:
> sed '2,4d' file
linux
ubuntu

5. Delete lines other than the first line or header line
Use the negation (!) operator with d option in sed command. The following sed command removes all the lines except the header line.
> sed '1!d' file
linux

6. Delete lines other than last line or footer line
> sed '$!d' file
ubuntu

7. Delete lines other than the specified range
> sed '2,4!d' file
unix
fedora
debian

Here the sed command removes lines other than 2nd, 3rd and 4th.
8. Delete first and last line
You can specify the list of lines you want to remove in sed command with semicolon as a delimiter.
> sed '1d;$d' file
unix
fedora
debian

9. Delete empty lines or blank lines
> sed '/^$/d' file

The ^$ indicates sed command to delete empty lines. However, this sed do not remove the lines that contain spaces. 

SED COMMAND TO DELETE LINES - BASED ON PATTERN MATCH


In the following examples, the sed command deletes the lines in file which match the given pattern.
10. Delete lines that begin with specified character
> sed '/^u/d' file
linux
fedora
debian

^ is to specify the starting of the line. Above sed command removes all the lines that start with character 'u'.
11. Delete lines that end with specified character
> sed '/x$/d' file
fedora
debian
ubuntu

$ is to indicate the end of the line. The above command deletes all the lines that end with character 'x'.
12. Delete lines which are in upper case or capital letters
> sed '/^[A-Z]*$/d' file

13. Delete lines that contain a pattern
> sed '/debian/d' file
linux
unix
fedora
ubuntu

14. Delete lines starting from a pattern till the last line
> sed '/fedora/,$d' file
linux
unix

Here the sed command removes the line that matches the pattern fedora and also deletes all the lines to the end of the file which appear next to this matching line.
15. Delete last line only if it contains the pattern
> sed '${/ubuntu/d;}' file
linux
unix
fedora
debian

Here $ indicates the last line. If you want to delete Nth line only if it contains a pattern, then in place of $ place the line number.
Note: In all the above examples, the sed command prints the contents of the file on the unix or linux terminal by removing the lines. However the sed command does not remove the lines from the source file. To Remove the lines from the source file itself, use the -i option with sed command.
> sed -i '1d' file

If you dont wish to delete the lines from the original source file you can redirect the output of the sed command to another file.
sed '1d' file > newfile

FIND COMMAND IN UNIX AND LINUX EXAMPLES

 

Find is one of the powerful utility of Unix (or Linux) used for searching the files in a directory hierarchy. The syntax of find command is

find [pathnames] [conditions]

Let see some practical exercises on using find command.
1. How to run the last executed find command?
!find

This will execute the last find command. It also displays the last find command executed along with the result on the terminal.
2. How to find for a file using name?
find -name "sum.java"
./bkp/sum.java
./sum.java

This will find all the files with name "sum.java" in the current directory and sub-directories.
3. How to find for files using name and ignoring case?
find -iname "sum.java"
./SUM.java
./bkp/sum.java
./sum.java

This will find all the files with name "sum.java" while ignoring the case in the current directory and sub-directories.
4. How to find for a file in the current directory only?
find -maxdepth 1 -name "sum.java"
./sum.java

This will find for the file "sum.java" in the current directory only
5. How to find for files containing a specific word in its name?
find -name "*java*"
./SUM.java
./bkp/sum.java
./sum.java
./multiply.java

It displayed all the files which have the word "java" in the filename
6. How to find for files in a specific directory?
find /etc -name "*java*"

This will look for the files in the /etc directory with "java" in the filename
7. How to find the files whose name are not "sum.java"?
find -not -name "sum.java"
.
./SUM.java
./bkp
./multiply.java

This is like inverting the match. It prints all the files except the given file "sum.java".
8. How to limit the file searches to specific directories?
find -name "sum.java"
./tmp/sum.java
./bkp/var/tmp/files/sum.java
./bkp/var/tmp/sum.java
./bkp/var/sum.java
./bkp/sum.java
./sum.java

You can see here the find command displayed all the files with name "sum.java" in the current directory and sub-directories.
a. How to print the files in the current directory and one level down to the current directory?
find -maxdepth 2 -name "sum.java"
./tmp/sum.java
./bkp/sum.java
./sum.java

b. How to print the files in the current directory and two levels down to the current directory?
find -maxdepth 3 -name "sum.java"
./tmp/sum.java
./bkp/var/sum.java
./bkp/sum.java
./sum.java

c. How to print the files in the subdirectories between level 1 and 4?
find -mindepth 2 -maxdepth 5 -name "sum.java"
./tmp/sum.java
./bkp/var/tmp/files/sum.java
./bkp/var/tmp/sum.java
./bkp/var/sum.java
./bkp/sum.java

9. How to find the empty files in a directory?
find . -maxdepth 1 -empty
./empty_file

10. How to find the largest file in the current directory and sub directories
find . -type f -exec ls -s {} \; | sort -n -r | head -1

The find command "find . -type f -exec ls -s {} \;" will list all the files along with the size of the file. Then the sort command will sort the files based on the size. The head command will pick only the first line from the output of sort.
11. How to find the smallest file in the current directory and sub directories
find . -type f -exec ls -s {} \; | sort -n -r | tail -1

Another method using find is
find . -type f -exec ls -s {} \; | sort -n  | head -1

12. How to find files based on the file type?
a. Finding socket files
find . -type s

b. Finding directories
find . -type d

c. Finding hidden directories
find -type d -name ".*"

d. Finding regular files
find . -type f

e. Finding hidden files
find . -type f -name ".*"

13. How to find files based on the size?
a. Finding files whose size is exactly 10M
find . -size 10M

b. Finding files larger than 10M size
find . -size +10M

c. Finding files smaller than 10M size
find . -size -10M

14. How to find the files which are modified after the modification of a give file.
find -newer "sum.java"

This will display all the files which are modified after the file "sum.java"
15. Display the files which are accessed after the modification of a give file.
find -anewer "sum.java"

16. Display the files which are changed after the modification of a give file.
find -cnewer "sum.java"

17. How to find the files based on the file permissions?
find . -perm 777

This will display the files which have read, write, and execute permissions. To know the permissions of files and directories use the command "ls -l".
18. Find the files which are modified within 30 minutes.
find . -mmin -30

19. Find the files which are modified within 1 day.
find . -mtime -1

20. How to find the files which are modified 30 minutes back
find . -not -mmin -30

21. How to find the files which are modified 1 day back.
find . -not -mtime -1

22. Print the files which are accessed within 1 hour.
find . -amin -60

23. Print the files which are accessed within 1 day.
find . -atime -1

24. Display the files which are changed within 2 hours.
find . -cmin -120

25. Display the files which are changed within 2 days.
find . -ctime -2

26. How to find the files which are created between two files.
find . -cnewer f1 -and ! -cnewer f2

So far we have just find the files and displayed on the terminal. Now we will see how to perform some operations on the files.
1. How to find the permissions of the files which contain the name "java"?
find -name "*java*"|xargs ls -l

Alternate method is
find -name "*java*" -exec ls -l {} \;

2. Find the files which have the name "java" in it and then display only the files which have "class" word in them?
find -name "*java*" -exec grep -H class {} \;

3. How to remove files which contain the name "java".
find -name "*java*" -exec rm -r {} \;

This will delete all the files which have the word “java" in the file name in the current directory and sub-directories.
Similarly you can apply other Unix commands on the files found using the find command. I will add more examples as and when i found.

scp : Command usage with examples

 

SCP Command Examples:


Let see the examples of scp command in unix or linux system.
1. Copying with in the same system
You can use the scp command just like the cp command to copy files from one directory to another directory.

scp Unix-storage.dat /var/tmp/

This command copies the file unix-storage.dat from current directory to the /var/tmp directory.
2. Copy file from local host to remote server
This is most frequently used operation to transfer files in unix system.

scp filename user@remotehost:/remote/directory/

This command connects to the remote host and copies the specified file to the /remote/directory/.
3. Copy files from remote host to local server.
This operation is used when taking backup of the files in remote server.

scp user@remotehost:/usr/backup/oracle_backup.dat .

This command copies the oracle backup file in the remote host to the current directory.
4. Copying files between two remote servers
The scp command can also be used to copy files between two remote hosts.

scp source_user@source_remote_host:/usr/bin/mysql_backup.sh target_user@target_remote_host:/var/tmp/

The above command copies the mysql bakup shell script from the source remote host the /var/tmp directory of target remote host.
5. Copying a directory.
To copy all the files in a directory, use the -r option with the scp command. This makes the scp command to copy the directory recursively.

scp -r directory user@remotehost:/var/tmp/

The above command copies the directory from local server to the remote host.
6. Improving performance of scp command
By default the scp command uses the Triple-DES cipher/AES-128 to encrypt the data. Using the blowfish or arcfour encryption will improve the performance of the scp command.

scp -c blowfish filename  user@remoteserver:/var/
scp -c arcfour localfile user@remoteserver:/var/

7. Limit bandwidth
You can limit the bandwidth used by the scp command using the -l option.

scp -l bandwidth_limit filename user@hostname:/usr/backup/
Here bandwidth_limit is numeric to be specified in kilobits per second.

8. Specifying the port number
We can make the scp command to copy the files over a specified port number using the -P option.
scp -P 6001 storage_backup.bat username@hostname:/tmp/

How to Create a Wallet in Fusion Middleware Control

 

  • Login to Fusion Middleware Control (em console)
  • Select the Domain
  • From the Navigation pane, locate the instance (ohs) that will use the wallet. Click on the instance.
  • Select the component type drop-down (eg: Oracle HTTP Server)
  • Navigate to Security , then Wallets
  • Select the Create a Wallet
  • Enter the Wallet name, check or uncheck the Autologin box, depending the choice you like
    • image.
  • Click Submit.
  • At this point, you must choose whether to add a certificate request (CR) at this time. If you choose not to do so, you can always add the CR later
  •          image
  • Click Finish.
  • There are two options for the CR:
        Copy and paste the Base64-encoded certificate request from the text box to a file.
        Export it directly to a file with the Export Certificate Request button.
  • A message appears confirming the wallet creation.

Wednesday, March 25, 2015

Integrating Oracle HTTP Server with the Weblogic Administration Server

 

Following steps illustrates how to connect Oracle HTTP Server to the Weblogic Administration Server:

1. Login to em console and in the navigation pane, expand HTTP Server.

2. Select an Oracle HTTP Server instance, such as ohs1. 

3. From the Oracle HTTP Server menu, select Administration, then mod_wl_ohs Configuration.

The mod_wl_ohs Configuration page is displayed, as shown in the following figure:

clip_image001

4. To connect to the Administration Server:

  • For WebLogic Host, enter the host name for the Administration Server.
  • For WebLogic Port, enter the server port for the Administration Server.

Alternatively, you can click the search icon. Then, select the Administration Server and click OK. The fields will be filled in automatically.

5. In the Locations section, click AutoFill.

All valid WebLogic Server endpoint locations are displayed.

6. From the table, select /em.

7. To add the Administration Console:

a. Click Add Row.

b. For location, enter /console.

c. For WebLogic Host, enter the host name for the Administration Server.

d. For Port, enter the Administration Server port number.

8. Click Apply.

9. Shutdown the Oracle HTTP Server instance, then start it again.

Routing Applications Through Oracle HTTP Server to Oracle WebLogic Server

To connect Oracle HTTP Server so that requests are routed through Oracle HTTP Server to Oracle WebLogic Server:

1. From the navigation pane, expand the domain, then HTTP Server.

2. Select an Oracle HTTP Server instance, such as ohs1. The Oracle HTTP Server page is displayed.

3. From the Oracle HTTP Server menu, select Administration, then mod_wl_ohs configuration.

The mod_wl_ohs Configuration page is displayed.

4. To have requests routed to the cluster, for WebLogic Cluster, enter the cluster address. Alternatively, you can click the search Icon and select the cluster. The fields will be filled automatically.

To have requests routed to a single WebLogic server:

  • For WebLogic Host, enter the server name.
  • For WebLogic Port, enter the server port.

Alternatively, you can click the search icon next to WebLogic Host. Then, select the server from the list and click OK. The fields will be filled in automatically.

Note that if you enter values for both WebLogic Cluster and WebLogic Host and Port. WebLogic Cluster will be used.

5. In the Locations section, click AutoFill.

All valid WebLogic Server endpoint locations are displayed.

6. Select the application from the table.

7. Click Apply.

8. Shutdown the Oracle HTTP Server instance, then start it again.

Tuesday, March 24, 2015

Enabling Linux HugePages

 

Enabling Linux HugePages can improve the performance of the Oracle JRockit JVM and have several advantages over the default page size of 4 KB in Linux.

In this recipe, the HugePages will be enabled on all machines in the PRD_DOMAIN domain. A new JVM parameter will be added to the Managed Servers so the JVM makes use of the HugePages.

PRD01 hosts the PRD_SVR1 and PRD_SVR2 Managed Servers. Since each instanceis configured with a heap size of 2 GB, reserving 4 GB for HugePages in server1 should be enough.

Before configuring the Linux HugePages, shut down all WebLogic Servers in the domain.Also stop the Administration Console instance and the Node Manager.

To enable the Linux HugePages, you must log in as root user:

1. Log in as root user to the shell and execute the following commands to check the HugePages configuration:

[root@server1]$ cat /proc/meminfo | grep Huge

HugePages_Total: 0

HugePages_Free: 0

HugePages_Rsvd: 0

Hugepagesize: 2048 kB

2. Create a mount point of type hugetlbfs:

[root@server1]$ mkdir /mnt/hugepages

[root@server1]$ chmod -R 777 /mnt/hugepages

[root@server1]$ mount -t hugetlbfs nodev /mnt/hugepages

3. Add the following mount point to the /etc/fstab:

[root@server1]$ vi /etc/fstab

4. Add the following line:

hugetlbfs /mnt/hugepages hugetlbfs rw,mode=0777 0 0

5. Enter :ws! to save the file and exit.

6. Edit the sysctl.conf file under /etc/:

[root@server1]$ vi /etc/sysctl.conf

7. Reserve 2048 HugePages by adding the following line:

vm.nr_hugepages = 2048

8. Enter :ws! to save the file and exit.

9. Execute the following command to make the changes effective:

[root@server1]# sysctl -p

10. Verify the change:

[root@server1]$ cat /proc/meminfo | grep Huge

HugePages_Total: 2048

HugePages_Free: 2048

HugePages_Rsvd: 0

Hugepagesize: 2048 kB

11. Restart the host if the HugePages could not be allocated.

12. Repeat the preceding steps on all machines in the PROD_DOMAIN.

To enable the Managed Servers to make use of the HugePages, follow the ensuing steps:

1. Access the Administration Console by pointing your web browser to

http://adminhost:7001/console.

2. Click on the Lock & Edit button to start a new edit session.

3. Expand the Environment tree to the left and then click on Servers.

4. Click on the PROD_Server01 link and then click on the Server Start tab.

5. Add the following to the Arguments field and click on the Save button:

-XX:+UseLargePagesForHeap

6. Click on the Activate Changes button.

7. Restart PRD_SVR1.

8. Repeat the preceding steps for PRD_SVR2, PRD_SVR3, and PRD_SVR4.

The first thing to do is to estimate how much memory should be reserved as HugePages.

Sum all heap sizes of the JVMs in the machine. In our case, we have 2 JVMs with 2 GB each so a total of 4 GB should be reserved in HugePages.

To calculate how many pages, get the memory needed and divide by the page size. The formula is sum of JVM heaps / page size.

The memory needed is 4 GB (4096 MB) and the page size is 2 MB (Hugepagesize is 2048 KB). The number of HugePages is 4096/2 = 2048. This 4 GB of reserved HugePages will be pre-allocated and cannot be used by other applications, even when the JVMs are not running, so be sure to do the sizing properly.

It is a common mistake to reserve a large amount of memory in HugePages and the host starts to swap. Remember to leave enough memory for the other applications and the operating system. Avoid the swapping at all costs. If you have the -Xverbose:gc,memory enabled, you can check if the JVM is using the HugePages properly in the STDOUT logfile.

[INFO ][memory ] Using 2MB pages for Java heap.

With the PROD_Server01 started, checking the /proc/meminfo should also reveal that HugePages are in use.

[user@server1]$ cat /proc/meminfo | grep Huge

HugePages_Total: 2048

HugePages_Free: 1024

HugePages_Rsvd: 0

Hugepagesize: 2048 kB

Using HugePages provides some significant advantages:

Because of the larger page size, the page table will be smaller in size. With HugePages, a 10 GB heap size should use only 5120 page entries despite the 2621440 page entries present when using the default 4 KB page size. This minimizes the CPU cost and the page table memory usage.

A performance boost in memory operations because the TLB cache works more efficiently, with more cache hits.

The memory reserved for HugePages will never swap to disk.

It forces a more controlled memory usage of the heap sizes.

Monday, March 23, 2015

How to Enable the RESTful services using WLST

 

By default RESTful is disabled in Weblogic 12c, we can use the weblogic Admin console or WLST to enable the RESTful service.

 

connect(‘WebloogicAdminUser’,’WeblogicAdminPassword’,’WeblogicAdminUrl’)

edit()

startEdit()

cd(‘/RestfulManagementServices/DOMAIN_NAME’)

cmo.setEnabled(true)

save()

activate()

exit()

 

Restart the AdminServer and all servers of the domain

Wednesday, March 18, 2015

How To Enable VncServer in Red Hat Linux

 

As  many of us works on Linux servers some times for installation of the products we like to have GUI enabled.

I would like to share the procedure to enable the GUI mode of installation on Red Hat Linux servers.

  • · Go to your home directory from any were by just typing “cd” and enter
  • · Then do ls –al to list out all the files in the directory
  • · You will see .vnc folder will be there.  Enter into the folder by cd .vnc
  • · You will see a file name called xstartup
  • · Take a back up of the file
  • · Run the following command “vncserver”
  • · Then you will get message similar to below
    • New 'roswell:1 (root)' desktop is roswell:1
    • Starting applications specified in /root/.vnc/xstartup
    • Log file is /root/.vnc/roswell:1.log
  • · Then go to the log file and note down the HTTP port value
  • · Then type the command “vncpasswd”   where it will ask you for the password please give your login password and verify it .
  • · The file will look like below where I uncommented two lines next to “#uncomment”
    •  #!/bin/sh
    • # Uncomment the following two lines for normal desktop:
    • unset SESSION_MANAGER
    • exec /etc/X11/xinit/xinitrc
    • [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    • [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    • xsetroot -solid grey
    • vncconfig -iconic &
    • xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    • startx &
  • · Then go to your Internet explorer and type :http://yourserverip:portnumber/
  • · You will get the page requesting for password and enter password.. Then you will see Redhatlinux window(GUI) for you.

Wednesday, March 11, 2015

How to Patch Weblogic with bsu utility


In Oracle Weblogic, we often gets security patches and other patches related to product. As Oracle Weblogic Admins it required to apply patches regularly, in this post will see how to apply patches from bsu utility in command prompt.
Preparing to Install Oracle Weblogic Server Patch set :
- Patches can be applied on a per-domain basis or installation –wide basis, its better to apply the patch to installation wide.
- user the same user which was used to install the weblogic to login to the servers.
- Stop all running instances of weblogic on the domain hosted on the server.
Installing the Oracle Weblogic Serer Patch Set :
- Down load the required patch set from the oracle support.
-  copy the patchset to  {MW_HOME}/utils/bsu/cache_dir  or any local directory on the server  and make sure its permissions are correct to execute the patch.
- set the WLS_Home    ( eg :. . $WL_HOME/server/bin/setWLSEnv.sh)
- Execute the bsu.sh
 bsu.sh -install -patch_download_dir={MW_HOME}/utils/bsu/cache_dir -patchlist={PATCH_ID} -prod_dir={MW_HOME}/{WL_HOME}
u01/oracle/fmw/utils/bsu> ./bsu.sh -install -patch_download_dir=/u01/oracle/fmw/utils/bsu/cache_dir/ -patchlist=12UV -prod_dir=/u01/oracle/fmw/wlserver_10.3 –verbose 
Post-Install verification :

- Restart all the weblogic servers
- The following command is a simple way to determine the application of WebLogic Server PSU.

  $ . $WL_HOME/server/bin/setWLSEnv.sh 
  $ java weblogic.version 
Uninstalling the Patch :

- Stop all the weblogic servers on the machine
- Execute bsu.sh -remove -patchlist={PATCH_ID} -prod_dir={MW_HOME}/{WL_HOME}
- Restart all Weblogic servers.



Note : These are general instruction for patches, but it’s advised to read  the readme file that comes with patch to make sure if it needs any additional steps for particular patch.