OpenVz: Migrating Vps from one Hard disk to another

*First copy the contents from old directory to new disk directory

cp -a /var/lib/vz/private/109/* /disk3/private/109/

*Once the copying is over stop the vps

vzctl stop 109

*Drop the quota file

vzquota drop 109

*Then edit the config file and enter the new VE_PRIVATE value,

nano /etc/vz/conf/109.conf

VE_PRIVATE=”/disk3/private/119″

mv /var/lib/vz/private/109 /var/lib/vz/private/109.bak //taking backup to restore if needed, once successful you can remove this file

*Start the vps

vzctl start 109

MRTG installation on linux server

1 Checking for snmp server

rpm -qa | grep snmp

yum install net-snmp-utils net-snmp

2 Checking Snmpd service running or not in the server

ps -aux | grep snmp

or

lsof -i :199

or

netstat -natv | grep ‘:199’

service snmpd start

chkconfig –add snmpd

chkconfig snmpd on

3 Checking snmp server configured properly

vi /etc/snmp/snmpd.conf

find

com2sec notConfigUser default public

replace

com2sec local localhost public
com2sec mynetwork 192.168.0.0/24 public (here replace with your network)

find
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser

Replace with:

group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
Again scroll down a bit and locate the following line:

Find line:

view systemview included system
Replace with:

view all included .1 80
Again scroll down a bit and change the following line:

Find line:

access notConfigGroup “” any noauth exact systemview none none
Replace with:

access MyROGroup “” any noauth exact all none none
access MyRWGroup “” any noauth exact all all none
Scroll down a bit and change the following lines:

Find lines:

syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root (configure /etc/snmp/snmp.local.conf)

Replcaec with

syslocation Linux (OS Name), Linux Router.
syscontact YourNameHere

chkconfig snmpd on
service snmpd start

snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

Sample outputs:
ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.127.0.0.1 = 1
ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.192.168.0.3 = 2

4 Install mrtg

yum install mrtg

5 Configure mrtg

mkdir -p /usr/local/apache/htdocs/mrtg
cfgmaker –global ‘WorkDir: /usr/local/apache/htdocs/mrtg’ –output /etc/mrtg/mrtg.cfg public@localhost

indexmaker –output=/usr/local/apache/htdocs/mrtg/index.html /etc/mrtg/mrtg.cfg

6 checking cron

cat /etc/cron.d/mrtg

7 Access mrtg using http://your-ip.add.ress/mrtg/

mod_geoip Install On a WHM/cPanel Server

Step 1:

mkdir /usr/share/GeoIP
cd /usr/share/GeoIP

Step 2:

Download and install the GeoIP database provided by MaxMind, enter the following commands:
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gzip -d GeoIP.dat.gz

Step 3:
Install the custom mod_geoip cPanel module.

wget wget http://docs.cpanel.net/twiki/pub/EasyApache3/CustomMods/custom_opt_mod-mod_geoip.tar.gz
tar -C /var/cpanel/easy/apache/custom_opt_mods -xzf custom_opt_mod-mod_geoip.tar.gz

Step 4:

Now that we have installed the GeoIP database and all the modules required to run mod_geoip with Apache and cPanel, we will need to rebuild Apache in WHM.

WHM -> Software -> EasyApache (Apache Update) -> Start customizing based on profile -> Check ‘Mod GeoIP’ option (on Short / Exhaustive Options List page) -> Save and Build

Step 5:

After Apache has been rebuilt with mod_geoip, we will need to load and enable the module every time Apache runs. First, in WHM, go to:

WHM -> Service Configuration -> Apache Configuration -> Include Editor -> Pre Main Include -> Select the current Apache version

LoadModule geoip_module /usr/local/apache/modules/mod_geoip.so
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat MemoryCache

testing:

httpd -m | grep -i geoip

Exim: email limiting per day for a cpanel domain

Following section will give the details how you can set up this on exim.

1

cp /etc/exim.pl /etc/exim_limit.pl

2 change the following section of code in exim_limit.pl:

if ($maxmails > 0) {
my $nummailsinhour = readbacktohour(“/usr/local/apache/domlogs/$domain-smtpbytes_log”);
my $nummailsinday = readbacktodate(“/usr/local/apache/domlogs/$domain-smtpbytes_log”);
if ($nummailsinhour > 100) {
die “Domain $domain has exceeded the max emails per hour. Message discarded.\n”;
}
if ($nummailsinday > $maxmails) {
die “Domain $domain has exceeded the max emails per day. Message discarded.\n”;
}
}

3 change the following line in exim_limit.pl:

sub readbacktodate {

to

sub readbacktohour {

4 Add the following code after that in the same exim_limit.pl:
I mean after completion of subroutine readbacktohour

sub readbacktodate {
my($filename) = @_;
my($buf);
my($filepos) = 0;
my $now = time();
my $onedayago = ($now – (24*60*60));
my($hitcount) = 0;
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);

$filepos = ($size – 4096);
open(RF,”$filename”);
seek(RF,$filepos,0);
while($filepos >= -4096) {
if ($filepos 0) {
$buf =~ /([^\n]+\n)/;
$filepos += length($1);
$buf = substr($buf,length($1));
}
my @BUF = split(/\n/, $buf);
foreach (reverse @BUF) {
my($ttime,$tbytes) = split(/ /);
if ($ttime > $onedayago) {
$hitcount++;
}
}

$filepos -= 4096;
if ($filepos > Server Configuration >> Tweak Settings, in the Mail section, the line ‘The maximum each domain can send out per hour’ is no longer a limit per hour but per day. That mean if you change these settings here it will only affect the maximum emails per day. We’ve hardly limited the number of emails per hour to 100 through the code “nummailsinhour > 100”

5 Go to Exim Configuration Editor, and switch to Advance Mode,
Then search for perl_startup

change the code corresponding to that code to

do ‘/etc/exim_limit.pl’

perl_startup = do ‘/etc/exim_limit.pl’

Save it up and Exim will restart automatically with the new changes.

Good luck!

Memmory out of error while using Yum

Error Message
++++++++++++++++

testing
Loaded plugins: fastestmirror, rhnplugin
Loading mirror speeds from cached hostfile
* cloudlinux-x86_64-server-5: cl-mirror.london.uk2.net
Excluding Packages in global exclude list
Traceback (most recent call last):
File “/usr/bin/yum”, line 29, in ?
yummain.user_main(sys.argv[1:], exit_code=True)
File “/usr/share/yum-cli/yummain.py”, line 309, in user_main
errcode = main(args)
File “/usr/share/yum-cli/yummain.py”, line 178, in main
result, resultmsgs = base.doCommands()
File “/usr/share/yum-cli/cli.py”, line 345, in doCommands
self._getTs(needTsRemove)
File “/usr/lib/python2.4/site-packages/yum/depsolve.py”, line 101, in _getTs
self._getTsInfo(remove_only)
File “/usr/lib/python2.4/site-packages/yum/depsolve.py”, line 112, in _getTsIn fo
pkgSack = self.pkgSack
File “/usr/lib/python2.4/site-packages/yum/__init__.py”, line 662, in
pkgSack = property(fget=lambda self: self._getSacks(),
File “/usr/lib/python2.4/site-packages/yum/__init__.py”, line 508, in _getSack s
self.excludePackages()
File “/usr/lib/python2.4/site-packages/yum/__init__.py”, line 1096, in exclude Packages
ignore_case=False)
File “/usr/lib/python2.4/site-packages/yum/packageSack.py”, line 396, in retur nPackages
None, patterns, ignore_case)
File “/usr/lib/python2.4/site-packages/yum/packageSack.py”, line 482, in _comp uteAggregateListResult
sackResult = apply(method, args)
File “/usr/lib/python2.4/site-packages/yum/sqlitesack.py”, line 1210, in retur nPackages
pkgobjlist = self._buildPkgObjList(repoid, patterns, ignore_case)
File “/usr/lib/python2.4/site-packages/yum/sqlitesack.py”, line 44, in newFunc
return func(*args, **kwargs)
File “/usr/lib/python2.4/site-packages/yum/sqlitesack.py”, line 1191, in _buil dPkgObjList
po = self._packageByKeyData(repo, x[‘pkgKey’], x)
File “/usr/lib/python2.4/site-packages/yum/sqlitesack.py”, line 444, in _packa geByKeyData
po = self.pc(repo, data)
File “/usr/lib/python2.4/site-packages/yum/sqlitesack.py”, line 73, in __init_ _
self._loadedfiles = False
MemoryError
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File “/usr/lib64/python2.4/atexit.py”, line 24, in _run_exitfuncs
Error in sys.exitfunc:
Traceback (most recent call last):
File “/usr/lib64/python2.4/atexit.py”, line 30, in _run_exitfuncs
traceback.print_exc()
File “/usr/lib64/python2.4/traceback.py”, line 212, in print_exc
print_exception(etype, value, tb, limit, file)
File “/usr/lib64/python2.4/traceback.py”, line 125, in print_exception
print_tb(tb, limit, file)
File “/usr/lib64/python2.4/traceback.py”, line 69, in print_tb
line = linecache.getline(filename, lineno)
File “/usr/lib64/python2.4/linecache.py”, line 14, in getline
lines = getlines(filename)
File “/usr/lib64/python2.4/linecache.py”, line 40, in getlines
return updatecache(filename)
File “/usr/lib64/python2.4/linecache.py”, line 100, in updatecache
fp = open(fullname, ‘rU’)
MemoryError

————————————————–
Solution
++++++

# ulimit -a

The output for this will be obtained as :

root@server1 [~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 19
file size (blocks, -f) unlimited
pending signals (-i) 139264
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) 10000
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 15
virtual memory (kbytes, -v) 262144
file locks (-x) unlimited

The reason for such memory error is because of virtual memory and max. memory size. It should be unlimited, otherwise it will show memory error.
# ulimit -m unlimited
# ulimit -v unlimited

Then run Yum