VI editor September 28th, 2010
Open
vi filename
Close/Quit/Quit without save
:q = close the file, if you didnt modified anything
:q! = close the file even u modified and dont want to save it
:
Save/ Save quit
:wq = save and exit
= save and stay
Add
i = from cursor before start append
I = begin of line allow appending
a = after cursor append
A =end of line append
o = new line
O =before cursor new line
Edit
r = from cursor character edit
R = replace from cursor anything on type, until esc pressed
cw = word replace
Del
dd = entire line delete
x = single character
dw = single word
D = remaining of the line starting with current cursor position
Cut/Past
yy = copy the current line into the buffer
Nyy or yNy = copy the next N lines, including the current line, into the buffer
p = paste the line in the buffer into the text after the current line
Searching
/string = search forward for occurrence of string in text
?string = search backward for occurrence of string in text
n = move to next occurrence of search string
N = move to occurrence of search string in opposite direction
Line numbers:
: .= returns line number of current line at bottom of screen
:= returns the total number of lines at bottom of screen
^g provides the current line number, along with the total number of lines, in the file at the bottom of the screen
Posted in CentOS, debian, fedora, feebsd, linux, Networking, ubuntu | No Comments »
Linux Tuning Parameters September 28th, 2010
KernelTo successfully run enterprise applications, such as a database server, on your Linux distribution, you may be required to update some of the default kernel parameter settings. For example, the 2.4.x series kernel message queue parameter msgmni has a default value (for example, shared memory, or shmmax is only 33,554,432 bytes on Red Hat Linux by default) that allows only a limited number of simultaneous connections to a database. Here are some recommended values (by the IBM DB2 Support Web site) for database servers to run optimally:
| - kernel.shmmax=268435456 for 32-bit- kernel.shmmax=1073741824 for 64-bit- kernel.msgmni=1024- fs.file-max=8192- kernel.sem=”250 32000 32 1024″ |
Shared Memory
| To view current settings, run command:# more /proc/sys/kernel/shmmaxTo set it to a new value for this running session, which takes effect immediately, run command:# echo 268435456 > /proc/sys/kernel/shmmaxTo set it to a new value permanently (so it survives reboots), modify the sysctl.conf file:…kernel.shmmax = 268435456… |
Semaphores
| To view current settings, run command:# more /proc/sys/kernel/sem 250 32000 32 1024 To set it to a new value for this running session, which takes effect immediately, run command:# echo 500 512000 64 2048 > /proc/sys/kernel/semParameters meaning:SEMMSL – semaphores per IDSEMMNS – (SEMMNI*SEMMSL) max semaphores in systemSEMOPM – max operations per semop callSEMMNI – max semaphore identifiers |
ulimits
| To view current settings, run command:# ulimit -aTo set it to a new value for this running session, which takes effect immediately, run command:# ulimit -n 8800# ulimit -n -1 // for unlimited; recommended if server isn’t shared Alternatively, if you want the changes to survive reboot, do the following: - Exit all shell sessions for the user you want to change limits on.- As root, edit the file /etc/security/limits.conf and add these two lines toward the end: user1 soft nofile 16000 user1 hard nofile 20000 ** the two lines above changes the max number of file handles – nofile – to new settings.- Save the file.- Login as the user1 again. The new changes will be in effect. |
Message queues Read the rest of this entry »
Posted in CentOS, debian, fedora, feebsd, linux, Networking, ubuntu | No Comments »
How to backup MySQL databases September 23rd, 2010
rm -f /backup/mysql*
### System Setup ###
BACKUP=/backup
NOW=$(date +”%d-%m-%Y”)
### MySQL Setup ###
MUSER=”mysqluser”
MPASS=”password”
MHOST=”localhost”
MYSQL=”$(which mysql)”
MYSQLDUMP=”$(which mysqldump)”
GZIP=”$(which gzip)”
### Start MySQL Backup ###
# Get all databases name
DBS=”$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse ‘show databases’)”
for db in $DBS
do
FILE=$BACKUP/mysql-$db.$NOW-$(date +”%T”).gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done
source here
Posted in CentOS, debian, fedora, feebsd, linux, Networking, ubuntu | No Comments »
setting up a iptables firewall with logwatch on gmail account September 22nd, 2010
Overview
Any basic home router is a combination firewall/switch/wifi device. If you don’t need wifi, you can get much finer-grained control of your home network by buying a low-power computer with 2 ethernet ports to use as your firewall, and then a cheap 4 or 8 port switch to do your switching. This gives you far better control and flexibility.
Here’s how you configure Fedora 10 on a low-power firewall machine.
Install a minimum F10 install on your firewall computer.
Not covered here. As a general rule, use the DVD, use the i386 version (on the assumption that you are using smaller; low-power hardware).
Kernel Settings
Do NOT skip this step or your internal computers will not be able to reach the internet.
Fedora 10 by default does not allow packet forwarding, which is a fantastically sane default setting. However, this needs to be changed for your 2-ethernet-port computer to act as a firewall. Therefore, ensure /etc/sysctl.conf looks like this:
# Kernel sysctl configuration file for Red Hat Linux # # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and # sysctl.conf(5) for more details. # Controls IP packet forwarding net.ipv4.ip_forward = 1 net.ipv4.icmp_echo_ignore_broadcasts = 1 # Controls source route verification net.ipv4.conf.default.rp_filter = 1 # Do not accept source routing net.ipv4.conf.default.accept_source_route = 0 # Controls the System Request debugging functionality of the kernel kernel.sysrq = 0 # Controls whether core dumps will append the PID to the core filename. # Useful for debugging multi-threaded applications. kernel.core_uses_pid = 1 Read the rest of this entry »
Posted in CentOS, debian, fedora, feebsd, linux, Networking, ubuntu | No Comments »
Firewall – How Do I Block an IP Address on My Linux server? September 12th, 2010
What is iptable? Iptables is a generic table structure that defines rules and commands as part of the netfilter framework that facilitates Network Address Translation (NAT), packet filtering, and packet mangling in the Linux 2.4 and later operating systems. NAT is the process of converting an Internet Protocol address (IP address) into another IP address. Packet filtering is the process of passing or blocking packets at a network interface based on source and destination addresses, ports, or protocols. Packet mangling is the ability to alter or modify packets before and/or after routing.
Iptables and netfilter are the successor to ipchains and ipfwadm in earlier versions of Linux. Netfilter and iptables are often combined into the single expression netfilter /iptables, which refers to the Linux 2.4 and later subsystems for NAT, firewall, and advanced packet processing.
How do I block an IP address or subnet under Linux operating system?
In order to block an IP on your Linux server you need to use iptables tools (administration tool for IPv4 packet filtering and NAT) and netfilter firewall. First you need to log into shell as root user. To block IP address you need to type iptables command as follows:
Syntax to block an IP address under Linux
Replace IP-ADDRESS with actual IP address. For example if you wish to block ip address 65.55.44.100 for whatever reason then type command as follows:
If you have IP tables firewall script, add above rule to your script.
If you just want to block access to one port from an ip 65.55.44.100 to port 25 then type command:
# iptables -A INPUT -s 65.55.44.100 -p tcp –destination-port 25 -j DROP
The above rule will drop all packets coming from IP 65.55.44.100 to port mail server port 25.
You can also create Security Shell Script to block the ips: Create /root/iptables/blocked.ips file as follows with list of ips and subnets to block entering your dedicated server.
Posted in CentOS, debian, fedora, feebsd, linux, Networking, ubuntu | No Comments »
