软件源代码包存放位置:/usr/local/src
源码包编译安装位置:/usr/local/软件名字
默认系统就会加载/dev/shm ,它就是所谓的tmpfs,有人说跟ramdisk(虚拟磁盘),但不一样。象虚拟磁盘一样,tmpfs 可以使用您的 RAM,但它也可以使用您的交换分区来存储。而且传统的虚拟磁盘是个块设备,并需要一个 mkfs 之类的命令才能真正地使用它,tmpfs 是一个文件系统,而不是块设备;您只是安装它,它就可以使用了。
tmpfs有以下优势:
1)动态文件系统的大小,
2)tmpfs 的另一个主要的好处是它闪电般的速度。因为典型的 tmpfs 文件系统会完全驻留在 RAM 中,读写几乎可以是瞬间的。
3)tmpfs 数据在重新启动之后不会保留,因为虚拟内存本质上就是易失的。所以有必要做一些脚本做诸如加载,绑定的操作。
首先在/dev/shm建个tmp文件夹,然后与实际/tmp绑定
mkdir /dev/shm/tmp
chmod 777 /dev/shm/tmp
mount --bind /dev/shm/tmp /tmp
5、下载软件
cd /usr/local/src #进入目录
(1)、下载nginx
wget
(2)、下载pcre (支持nginx伪静态)
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
(3)、下载ngx_cache_purge(清除指定URL缓存)
wget
(4)、下载keepalived
wget
6、安装pcre
tar zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure
make
make install
7、安装nginx
groupadd www #添加www组
useradd -g www www -s /bin/false #创建nginx运行账户www并加入到www组,不允许www用户直接登录系统
cd /usr/local/src
tar zxvf ngx_cache_purge-1.5.tar.gz
tar zxvf nginx-1.3.0.tar.gz
cd nginx-1.3.0
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/include/openssl --with-pcre=/usr/local/src/pcre-8.30 --add-module=/usr/local/src/ngx_cache_purge-1.5 --with-http_gzip_static_module
# 注意:--with-pcre指向的是源码包解压的路径,而不是安装的路径,否则编译会报错
make
make install
/usr/local/nginx/sbin/nginx #启动nginx
chown -R /usr/local/nginx/html #设置目录所有者
vi /etc/rc.d/init.d/nginx # 设置nginx开启启动,编辑启动文件添加下面内容
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.1.3.0 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVALchmod +x /etc/rc.d/init.d/nginx # 赋予执行权限
chkconfig nginx on #设置开机启动
service nginx stop #关闭nginx