Showing posts with label Bash. Show all posts
Showing posts with label Bash. Show all posts
Linux Commands For Beginners
TL;DR
- Basic Linux commands that we use literally all the time.
alias
alias grep=“grep –color” alias
ps
- print pid: ps -C {program-name} -o pid=
- Show full command: ps -f | less
- ps detects the size of your terminal window and clips to that.
xargs
- use \0 as the delimiter and -0 to use it
- printf ‘%s\0’ Hello Hola Bonjour | xargs -0 -I _ echo _ Landon
Search
Sort files by date then grep
- ls -rt *.log | xargs grep -l
List open files
- ls -l /proc/${pid}/fd
- Use this when lsof is not installed
- lsof -p ${pid}
watch
- watch -n 5 curl -s localhost:8983/show/health
- -d: highlights the changes
curl
pbcopy (take standard input to clipboard) + pbpaste (take data from clipboard to standard output)
diff
sed
- sed -n ‘16224,16482p’ filename > newfile
System
Check the age of the system
- rpm -qi basesystem | grep “Install Date”
Misc
- cd $(dirname ${file_full_path})
- tar xfz somefilename.tar.gz
- dirname, basename, realpath
- Copy one file to multiple file names
- cat 1.ods | tee {jan,feb,mar}-{Rep,graph}.ods >/dev/null
- tail -f **/*.log
Get current working directory of a process
- pwdx
- lsof -p
| grep cwd - readlink -e /proc/
/cwd ##### [View a range of bash history] - fl -l ${start} ${end}
- history | sed ‘start,{end}p’
- lsof -p
Brace expansion
- mkdir -p {f1, f2}
- for i in {1..3}; do echo $i; done
- {START..END..INCREMENT}
Command History
| !!:n | where n is the 0-based position of the argument you want |
| !$ | last argument from previous command |
| !^ | first argument (after the program/built-in/script) from previous command |
| !! | previous command (often pronounced “bang bang”) |
| !n | command number n from history |
| !pattern | most recent command matching pattern |
| !!:s/find/replace | last command, substitute find with replace |
| :p | print the command - !!:p, !!n:p |
Related Posts
Labels:
Bash,
From_Github,
Linux,
Linux commands
Bash Scripting Essentials
Brace Expansion
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
Special Variables
$? Exit value of last executed command.
pid=$!
wait $pid
$! Process number of last background command.
$0 First word; that is, the command name. This will have the full pathname if it was found via a PATH search.
$n Individual arguments on command line (positional parameters).
$# Number of command-line arguments.
“$*” All arguments on command line as one string (“$1 $2…”). The values are separated by the first character in $IFS.
“$@” All arguments on command line, individually quoted (“$1” “$2” …).
Tests
-n string is not null.
-z string is null, that is, has zero length
Testing for File Characteristics
-d File is a directory
-e File exists
-f File is a regular file
-s File has a size greater than zero
-r, -w, -x, -s - socket
[ -d "$dir" ] && echo "$dir exists." || echo "$dir doesn't exists."
Testing with Pattern Matches
== pattern
=~ ere
if [[ "${MYFILENAME}" == *.jpg ]]
-a, &&
-o, ||
if [ ! -d $param ]
if [ $? -ne 0 ]
Parsing
HEAP_DUMP_DIR=$(sed 's/-XX:HeapDumpPath=\([^ ]*\)/\1/' <<< $param)
Function
Use variable $1, $2..$n to access argument passed to the function.
Hello () {
echo "Hello $1 $2"
return 10
}
Return value in bash
echo in the function, capture the result in caller $()
Hello a b
for i in $( command ); do command $i; done
for i in $( command ); do
command $i
done
if [ "$var" == "value" ]; then
else
fi
Google Shell Style Guide
quote your variables; prefer "${var}" over "$var",
Use
while IFS=, read var1 var2 var3; do
Use Local Variables
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
Special Variables
$? Exit value of last executed command.
pid=$!
wait $pid
$! Process number of last background command.
$0 First word; that is, the command name. This will have the full pathname if it was found via a PATH search.
$n Individual arguments on command line (positional parameters).
$# Number of command-line arguments.
“$*” All arguments on command line as one string (“$1 $2…”). The values are separated by the first character in $IFS.
“$@” All arguments on command line, individually quoted (“$1” “$2” …).
Tests
-n string is not null.
-z string is null, that is, has zero length
Testing for File Characteristics
-d File is a directory
-e File exists
-f File is a regular file
-s File has a size greater than zero
-r, -w, -x, -s - socket
[ -d "$dir" ] && echo "$dir exists." || echo "$dir doesn't exists."
Testing with Pattern Matches
if [[ "${MYFILENAME}" == *.jpg ]]
-a, &&
-o, ||
if [ ! -d $param ]
if [ $? -ne 0 ]
Parsing
HEAP_DUMP_DIR=$(sed 's/-XX:HeapDumpPath=\([^ ]*\)/\1/' <<< $param)
Function
Use variable $1, $2..$n to access argument passed to the function.
Hello () {
echo "Hello $1 $2"
return 10
}
Return value in bash
echo in the function, capture the result in caller $()
Hello a b
for i in $( command ); do command $i; done
for i in $( command ); do
command $i
done
if [ "$var" == "value" ]; then
else
fi
Google Shell Style Guide
quote your variables; prefer "${var}" over "$var",
Use
$(command) instead of backticks.[[ ... ]] is preferred over [, test- [[ ... ]] reduces errors as no pathname expansion or word splitting takes place between [[ and ]] and [[ ... ]] allows for regular expression matching where [ ... ] does not
Use readonly or declare -r to ensure they're read only.
Make variable readonly: readonly var=value
Make function readonly: readonly -f function
readonly -p/-f
if [[ -f ~/.bashrc ]]; then
source ~/.bashrc
fi
[ ! -f $FILE ] && { echo "$FILE not found"; exit -1; }
$(( $a+$b )) to execute arithmetic expressions
Put ; do and ; then on the same line as the while, for or if.
Prefer brace-quoting all other variables.
Use "$@" unless you have a specific reason to use $*.
- "$@" will retain arguments as-is, so no args provided will result in no args being passed on;
- "$*" expands to one argument, with all args joined by (usually) spaces, so no args provided will result in one empty string being passed on.
while IFS=, read var1 var2 var3; do
...
done < file.txt
local var="something"
local var
var="$(func)" || return
if [[ "${my_var}" = "some_string" ]]; then
do_something
fi
-z (string length is zero) and -n (string length is not zero)
if ! mv "${file_list}" "${dest_dir}/" ; then
fi
local var
var="$(func)" || return
if [[ "${my_var}" = "some_string" ]]; then
do_something
fi
-z (string length is zero) and -n (string length is not zero)
if ! mv "${file_list}" "${dest_dir}/" ; then
fi
Use set -o errexit (a.k.a. set -e) to make your script exit when a command fails.
Then add || true to commands that you allow to fail.
set -e - enable exit immediately
set +e - disable exit immediately
set -x - print a trace Use set -o nounset (a.k.a. set -u) to exit when your script tries to use undeclared variables.
Use set -o xtrace (a.k.a set -x) to trace what gets executed. Useful for debugging.
set -u Fail for undefined variable (set -o nounset)
Use $(( ... )), not expr for executing arithmetic expressions. which is more forgiving about space
set +e - disable exit immediately
set -x - print a trace Use set -o nounset (a.k.a. set -u) to exit when your script tries to use undeclared variables.
Use set -o xtrace (a.k.a set -x) to trace what gets executed. Useful for debugging.
set -u Fail for undefined variable (set -o nounset)
Use $(( ... )), not expr for executing arithmetic expressions. which is more forgiving about space
Use (( or let, not $(( when you don't need the result
Identify common problems with shellcheck.
Misc
while true; do some_commands_here; done
while true
do
some_commands_here
done
Run command until success
until $the_command; do echo "Try again"; done
while [ -n $(the command) ]; do echo "Try again";done;
Related
Essential Linux Commands for Developers
Misc
while true; do some_commands_here; done
while true
do
some_commands_here
done
Run command until success
until $the_command; do echo "Try again"; done
while [ -n $(the command) ]; do echo "Try again";done;
Related
Essential Linux Commands for Developers
Script to Setup SolrCloud Environment
Senario
Here is the script how to create SolrCloud environment in local dev setup: a collection with numShards=2&replicationFactor=3 on 3 separate (local) nodes.
vms_solr_init creates folders: example/cloud/node{1,2,3}/solr, copy solr.xml and zoo.cfg to these folders, starts the server and creates the collection using admin collection apis.
Other scripts which start/stop are easier to implement.
The implementation
Here is the script how to create SolrCloud environment in local dev setup: a collection with numShards=2&replicationFactor=3 on 3 separate (local) nodes.
vms_solr_init creates folders: example/cloud/node{1,2,3}/solr, copy solr.xml and zoo.cfg to these folders, starts the server and creates the collection using admin collection apis.
Other scripts which start/stop are easier to implement.
The implementation
function solr_init()
{
cd $SOLR_HOME
mkdir -p $SOLR_NODE1_REL_HOME
mkdir -p $SOLR_NODE2_REL_HOME
mkdir -p $SOLR_NODE3_REL_HOME
cp $SOLR_HOME/server/solr/solr.xml $SOLR_HOME/server/solr/zoo.cfg $SOLR_NODE1_REL_HOME
cp $SOLR_HOME/server/solr/solr.xml $SOLR_HOME/server/solr/zoo.cfg $SOLR_NODE2_REL_HOME
cp $SOLR_HOME/server/solr/solr.xml $SOLR_HOME/server/solr/zoo.cfg $SOLR_NODE3_REL_HOME
solr_start
data_solr_create
}
function solr_start() {
if [[ `solr_pid` ]]
then
echo "solr is already running...";
else
echo "Starting solr-cloud... $SOLR_NODE1_PORT, $SOLR_NODE2_PORT, $SOLR_NODE3_PORT";
$SOLR_HOME/bin/solr start -cloud -Dsolr.ltr.enabled=true -s "$SOLR_NODE1_REL_HOME" -p $SOLR_NODE1_PORT -h $SOLR_HOSTNAME;
$SOLR_HOME/bin/solr start -cloud -Dsolr.ltr.enabled=true -s "$SOLR_NODE2_REL_HOME" -p $SOLR_NODE2_PORT -z $SOLR_ZKHOST -h $SOLR_HOSTNAME;
$SOLR_HOME/bin/solr start -cloud -Dsolr.ltr.enabled=true -s "$SOLR_NODE3_REL_HOME" -p $SOLR_NODE3_PORT -z $SOLR_ZKHOST -h $SOLR_HOSTNAME;
fi
}
function solr_stop() {
echo "Stopping solr-cloud...";
$SOLR_HOME/bin/solr stop -all;
}
function solr_restart() {
echo "Restarting solr-cloud...";
solr_stop && solr_start
}
function solr_pid() {
pgrep -f "solr-6.4.0/server";
}
function data_solr_create() {
# Go to the solr config directory
currdir=`pwd`;
cd "$WS/resource/solr";
# Retrieve list of collections
collections_list=`curl -s -v -X GET -H 'Content-type:application/json' "$SOLR_NODE1_PORT/admin/collections?action=LIST&wt=json" | jq '.collections | join(" ")' `;
# Create/update schema
mv solrconfig solrconfig.old.`datetimestamp`;
unzip -d solrconfig solr-core-config.zip;
# create myCollection
cp myCollection_solrconfig.xml solrconfig/conf/solrconfig.xml;
cp myCollection_schema.xml solrconfig/conf/schema.xml;
$SOLR_HOME/server/scripts/cloud-scripts/zkcli.sh -zkhost "$SOLR_ZKHOST" -cmd upconfig -confname myCollection -confdir "solrconfig/conf/";
if grep -q "myCollection" <<< $collections_list; then
curl -s -v -X GET "$SOLR_NODE1_ENDPOINT/admin/collections?action=RELOAD&name=myCollection";
echo "Updated myCollection";
else
curl -s -v -X GET "$SOLR_NODE1_ENDPOINT/admin/collections?action=CREATE&name=myCollection&numShards=2&collection.configName=myCollection&replicationFactor=3&maxShardsPerNode=2";
echo "Created myCollection";
fi
rm -rf solrconfig;
cd $currdir;
}
Linux: Using inode number to delete files with special characters
Today I found there is one special file named -v in the folder.
-rw-r--r-- 1 root root 790 Apr 23 18:36 -v
In this case, we can find the file's inode number and use the inode number to delete it.
First let's find the file's inode number using ls -li.
The -i prints the inode number of each file.
ls -li
5242899 -rw-r--r-- 1 root root 790 Apr 23 18:36 -v
Then use one of below commands to delete it:
find . -inum 5242899 -delete
find . -inum 5242899 -exec rm -i {} \;
Also if we are creating multiple hard links to one file, and we want to remove that file completely- even there are still multiple hard links. We can use the same trickL:
find . -inum [inum] -delete
-rw-r--r-- 1 root root 790 Apr 23 18:36 -v
In this case, we can find the file's inode number and use the inode number to delete it.
First let's find the file's inode number using ls -li.
The -i prints the inode number of each file.
ls -li
5242899 -rw-r--r-- 1 root root 790 Apr 23 18:36 -v
Then use one of below commands to delete it:
find . -inum 5242899 -delete
find . -inum 5242899 -exec rm -i {} \;
Also if we are creating multiple hard links to one file, and we want to remove that file completely- even there are still multiple hard links. We can use the same trickL:
find . -inum [inum] -delete
Commonly Used Windows PowerShell Commands
One reason we like Linux is because it's so easy to complete common (administration) tasks via the shell or scripting.
But sometimes, we have to work on Windows, and not able to install cygwin.
Luckily, Microsoft provides PowerShell, and it's preinstalled with Win7, Windows Server 2008 R2 and later Windows release.
Power Shell is cool and useful, it's different from Linux's Shell, as it's completely object-oriented.
Common Folder/File Operations
Create a folder
mkdir c:\f1\f2\f3
md c:\f1\f2\f3
New-Item c:\f1\f2\f3 -ItemType directory
rm -r c:\f1\f2\f3
Create a file
New-Item c:\f1\f2\f3 -ItemType file -force -value "hello world"
cat c:\f1\f2\f3
Delete Files
Remove-Item -Recurse -Force .\incubator-blur #like linux rm -rf
Remove-Item c:\scripts\* -include .txt -exclude *test
Extract lines from files
Get first 10 lines as head -10 in linux
Get-Content -Path my.csv -TotalCount 10
Get last 10 lines as tail -10 in Linux
Get-Content -Path my.csv | Select-Object -Last 10
Get-Content -Path my.csv | Select-Object -Index(10)
Get the 10th to 100th lines
Get-Content -Path my.csv | Select-Object -Index(10..100)
Get 10th and 100th lines
Get-Content -Path my.csv | Select-Object -Index(10, 100)
Search recursively for a certain string within files
Get-ChildItem -Recurse -Filter *.log | Select-String Exception
Get-ChildItem -Recurse -Filter *.log | Select-String -CaseSensitive -Pattern Exception
Tail -f in PowerShell
In powershell 3.0 and newer version, powershel supports: -Tail:
Get-Content error.log -Tail 10 -Wait
Get-Content error.log -wait
Get-Content error.log -wait | Where-Object { $_ -match "Exception" }
-match is case-insensitive. -cmath is case-sensitive.
List All Java Files in All Subfolders
gci -Recurse -filter *.java | % { $_.FullName }
Select-String
(select-string -path audit.log -pattern "logon failed").count
Select-String C:\Scripts\Test.lxt -pattern "failure" -context 3,1
Measure-Object
Display the number of characters, words, and lines in the Text.txt file.
get-content C:\test.txt | measure-object -character -line -word
get-childitem | measure-object -property length -minimum -maximum -average
import-csv d:\test\serviceyrs.csv | measure-object -property years -minimum -maximum -average
Find the five processes using the most memory
Get-Process | Sort-Object -Property WS -Descending | Select-Object -First 10
Delete all files within a directory
Remove-Item foldername -Recurse
Rename all .TXT files as .LOG files in the current directory:
Get-Childitem -Path *.txt | rename-item -NewName {$_.name -replace ".txt",".log"}
Miscs
Restart-Computer –Force –ComputerName TARGETMACHINE
Run a script on a remote computer
invoke-command -computername machine1, machine2 -filepath c:\Script\script.ps1
Using Get-WmiObject
List all WMI classes:
Get-WmiObject -List
Get-WmiObject -Class Win32_ComputerSystem
Get-WmiObject -Class Win32_BIOS -ComputerName .
gwmi win32_service -filter "name like 'Oracle%'" | select name
gwmi win32_service -filter "startmode='auto'" | select name,startmode
(gwmi win32_service -filter "name='alerter'").StopService()
But sometimes, we have to work on Windows, and not able to install cygwin.
Luckily, Microsoft provides PowerShell, and it's preinstalled with Win7, Windows Server 2008 R2 and later Windows release.
Power Shell is cool and useful, it's different from Linux's Shell, as it's completely object-oriented.
Common Folder/File Operations
Create a folder
mkdir c:\f1\f2\f3
md c:\f1\f2\f3
New-Item c:\f1\f2\f3 -ItemType directory
rm -r c:\f1\f2\f3
Create a file
New-Item c:\f1\f2\f3 -ItemType file -force -value "hello world"
cat c:\f1\f2\f3
Delete Files
Remove-Item -Recurse -Force .\incubator-blur #like linux rm -rf
Remove-Item c:\scripts\* -include .txt -exclude *test
Extract lines from files
Get first 10 lines as head -10 in linux
Get-Content -Path my.csv -TotalCount 10
Get last 10 lines as tail -10 in Linux
Get-Content -Path my.csv | Select-Object -Last 10
Get-Content -Path my.csv | Select-Object -Index(10)
Get the 10th to 100th lines
Get-Content -Path my.csv | Select-Object -Index(10..100)
Get 10th and 100th lines
Get-Content -Path my.csv | Select-Object -Index(10, 100)
Search recursively for a certain string within files
Get-ChildItem -Recurse -Filter *.log | Select-String Exception
Get-ChildItem -Recurse -Filter *.log | Select-String -CaseSensitive -Pattern Exception
Tail -f in PowerShell
In powershell 3.0 and newer version, powershel supports: -Tail:
Get-Content error.log -Tail 10 -Wait
Get-Content error.log -wait
Get-Content error.log -wait | Where-Object { $_ -match "Exception" }
-match is case-insensitive. -cmath is case-sensitive.
List All Java Files in All Subfolders
gci -Recurse -filter *.java | % { $_.FullName }
Select-String
(select-string -path audit.log -pattern "logon failed").count
Select-String C:\Scripts\Test.lxt -pattern "failure" -context 3,1
Measure-Object
Display the number of characters, words, and lines in the Text.txt file.
get-content C:\test.txt | measure-object -character -line -word
get-childitem | measure-object -property length -minimum -maximum -average
import-csv d:\test\serviceyrs.csv | measure-object -property years -minimum -maximum -average
Find the five processes using the most memory
Get-Process | Sort-Object -Property WS -Descending | Select-Object -First 10
Delete all files within a directory
Remove-Item foldername -Recurse
Rename all .TXT files as .LOG files in the current directory:
Get-Childitem -Path *.txt | rename-item -NewName {$_.name -replace ".txt",".log"}
Miscs
Restart-Computer –Force –ComputerName TARGETMACHINE
Run a script on a remote computer
invoke-command -computername machine1, machine2 -filepath c:\Script\script.ps1
Using Get-WmiObject
List all WMI classes:
Get-WmiObject -List
Get-WmiObject -Class Win32_ComputerSystem
Get-WmiObject -Class Win32_BIOS -ComputerName .
gwmi win32_service -filter "name like 'Oracle%'" | select name
gwmi win32_service -filter "startmode='auto'" | select name,startmode
(gwmi win32_service -filter "name='alerter'").StopService()
A Complete DNS Setup Guide on Redhat(CentOS)
Background
When install cloudera cluster recently, I have to setup a private DNS server.
Environment
Private DNS server: 172.19.97.224(bigdatam.localdomain.com)
DNS client: 172.19.101.66(bigdata1.localdomain.com) and 172.19.102.56(bigdata2.localdomain.com.
Install bind and caching-nameserver
yum install bind bind-utils bind-libs bind-chroot caching-nameserver -y
Run service named restart to start named server first.
Configure DNS Server
Enable Caching nameserver and Create Zones
Edit /var/named/chroot/etc/named.conf:
1. Use forwarders block to forward DNS requests it can't resolve to upstream DNS server.
2. Add forward and reverse zones block for localdomain.com and 19.172.in-addr.arpa.
3. Add forward and reverse zones block for locahost and 0.0.127.in-addr.arpa.
vi /var/named/chroot/etc/named.conf
Go to /var/named/chroot/var/named directory, create files: localdomain.com.zone and 19.172.in-addr.arpa.
cd /var/named/chroot/var/named
touch localdomain.com.zone && chown named:named localdomain.com.zone && chmod 644 localdomain.com.zone
touch 19.172.in-addr.arpa && chown named:named 19.172.in-addr.arpa && chmod 644 19.172.in-addr.arpa
vi localdomain.com.zone
vi 172.19.zone
Restart named server
service named restart
chkconfig named on
Reload configuration and zones
rndc reload
Toggle query logging
rndc querylog
Sometimes, we need disable SELinux and firewall
Disable SELinux
setenforce 0
vi /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
Disable firewall
/etc/init.d/iptables stop
chkconfig iptables off
Configure DNS Client
Do following steps in all 3 servers.
Prevent /etc/resolv.conf get overwritten
/etc/sysconfig/network-scripts/ifcfg-eth0 (replace eth0 with your network interface if different) and change PEERDNS=yes to PEERDNS=no
Setup DNS Name resolution
vi /etc/resolv.conf
search localdomain.com
nameserver 172.19.97.224 # the private dns server ip address.
Restart network
/etc/init.d/network restart
Test DNS Setup
Run nslookup to start a session, and run the folloiwng command in all hosts.
# nslookup
host -v -t A `hostname
vi /etc/hosts
127.0.0.1 localhost.localdomain localhost
Synchronize System Clock Between Servers
ntpdate pool.ntp.org
Resources
How to set up a home DNS server
How to set up a home DNS server, part II
When install cloudera cluster recently, I have to setup a private DNS server.
Environment
Private DNS server: 172.19.97.224(bigdatam.localdomain.com)
DNS client: 172.19.101.66(bigdata1.localdomain.com) and 172.19.102.56(bigdata2.localdomain.com.
Install bind and caching-nameserver
yum install bind bind-utils bind-libs bind-chroot caching-nameserver -y
Run service named restart to start named server first.
Configure DNS Server
Enable Caching nameserver and Create Zones
Edit /var/named/chroot/etc/named.conf:
1. Use forwarders block to forward DNS requests it can't resolve to upstream DNS server.
2. Add forward and reverse zones block for localdomain.com and 19.172.in-addr.arpa.
3. Add forward and reverse zones block for locahost and 0.0.127.in-addr.arpa.
vi /var/named/chroot/etc/named.conf
acl localdomain-com { 172.19/16; };
options {
directory "/var/named";
allow-query { localdomain-com; };
# The block will cause the caching name server to forward DNS requests it can't resolve to upstream DNS server.
forwarders { upstream-dns-server1; upstream-dns-server2};
#forward only;
};
zone "localdomain.com" IN {
type master;
file "localdomain.com.zone";
};
zone "19.172.in-addr.arpa" IN {
type master;
file "172.19.zone";
};
zone "locahost" IN {
type master;
file "localhost.zone";
allow-update{none;};
};
zone "0.0.127.in-addr.arpa" {
type master;
file "named.local";
};
zone "." {
type hint;
file "named.ca";
};
Add Zone filesGo to /var/named/chroot/var/named directory, create files: localdomain.com.zone and 19.172.in-addr.arpa.
cd /var/named/chroot/var/named
touch localdomain.com.zone && chown named:named localdomain.com.zone && chmod 644 localdomain.com.zone
touch 19.172.in-addr.arpa && chown named:named 19.172.in-addr.arpa && chmod 644 19.172.in-addr.arpa
vi localdomain.com.zone
$TTL 1D
$ORIGIN localdomain.com.
@ IN SOA bigdatam.localdomain.com. foo.bar.tld. (
200612060 ; serial
2H ; refresh slaves
5M ; retry
1W ; expire
1M ; Negative TTL
)
@ IN NS bigdatam
bigdatam IN A 172.19.97.224
bigdata1 IN A 172.19.101.66
bigdata2 IN A 172.19.102.56
vi 172.19.zone
$TTL 1D
$ORIGIN 19.172.IN-ADDR.ARPA.
@ IN SOA bigdatam.localdomain.com. foo.bar.tld. (
200612060 ; serial
2H ; refresh slaves
5M ; retry
1W ; expire
1M ; Negative TTL
)
IN NS bigdatam.localdomain.com.
224.97 IN PTR bigdatam.localdomain.com.
66.101 IN PTR bigdata1.localdomain.com.
56.102 IN PTR bigdata2.localdomain.com.
localhost.zone, named.local and named.ca are already in /var/named/chroot/var/named, they are created automatically, we just need refer them in /var/named/chroot/etc/named.conf.Restart named server
service named restart
chkconfig named on
Reload configuration and zones
rndc reload
Toggle query logging
rndc querylog
Sometimes, we need disable SELinux and firewall
Disable SELinux
setenforce 0
vi /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
Disable firewall
/etc/init.d/iptables stop
chkconfig iptables off
Configure DNS Client
Do following steps in all 3 servers.
Prevent /etc/resolv.conf get overwritten
/etc/sysconfig/network-scripts/ifcfg-eth0 (replace eth0 with your network interface if different) and change PEERDNS=yes to PEERDNS=no
Setup DNS Name resolution
vi /etc/resolv.conf
search localdomain.com
nameserver 172.19.97.224 # the private dns server ip address.
Restart network
/etc/init.d/network restart
Test DNS Setup
Run nslookup to start a session, and run the folloiwng command in all hosts.
# nslookup
> 127.0.0.1 Server: 172.19.97.224 Address: 172.19.97.224#53 1.0.0.127.in-addr.arpa name = localhost. > localhost Server: 172.19.97.224 Address: 172.19.97.224#53 Non-authoritative answer: Name: localhost Address: 127.0.0.1 > bigdatam Server: 172.19.97.224 Address: 172.19.97.224#53 Name: bigdatam.localdomain.com Address: 172.19.97.224 > bigdata1 Server: 172.19.97.224 Address: 172.19.97.224#53 Name: bigdata1.localdomain.com Address: 172.19.101.66dig bigdaam
host -v -t A `hostname
vi /etc/hosts
127.0.0.1 localhost.localdomain localhost
Synchronize System Clock Between Servers
ntpdate pool.ntp.org
Resources
How to set up a home DNS server
How to set up a home DNS server, part II
Advanced Usage of Linux Grep Command
Grep recursively: -R, -r, --recursive
grep -r "127" /etc
Use grep to search words only: -w, --word-regexp
Select only those lines containing matches that form whole words
grep -w "boo" file
-s, --no-messages
Suppress error messages about nonexistent or unreadable files.
Ignore binary files: -I
When we search, we may only want to search text files and ignore binary files for better performance. we can use: -I.
-I Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.
Combine grep and find
grep "some_string" `find some_folder -name "*.some_extension"`
find . -name "*.php" -exec grep -H "some_string" {} \;
--include=GLOB
Search only files whose base name matches GLOB
--exclude=GLOB
Skip files whose base name matches GLOB (using wildcard matching). A file-name glob can use *, ?, and [...] as wildcards, and \ to quote a wildcard or backslash character literally.
--exclude-dir=DIR
grep -rsI --include=*.html --include=*.php --include=*.htm "pattern" /some/path/
grep -rsI --include=*.{html,php,htm} "pattern" /some/path/
grep -rsI --include=*.{py,pyc} hue /etc
Find jars that contain matched classes
Grep can be used to find the jar that contains the matched class fileL
grep -r com.cloudera.cmf.inspector.Inspector /usr/share/cmf/lib
Miscs
-c, --count
Suppress normal output; instead print a count of matching lines for each input file
-n, --line-number
-h, --no-filename
-H, --with-filename
-v, --invert-match
--color[=WHEN], --colour[=WHEN]
grep --color root /etc/passwd
Resources
Grep Manual
grep -r "127" /etc
Use grep to search words only: -w, --word-regexp
Select only those lines containing matches that form whole words
grep -w "boo" file
-s, --no-messages
Suppress error messages about nonexistent or unreadable files.
Ignore binary files: -I
When we search, we may only want to search text files and ignore binary files for better performance. we can use: -I.
-I Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.
Combine grep and find
grep "some_string" `find some_folder -name "*.some_extension"`
find . -name "*.php" -exec grep -H "some_string" {} \;
--include=GLOB
Search only files whose base name matches GLOB
--exclude=GLOB
Skip files whose base name matches GLOB (using wildcard matching). A file-name glob can use *, ?, and [...] as wildcards, and \ to quote a wildcard or backslash character literally.
--exclude-dir=DIR
grep -rsI --include=*.html --include=*.php --include=*.htm "pattern" /some/path/
grep -rsI --include=*.{html,php,htm} "pattern" /some/path/
grep -rsI --include=*.{py,pyc} hue /etc
Find jars that contain matched classes
Grep can be used to find the jar that contains the matched class fileL
grep -r com.cloudera.cmf.inspector.Inspector /usr/share/cmf/lib
Miscs
-c, --count
Suppress normal output; instead print a count of matching lines for each input file
-n, --line-number
-h, --no-filename
-H, --with-filename
-v, --invert-match
--color[=WHEN], --colour[=WHEN]
grep --color root /etc/passwd
Resources
Grep Manual
Linux Mount and Unmout Remote File System
Create the Mount Point
sudo mkdir /mnt/ip-shared
Mount a windows shared folder
mount //server-name/share-name /mnt/ip-shared -o username=shareuser,password=sharepassword,domain=sharedomain
Here, -o is used top specify mount options, in this case, we specify the login credential: username, password, and domain . Its format can be -o username=sharedomain/shareuser,password=sharepassword
Here we don't use -t to specify vfstype, thus mount will try to guess the desired type. Check the list here at mount Manual.
Common Mount Options
loop Mounts an image as a loop device.
ro Mounts the file system for reading only.
rw Mounts the file system for both reading and writing.
Unmount it
If we don't need to access the remote file system, we can use umount to unmount it: Notice, it's umount, not unmount.
umount /mnt/ip-shared
Resource
Linux Mount Manual
Linux mount CIFS Windows Share
sudo mkdir /mnt/ip-shared
Mount a windows shared folder
mount //server-name/share-name /mnt/ip-shared -o username=shareuser,password=sharepassword,domain=sharedomain
Here, -o is used top specify mount options, in this case, we specify the login credential: username, password, and domain . Its format can be -o username=sharedomain/shareuser,password=sharepassword
Here we don't use -t to specify vfstype, thus mount will try to guess the desired type. Check the list here at mount Manual.
Common Mount Options
loop Mounts an image as a loop device.
ro Mounts the file system for reading only.
rw Mounts the file system for both reading and writing.
Unmount it
If we don't need to access the remote file system, we can use umount to unmount it: Notice, it's umount, not unmount.
umount /mnt/ip-shared
Resource
Linux Mount Manual
Linux mount CIFS Windows Share
Subscribe to:
Posts (Atom)
Labels
ANT
(6)
Algorithm
(69)
Algorithm Series
(35)
Android
(7)
Big Data
(7)
Blogger
(14)
Bugs
(6)
Cache
(5)
Chrome
(19)
Code Example
(29)
Code Quality
(7)
Coding Skills
(5)
Database
(7)
Debug
(16)
Design
(5)
Dev Tips
(63)
Eclipse
(32)
Git
(5)
Google
(33)
Guava
(7)
How to
(9)
Http Client
(8)
IDE
(7)
Interview
(88)
J2EE
(13)
J2SE
(49)
JSON
(7)
Java
(186)
JavaScript
(27)
Learning code
(9)
Lesson Learned
(6)
Linux
(26)
Lucene-Solr
(112)
Mac
(10)
Maven
(8)
Network
(9)
Nutch2
(18)
Performance
(9)
PowerShell
(11)
Problem Solving
(11)
Programmer Skills
(6)
Scala
(6)
Security
(9)
Soft Skills
(38)
Spring
(22)
System Design
(11)
Testing
(7)
Text Mining
(14)
Tips
(17)
Tools
(24)
Troubleshooting
(29)
UIMA
(9)
Web Development
(19)
Windows
(21)
adsense
(5)
bat
(8)
regex
(5)
xml
(5)