CentOS 作为linux世界里最稳定的服务器版本,rhas5一直有很大的应用面,之前一直关注的是freebsd,因为应用的需要,特别在配合mysql和oracle上red hat有着太多优势。
用centos来代替red hat as的使用,因为centos5是利用rhas5的源码,去掉redhat的商标、图标之后编译发行的,是最一个源码编译版本,我用的是centos 5.2
在安装centos 5.2的时候,忘设置swap交换分区,在内存小的情况下,增大swap的作用比较有效的。
配置swap之前,通过 free 和 df 查看 swap 和 磁盘空间情况,目的是通过配置swap后比较变化。
复制代码
free -m</p>
<p>[root@ithomer ~]# free -m
total used free shared buffers cached
Mem: 1008 955 53 0 17 168
-/+ buffers/cache: 769 239
Swap: 0 0 0</p>
<p> </p>
<p>df -h</p>
<p>[root@ithomer ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 15G 4.2G 79% /
tmpfs 505M 0 505M 0% /dev/shm
/dev/xvdb 9.9G 5.1G 4.4G 54% /home/data
第一步 创建文件块
复制代码
[root@ithomer ~]# cd /var (进入一个文件夹)</p>
<p>[root@ithomer var]# dd if=/dev/zero of=swapfile bs=1024 count=1024000 (创建1GB的swap ,一般是内存的两倍)</p>
<p>1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 23.3843 s, 44.8 MB/s</p>
<p>[root@ithomer var]# /sbin/mkswap swapfile (创建swap文件,实际上dd已创建,此处不必再创建)</p>
<p>mkswap: swapfile: warning: don’t erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=e878f535-ea6f-4516-8a34-f1458951aa36</p>
<p>[root@ithomer var]# ll swapfile
-rw-r–r– 1 root root 1048576000 11月 27 00:55 swapfile</p>
<p>[root@ithomer var]# /sbin/swapon swapfile (激活swap文件)</p>
<p>[root@ithomer var]# /sbin/swapon -s (检查swap是否正确)</p>
<p>Filename Type Size Used Priority
/var/swapfile file 1023992 0 -1</p>
<p> </p>
<p>[root@ithomer var]# vi /etc/fstab (加到fstab文件中让系统引导时自动启动)
在末尾增加以下内容:
复制代码
/var/swapfile swap swap defaults 0 0</p>
<p>[root@ithomer var]# reboot
重启之后,top命令查看,有swap分区的大小了
复制代码
free -m</p>
<p>[root@ithomer ~]# free -m
total used free shared buffers cached










