Add more Swap on linux Vm

How to add more swap on a linux Vm.
It can be used on a physical machine too but remember that swap is store on a file and not in a dedicate partition.

#########################sWap File
#Create Local Folder
mkdir -p /usr/local/swap/

#Create a 2Gb Local File to store swap
dd if=/dev/zero of=/usr/local/swap/swapfile1 bs=1024 count=2097152 #2gb 4194304
mkswap /usr/local/swap/swapfile1

#set Grant On File
cd /usr/local/swap/
chown root:root swapfile1
chmod 0600 swapfile1

#Enable Swap
swapon swapfile1

Add this line in /ect/fstab to load swap on system startup:


/usr/local/swap/swapfile1 swap swap defaults 0 0

Db2 : restore a database from an instance to another and set grant to administer database

This post describe how to restore a database backup from an instance to another and set grant; I assume you have successfully installed Db2 and configured a new instance.

Step 1 restore db:

Use this command to restore db*:

db2 restore db <dbname> from <backupdir> ON <datapath> NEWLOGPATH <tranlogpath>

<dbname> = original database name
<backupdir> = path where backup is located (if more then one backup is present you must specify timestamp with comand TAKEN AT)
<datapath> = where you want to store your database path tipically /home/<instancename>/
<tranlogpath> = where you want to store tranlog (I use : /home/<instancename>/tranlog)

* A database backup contains settings for path so if you move Db from one server to another you have to specify new filesystem path

Step 2 grant :

Use this command to set grant:

db2 CONNECT TO <dbname> user <databaseowner> using <databaseownerpassword>;
db2 GRANT DBADM,CREATETAB,BINDADD,CONNECT,CREATE_NOT_FENCED_ROUTINE,IMPLICIT_SCHEMA,LOAD,CREATE_EXTERNAL_ROUTINE,QUIESCE_CONNECT,SECADM ON DATABASE TO USER <newuser>;
db2 CONNECT RESET;

<dbname> = original database name
<databaseowner> = grant must be set from the old db owner, to do this I usually create a new user whit old name on new server.
<databaseownerpassword> = password
<newuser> = new owner

 


Example:

Immagine you have a server named server1 with instance db2inst1 and a database named wpsdb.
Now immagine you have to move a wpsdb to server2 with instance name db2wps.
What you have to do is :

– Restore db: db2 restore db wpsdb from /backup ON /home/db2wps NEWLOGPATH /home/db2wps/tranlog
– create user db2inst1 on server2:(banally “useradd db2inst1” and “passwd db2inst1” to set password)
– grant:

db2 CONNECT TO wpsdb user db2inst1 using password
db2 GRANT DBADM,CREATETAB,BINDADD,CONNECT,CREATE_NOT_FENCED_ROUTINE,IMPLICIT_SCHEMA,LOAD,CREATE_EXTERNAL_ROUTINE,QUIESCE_CONNECT,SECADM ON DATABASE TO USER db2wps
db2 CONNECT RESET

How to export Tivoli Directory Server to .ldif file

This script is simply and usefull to backup all users in a tivoli directory server to an ldif file.
When schedule by crontab it’s possible to add in command line destination folder by $1 param,
so you can have different versions of backup.

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/sh
 
NOW=$(date +"%u")
LPATH=/tmp/juve_full_backup$NOW.ldif
RPATH=/backup/ldap/$1
LOG=/var/log/bckLdap$1"-"$NOW".log"
 
echo "------------------"Backup LDAP on DOW $NOW"----------------------------------">LOG
echo `date`>>$LOG
 
mkdir $RPATH
/opt/IBM/ldap/V6.3/sbin/idsdb2ldif -I juvetds1 -o $LPATH  >$LOG
mv $LPATH $RPATH

Mysql Usefull Commands

Here some usefull command to administer Mysql Database Server:
#Access command line:
mysql -uroot -upassword

#Viev all user:
select user,password,host from mysql.user;

#Enable root remote login :
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘password’;
FLUSH PRIVILEGES;
exit;

#Execute Mysql command from bash:

mysql -uroot -e “create database prod”
mysql -uroot -e “CREATE USER ‘prod’@’%’ IDENTIFIED BY ‘MyProd016′”
mysql -uroot -e “GRANT ALL PRIVILEGES ON prod.* TO ‘prod’@’%’ WITH GRANT OPTION”
mysql -uroot -e “FLUSH PRIVILEGES”
exit;

Lvm Extend Volume Group adding new Disk

These are the step to add space to and existing Logical Volume on a Volume Group:

1) add disk and perform  rescan-scsi-bus.sh
2) Add Physical Volume available for LVM:

pvcreate (-t)* /dev/sdc

3) Exteng the volume group (here namend system) with new create physical volume:

vgextend (-t)* system /dev/sdc

4) Extend target logical volume (here named /dev/system/opt) with new space (here 10gb):

lvextend -L +10G -t /dev/system/opt

5) verify :

lvmdisplay

6) In the end you have to resize physical space :

resize2fs /dev/system/opt

 

*Always by tiping -t you can test command before execute on production server.