Showing posts with label CentOS. Show all posts
Showing posts with label CentOS. Show all posts

Monday, October 6, 2014

Install OpenVZ on Amazon EC2 Instance

1. Create an CentOS 6 Amazon Instance from the MarketPlace. 

Click on launch instance, then click on AWS marketpalce
I choose:
Rating
Sold by CentOS.org
$0.00/hr for software


2. Download this script into instance and run it. 

https://raw.githubusercontent.com/H2so4/CentOS-6-Quick-Install-Scripts/master/installOpenVZ-with-WebPanel.sh

#!/bin/bash
# run: source <(curl -s https://raw.github.com/qrpike/CentOS6---OpenVZ-Installer/master/installOpenVZ.sh)


clear
echo 'Going to install OpenVZ for you..'

echo 'installing wget..'
yum install -y wget

echo 'now adding openvz Repo'
cd /etc/yum.repos.d
wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo
rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ

echo 'Installing OpenVZ Kernel'
yum install -y vzkernel.x86_64

echo 'Installing additional tools'
yum install -y vzctl vzquota

echo 'Changing around some config files..'
sed -i 's/kernel.sysrq = 0/kernel.sysrq = 1/g' /etc/sysctl.conf
sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf

echo 'net.ipv4.conf.default.proxy_arp = 0' >> /etc/sysctl.conf
echo 'net.ipv4.conf.all.rp_filter = 1' >> /etc/sysctl.conf
echo 'net.ipv4.conf.default.send_redirects = 1' >> /etc/sysctl.conf
echo 'net.ipv4.conf.all.send_redirects = 0' >> /etc/sysctl.conf
echo 'net.ipv4.icmp_echo_ignore_broadcasts=1' >> /etc/sysctl.conf
echo 'net.ipv4.conf.default.forwarding=1' >> /etc/sysctl.conf

echo 'Done with that, purging your sys configs'
sysctl -p

sed -i 's/NEIGHBOUR_DEVS=detect/NEIGHBOUR_DEVS=all/g' /etc/vz/vz.conf
sed -i 's/SELINUX=enabled/SELINUX=disabled/g' /etc/sysconfig/selinux

echo 'Now downloading CentOS6 x86_64 template....'
cd /vz/template/cache
wget http://download.openvz.org/template/precreated/centos-6-x86_64.tar.gz

/bin/cp /etc/rc.local /tmp/rc.local
cat > /etc/rc.local << EOF
#!/bin/bash
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh 
modprobe vzcpt
modprobe nf_conntrack_ftp
modprobe ip_nat_ftp
/bin/cp -f /tmp/rc.local /etc/rc.local
EOF

# BARE MINIMUM OpenVZ iptables config - CENTOS 6.4
cat > /etc/sysconfig/iptables << EOF
*nat
:PREROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth+ -j MASQUERADE
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type echo-request -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3000 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -p icmp -m icmp --icmp-type echo-request -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -i lo -j ACCEPT
-A FORWARD -o eth+ -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
EOF
reboot


echo ' - - - - - - - - - - - - - - - - - - - - - - '
echo ' The server will reboot now and install OpenVZ Web panel'
echo ' '
echo 'When the server boots, it will run the OpenVZ Web panel installation which can take up to 10 minutes'
echo 'This script is executed by backing up/replacing /etc/rc.local with a new file containing the installation script.'
echo 'Once complete, the original /etc/rc.local file is replaced'
echo ' - - - - - - - - - - - - - - - - - - - - - - '

echo '..... well.... that should do it.'
echo 'oh, and ur welcome...'

More info
http://scaleup.us/2014/01/01/centos-one-liner-installation-openvz-and-openvz-web-panel/




Tuesday, July 22, 2014

Start network after boot on CentOS

You have two options, use the network-scripts or networkmanager

For myself, I want to use the network scripts. 
chkconfig NetworkManager off
chkconfig network on
Disable the NetworkManager and enable the old network

Then, you need to make sure you are setting up a correct network script at /etc/sysconfig/network-scripts/ifcfg-eth0

make sure ONBOOT=yes

Example of external network interface using DHCP:

$ vim /etc/sysconfig/network-scripts/ifcfg-em1
DEVICE=em1
HWADDR=00:26:B9:3E:33:A9
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp
DHCP_HOSTNAME=sr2s1
PEERDNS=yes

Example of internal network interface using static IP:

vim /etc/sysconfig/network-scripts/ifcfg-p1p1
DEVICE=p1p1
HWADDR=00:1B:21:44:8D:70
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.21
BROADCAST=192.168.0.255
NETMASK=255.255.255.0
NAME=p1p1


Friday, June 27, 2014

Setup FTP server

CentOS

# yum install vsftpd ftp -y
http://www.unixmen.com/install-vsftpd-server-on-centos-rhel-scientific-linux-6-4/

FTP login uses plain/clear text, you can use SFTP to encrypt the login

If you have following problem when use FTP to login:
Name (localhost:dbadmin): username
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/username
Login failed.
ftp> 

You just need to disable selinux and reboot

To disable permanently, I edited /etc/selinux/config and set
SELINUX=disabled
After the reboot, I was able to log in normally.

http://unix.stackexchange.com/questions/79743/what-are-the-settings-to-correct-vsftpd-500-oops-cannot-change-directory-erro

Kali Linux


   17  apt-cache search ftpd
   19  apt-get install ftpd
   21  /etc/init.d/atftpd
   22  /etc/init.d/atftpd start

$ service atftpd start

Note that ftp server does not allow root to log in

root@kali-csc5991:/home/csc5991-student# ftp localhost
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
220 kali-csc5991 FTP server (Version 6.4/OpenBSD/Linux-ftpd-0.17) ready.
Name (localhost:csc5991-student):
331 Password required for csc5991-student.
Password:
230-
230- The programs included with the Kali GNU/Linux system are free software;
230- the exact distribution terms for each program are described in the
230- individual files in /usr/share/doc/*/copyright.
230-
230- Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
230- permitted by applicable law.
230 User csc5991-student logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

Monday, January 13, 2014

Configure the hostname in CentOS

Test a hostname if working:
nfslookup HOSTNAME
or
nfslookup IP_ADDRESS

to see if there is an entry in the DNS server

First, you need to have a correct network script in /etc/sysconfig/network-script/ifcfg-eth4

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth4 


DEVICE=eth4                                   //device name
HWADDR=00:26:B9:38:4C:23            // mac address 
TYPE=Ethernet                         
ONBOOT=yes                                  // automatically connected after bootup
NM_CONTROLLED=no                     // does not use Network Manager, use ifcfg-eth4 script
BOOTPROTO=dhcp                         // use DHCP
DHCP_HOSTNAME=sr2s18              // configure DHCP hostname

PEERDNS=yes                                //Modify /etc/resolv.conf if the DNS directive is set. If using DHCP, then yes is the default


Then, configure the hostname:

http://www.rackspace.com/knowledge_center/article/centos-hostname-change

1. set /etc/sysconfig/network

[root@sr2s16 ~]# cat /etc/sysconfig/network
NETWORKING_IPV6=no
HOSTNAME=sr2s16.example.com

NETWORKING=yes

2. configre /etc/hosts

[root@sr2s16 ~]# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
129.174.114.142 sr2s16.example.com sr2s16
::1 sr2s16.example.com sr2s16

192.168.0.36 sr2s16.example.com sr2s16


3. restart network

$ service network restart









Friday, January 10, 2014

network configuration sample on Cent OS

External network interface using dhcp: /etc/sysconfig/network-script/ifcfg-eth4

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth4 

DEVICE=eth4
HWADDR=00:26:B9:38:4C:23
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

Internal network interface using static IP: /etc/sysconfig/network-script/ifcfg-eth0

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
HWADDR=00:1B:21:44:96:10
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.38
BROADCAST=192.158.0.25
NETMASK=255.255.255.0
NAME=eth0

Run dhcp when system starts up on Cent OS

configure /etc/sysconfig/network-script/ifcfg-eth4

DEVICE=eth4
HWADDR=00:26:B9:38:4C:23
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

if you set the onboot=yes, the system will run dhcp when system boots

Fix nobody issue on CentOS/Ubunut using LDAP and NFS

CentOS

vim /etc/idmapd.conf
add Domain=example.com
restart the services
/etc/init.d/rpcidmapd restart and /etc/init.d/nfs restart

http://lfhck.com/question/100876/centos-6--ldap--nfs-file-ownership-is-stuck-on-nobody

Solved!
I happened to notice this line in /var/log/messages on my NFS server when I was attempting to mount an export from the remote client:
Feb 28 15:54:02 storage1 rpc.idmapd[1651]: nss_getpwnam: name 'nobody' does not map into domain 'localdomain'
This caused me to look at the first few lines of /etc/idmapd.conf:
[General]
#Verbosity = 0
# The following should be set to the local NFSv4 domain name
# The default is the host's DNS domain name.
#Domain = local.domain.edu
I then added Domain=subdomain.mycompany.com under the commented out "Domain" line. Saved, exited and then ran/etc/init.d/rpcidmapd restart and /etc/init.d/nfs restart.



Ubuntu

vim /etc/idmapd.conf
add Domain=example.com
reboot

Monday, December 30, 2013

Configure NFS server on CentOS 6.4

I use two physical machines to conduct this experiment.
NFS Server IP: 192.168.0.21
NFS Client IP: 192.168.0.27

Install NFS Server (CentOS 6.4)

$ yum install nfs-utils -y
$ service nfs start
$ chkconfig nfs on

Configure NFS Server

$ mkdir /nfs_dir
$ chmod 777 /nfs_dir
$ vim /etc/exports
add this line into the file
/nfs-dir 192.168.0.27(rw.sync,root_squash)

These settings accomplish several tasks:
  • rw: This option allows the client server to both read and write within the shared directory

  • sync: Sync confirms requests to the shared directory only once the changes have been committed.

  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.

  • no_root_squash: This phrase allows root to connect to the designated director

$ exportfs -a
$ exportfs 
$ showmount -e

You may want to flush the IP Tables to allow the NFS connection
$ iptables -L 
$ iptables -F

Configure NFS Client

$ mkdir /nfs_mnt
$ mount -t nfs 192.168.0.21:/nfs_dir /nfs_mnt

Or you can set the /etc/fstab file, and this line into the file
192.168.0.21:/nfs_dir  /nfs_mnt   nfs4     defaults,acl        1 1

Show mount list
$ mount
$ df -h

If you have an error message:
# mount -a
mount: wrong fs type, bad option, bad superblock on 172.31.27.164:/nfs_meerkats,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)
       In some cases useful info is found in syslog - try

       dmesg | tail  or so

Solution: You need to install nfs-utils on the client side. Also, you need to service rpcbind start


IP Tables

$ iptables -L [--list]
list all of the IP table rules

$ iptables -F [--flush]
flush all of the IP table rules

$ service iptables save
save current iptables to /etc/sysconfig/iptables


Good article from linuxwave blog

http://linuxwave.blogspot.com/2013/11/manually-manipulating-iptables-in.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Linuxwave+%28linuxwave%29


Manually manipulating iptables in CentOS and Redhat

The iptables rules in redhat based distro is being kept by default in /etc/sysconfig/iptables and /etc/sysconfig/ip6tables. To manipulate the firewall, just add or remove rules from this file, and restart iptables services. For example, we want to allow tftp port, which is port 69 udp:
  1. Edit /etc/sysconfig/iptables
    • # vi /etc/sysconfig/iptables
  2. Add the following lines, before the final LOG and DROP lines for INPUT chain:
    • -A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT
  3. Save and close the file
  4. Restart iptables service:
    • # /etc/init.d/iptables restart
  5. Check your new iptables rules, where -L is to list all rules in the selected chain, and -n is for printing port in numeric output:
    • # sudo iptables -L -n
  6. And you can see that
    "ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           state NEW udp dpt:69"
    line is in the iptables file.

To block any particular port, you just need to edit /etc/sysconfig/iptables, remove the ACCEPT line that contain that port, and restart iptables, and you are done :)


Save IP tables on CentOS
/etc/init.d/iptables start or service iptables save


Remove IPtable rules by line
iptables -vnL --line-numbers
iptables -D INPUT 22


Thursday, June 20, 2013

Install OpenVZ on CentOS

Installation: I successfully installed OpenVZ on CentOS 6.4, but CentOS 5.5 has booting problem after switching to OpenVZ kernel

http://openvz.org/Quick_installation
https://openvz.org/Quick_Installation_CentOS_6

Create and Run a Container:
http://openvz.org/Basic_operations_in_OpenVZ_environment
http://openvz.org/Quick_installation

Change hostname on CentOS

$vim /etc/sysconfig/network

Change the HOSTNAME to anything you like
e.g.: sr1s5

Sunday, July 29, 2012

CentOS cannot boot

I had couple of times with CentOS cannot boot.

Please read my previous article about how to use Ubuntu LiveCD, and mount CentOS Volume group disk. Then you can change the grub.cfg file.

http://fengweizhang.blogspot.com/2011/02/mount-lvm-partition-from-other-disk.html

But it didn't work for this time.

I cashed CentOS again by adding mem=2000 to the boot argument in grub.cfg. Even I used first method, it cannot find any file in /boot directory.

This time I soved by using CentOS LiveCD. It has an rescue function, and install grub and configure boot flag automatic.

Monday, July 16, 2012

Install Custom Kernels on CentOS

Read: http://wiki.centos.org/HowTos/Custom_Kernel


Basic, it suports kernel from CentOS source, not from mainline kernel from kernel.org.

But I have been successfully compiled kernel version 2.6.19 based on CentOS 4.5, and version 2.6.24 based on CentOS 5.5.

Steps:
$make menuconfig // need to enable General config-->enable deprecated sysfs 
$make -j4
$make modules_install
$make install



Ref:
https://www.centos.org/modules/newbb/viewtopic.php?topic_id=15198&forum=37&post_id=88760#threadbottom

Friday, June 8, 2012

How to Limit the Amount of Memory Available to OS

Linux:

set the mem=2000m as the boot arguments, then the Linux only use first 2000MB memory. If the total RAM is 2G, it reserves 48MB.
http://fengweizhang.blogspot.com/2012/06/boot-arguments-on-linux.html


Windows:

Add line
MaxPhyPage=0x7D000 
at [386enh] section of C:\WINDOWS\system.ini
0x7D000 * 4KB = 2000MB
http://support.microsoft.com/kb/181862



Sunday, April 22, 2012

Crash CentOS...

I crashed my CentOS testing machine today. The command I run:
 $ yum remove glib2

I was trying to reinstall glib2(I know there is a reinstall command, but I don't why I didn't use that one), and I removed the glib2 packet. 

After I run this command, I went out for dinner. 

When I came back, my System is crashed. I tried many ways to rescue, but none of them helped. 
For exmaple: 
reboot into another kernel.
Put the CentOS installation disk, upgrade the OS, rescue the OS.....

Finally, I reinstall the CentOS. On lucky thing is I have backed up all my data on the server. 

Never never remove glib2 packet in future...

Saturday, April 21, 2012

CentOS 5.5 Download

http://mirror.teklinks.com/centos/5.5/isos/i386/
http://centos.org/modules/tinycontent/index.php?id=15

Go to CentOS website, and to download mirror list.
Some Mirror doesn't have full list of versions of CentOS. You need check one by one

Tuesday, November 22, 2011

Install RPM file in CentOS

rpm -iv sloccount-2.26-1.i386.rpm

Tuesday, October 4, 2011

Install QEMU on CentOS 5.5

If you don't want to install it form source, you could simply do:  $ yum install qemu


install it from source:
http://fengweizhang.blogspot.com/2012/03/install-qemu.html

or

Download QEMU version: qemu-0.12.5.tar.gz from wiki.qemu.org/Download
$ tar -xvzf qemu-0.12.5.tar.gz
$ cd qemu-0.12.5
$ ./configure
$ make
$ make install

Note: May have ./configure error saying missing glib-2.0 library. Please go to following website, add the i686 repository to current OS.
http://wiki.centos.org/AdditionalResources/Repositories/RPMForge
Download it, and install it
Then do:
$ yum install glib2-devel.i386
$ yum install blid2.i386

Friday, February 4, 2011

mount LVM partition from other disk

 Supposed you installed Ubuntu or Cent OS on your machine, you want to mount another LVM paritition disk.
Following is the detailed steps:

2. Boot using the live cd. Search for these tools: lvm2. If the cd do not have it, install it. (Cent OS already installed, Ubuntu maybe not)
# apt-get install lvm2

3. To make sure the harddisk is recognised, you can use fdisk
# fdisk -lu

4. Once installed, run pvscan to scan all disks for physical volume. this to make sure your LVM harddisk is detected by Ubuntu
# pvscan
PV /dev/sda2 VG VolGroup00 lvm2 [74.41 GB / 32.00 MB free]
Total: 1 [74.41 GB] / in use: 1 [74.41 GB] / in no VG: 0 [0 ]

5. After that run vgscan to scan disks for volume groups.
# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VolGroup00" using metadata type lvm2

6. Activate all volume groups available.
# vgchange -a y
2 logical volume(s) in volume group "VolGroup00" now active

7. Run lvscan to scan all disks for logical volume. You can see partitions inside the hard disk now active.
# lvscan
ACTIVE '/dev/VolGroup00/LogVol00' [72.44 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [1.94 GB] inherit

8. Mount the partition to any directory you want, usually to /mnt
# mount /dev/VolGroup00/LogVol00 /mnt

more info:
http://linuxwave.blogspot.com/2007/11/mounting-lvm-disk-using-ubuntu-livecd.html