在linux下,内存虚拟盘映射目录为/dev/shm
一、/dev/shm理论
默认的Linux发行版中的内核配置都会开启tmpfs,映射到了/dev/下的shm目录。可以通过df 命令查看结果.
二、修改/dev/shm大小
默认的最大一半内存大小在某些场合可能不够用,并且默认的inode数量很低一般都要调高些,这时可以用mount命令来管理它。
#mount -o size=1500M -o nr_inodes=1000000 -o noatime,nodiratime -o remount /dev/shm
在2G的机器上,将最大容量调到1.5G,并且inode数量调到1000000,这意味着大致可存入最多一百万个小文件。
如果需要永久修改/dev/shm的值,需要修改/etc/fstab
tmpfs /dev/shm tmpfs defaults,size=1.5G 0 0
mount -o remount /dev/shm
三、/dev/shm应用
首先在/dev/shm建个tmp文件夹,然后与实际/tmp绑定
#mkdir /dev/shm/tmp
#chmod 1777 /dev/shm/tmp
#mount --bind /dev/shm/tmp /tmp
查看设置
mount -l
再以网站runtime目录为例
chmod 0777 /dev/shm/joyurl_runtime
mount --bind /dev/shm/joyurl_runtime /www/web/joyurl.com/runtime
断开绑定
umount /www/web/joyurl/runtime
查看绑定
mount -l
四、设置开机启动
1 修改vi /etc/rc.local 或 把脚本放在/etc/init.d/文件
以添加/etc/init.d/site 为例
#!/bin/bash
# chkconfig: 2345 10 90
# description: site init
sleep 5
mkdir /dev/shm/joyurl_runtime
chmod 1777 /dev/shm/joyurl_runtime
chown www.www /dev/shm/joyurl_runtime
mkdir /dev/shm/joyurl_static
chmod 1777 /dev/shm/joyurl_static
chown www.www /dev/shm/joyurl_static
mount --bind /dev/shm/joyurl_runtime /www/web/joyurl.com/runtime
mount --bind /dev/shm/joyurl_static /www/web/joyurl.com/www/static
#php session目录
mkdir /www/web/joyurl.com/runtime/session
chown www.www /www/web/joyurl.com/runtime/session
chmod 1777 /www/web/joyurl.com/runtime/session
cp -rf /www/web/joyurl.com/www/static_upload/* /www/web/joyurl.com/www/static/
2 设置脚本为开机启动
chkconfig --add site
chkconfig --list
systemctl | grep running