vps centos check cpu and memery usage

For memery use:

free -m

You will see an output like this:

total       used       free     shared    buffers     cached

Mem:           512        462         49          0         46        127

-/+ buffers/cache:        287        224

Swap:         2047          0       2047

The important figure to look at is the “used” number in the “buffers/cache” row. This will tell you how much memory your processes are currently using. Memory allocation errors will occur if this number is higher than the total amount of memory and swap space. To see how much RAM is free, check the “free” column in the “buffers/cache” row.

for running process check use:

ps aux

The output will look like this:
root         1  0.0  0.1  10368   632 ?        Ss   Jan07   0:00 init [3]
root         2  0.0  0.0      0     0 ?        S<   Jan07   0:00 [migration/0]
root         3  0.0  0.0      0     0 ?        SN   Jan07   0:00 [ksoftirqd/0]
One of the benefits of a VPS is that, in the case of a memory shortage, you can upgrade RAM on-the-fly with little (Xen) to no (OpenVZ) downtime. Open a support ticket, or find us on live chat, if you need an upgrade!
For active listening port:
netstat -ntplau

Creating links to files and directories in unix centos vps

Creating a link to a directory

It is often useful to change to another directory without typing its full pathname: symbolic links provide a useful shortcut to do this. A symbolic link differs from a hard link. It is a small file that contains a reference (by name) to a directory or file that already exists. Unlike normal links, symbolic links can cross filesystems and link to directories. (They are used extensively by the system.) Also unlike normal links, symbolic links are separate files; they cease to work if the file they point to is deleted or renamed, or if they are moved.

Many of the files found in /bin/lib, and /usr are actually symbolic links that point to files (of the same name) stored below /var/opt. The directories these files are located in are called “storage sections”. Storage sections are used because they make it easier to install system upgrades. Software subsystems (such as UUCP) consist of many files, which may be installed in several directories. However, all the files in a subsystem belong to a single storage section. By overwriting the contents of the (single) storage section directory, all the files in the subsystem can be updated simultaneously.

Symbolic links are identified in a directory listing by a “->”, as follows:

   $ l
   drw-r--r--  1 johnd  unixdoc     29  Feb 27 15:56 mydata -> /u/work

You can obtain a directory listing without symbolic links visible in it by specifying the -L (logical) option. This makes ls (or l, or any related program) list the directory, replacing the information about each symbolic link with the details for the file pointed to by the link:

   $ l -L
   drw-r--r--  1 johnd  unixdoc   10297  Feb 27 15:56 mydata

To create a symbolic link, use the ln -s option, as follows:

ln -s directory symbolic_link

For example, suppose you work in /u/workgrp/tasks/projects and your home directory is /u/me. Your normal command to work on a file would be the following:

   $ cd /u/workgrp/tasks/projects

To reduce the typing required, enter the following command:

   $ ln -s /u/workgrp/tasks/projects mydata

This command creates a symbolic link called mydata in your current directory. From now on, mydata and /u/workgrp/tasks/projects refer to the same location, and you can relocate to /u/workgrp/tasks/projects by typing cd mydata instead of typing in the full pathname.

You must have write permission on a directory before you can create a link that involves that directory or a file in that directory.

add tomcat to auto start in centos VPS

This article assumes that you have already installed the Apache Tomcat Server on your Linux Centos machine. If you need help with your with Apache Tomcat Setup then please click on the Link below.


Step 1: Create a file named tomcat6 in your /etc/init.d directory

$ cd /etc/init.d
$ gedit tomcat6 

If this file is created in windows, make sure the file be converted to UNIX format.  Otherwise,  following would happen:

/bin/bash^M: bad interpreter: No such file or directory

Below is one way to do the conversion in Notepad++

Step 2: Copy the following script and save the file

# chkconfig: 2345 80 20
# Description: Tomcat Server basic start/shutdown script
# /etc/init.d/tomcat6 -- startup script for the Tomcat 6 servlet engine

TOMCAT_HOME=/usr/local/apache-tomcat-6.0.35/bin START_TOMCAT=/usr/local/apache-tomcat-6.0.35/bin/startup.sh STOP_TOMCAT=/usr/local/apache-tomcat-6.0.35/bin/shutdown.sh

start() {
 echo -n "Starting tomcat6: "
 echo "done."

stop() {
 echo -n "Shutting down tomcat6: "
 echo "done."

case "$1" in



 sleep 10

 echo "Usage: $0 {start|stop|restart}"

exit 0

Change the settings for the chkconfig based on your requirements. In a scenario where Apache Web server is in the front of Tomcat server with MySQL database usually the startup sequence should be MySQL then Tomcat and Apache Web Server in last. Also make sure you change the TOMCAT_HOME, START_TOMCAT and STOP_TOMCAT variables based on your Tomcat Install.

Step 3: Update the file permissions to make it executable by any user

$ chmod 755 tomcat6

Step 4: Make sure you have chkconfig command installed

$ chkconfig --help

otherwise just install it
$ sudo apt-get install chkconfig


Step 5: Run chkconfig command to add the script to the startup services

$ chkconfig --add tomcat6

(double dash before add )

Basically the chkconfig command automatically adds the symbolic links for starting and stopping the service based on the paramaters passed to it. Here is the list of links created from the above link. You can run the find command to check.

关于 chkconfig
$ find . -name “*tomcat6”

Response from the above command …

Step 6: Make sure scripts got added to the startup services

Type the following command on the Terminal

$ chkconfig --list tomcat6 

   (double dash before list)
Response should be something like this
tomcat6         0:off   1:off   2:on    3:on    4:on    5:on    6:off

Step 7: Verify your service is working

To start the Tomcat server
$ service tomcat6 start
To stop the Tomcat server
$ service tomcat6 stop

CentOS Linux VPS搭建Java环境

搭建Java环境要安装JDK,搭配Tomcat可以作为JSP Web服务器。系统先升级到目前最新。

yum check-update && yum update

JRE(Java Runtime Enviroment)是Java运行环境,JDK(Java Development Kit)是Java开发环境,包括了Java开发工具、Java运行环境、及其它工具。
Java SE(standard edition)是标准版,Java EE(enterprise edition)是企业版,Java ME(micro edition)是用于移动和嵌入式设备。

这里JDK安装的是Java SE 6:


cd /tmp
wget http://download.oracle.com/otn-pub/java/jdk/6u27-b07/jdk-6u27-linux-i586-rpm.bin
chmod a+x jdk-6u27-linux-i586-rpm.bin


vim /etc/profile


export JAVA_HOME=/usr/java/jdk1.6.0_27
export CALSSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin



安装Tomcat,这里下的是已经编译好的Binary Distributions:

cd /tmp
wget http://labs.renren.com/apache-mirror/tomcat/tomcat-6/v6.0.33/bin/apache-tomcat-6.0.33.tar.gz
tar -zxvf apache-tomcat-6.0.33.tar.gz
mv apache-tomcat-6.0.33 /usr/local/tomcat

编辑tomcat jvm启动参数:

vim /usr/local/tomcat/bin/catalina.sh


JAVA_OPTS=”-Xms32m -Xmx64m -Xss128K -XX:PermSize=16m -XX:MaxPermSize=32m”





Add User to root Group on CentOS VPS

1. Add a new user. In this example, I used ‘myroot’ and then set the password.

[root@CentOS57 ~]# useradd myroot
[root@CentOS57 ~]# passwd myroot
Changing password for user myroot.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

2. Check current groups for ‘root’ user.

[root@CentOS57 ~]# groups
root bin daemon sys adm disk wheel

3. Add ‘myroot’ into root group as below:
useradd -G {group-name} username

[root@CentOS57 ~]# usermod -G root myroot

4. Switch to ‘myroot’ user. Then Check current group for ‘myroot’. root group will be the second group for ‘myroot’.

[root@CentOS57 ~]# su - myroot
[myroot@CentOS57 ~]$ groups
myroot root

5. Grep the ‘myroot’ user’s group.

[root@CentOS57 ~]# grep myroot /etc/group

6. Edit /etc/passwd file,find the following line,change the user ID to 0 :


After modification:


save,get root privilege after login as myroot。

Explanation : Only the owner which is ‘root’ user can edit the /etc/passwd file, not in the root’s group.