nginx
nginx编译安装:
[root@nginx ~]# yum install gcc -y [root@nginx ~]# yum install gcc-c++ -y [root@nginx ~]# #PCRE库 支持正则表达式 [root@nginx ~]# yum install pcre pcre-devel -y [root@nginx ~]# #支持压缩 [root@nginx ~]# yum install zlib -y [root@nginx ~]# yum install zlib-devel -y [root@nginx ~]# #支持OpenssL https SSL传输协议 [root@nginx ~]# yum install openssl openssl-devel y [root@nginx ~]# yum install perl -y [root@nginx ~]# yum install make -y [root@nginx ~]# cd /opt [root@nginx opt]# yum install wget -y [root@nginx opt]# wget http://www.openssl.org/source/openssl-1.0.1f.tar.gz [root@nginx opt]# ll openssl-1.0.1f.tar.gz -rw-r--r-- 1 root root 4509212 Apr 6 2014 openssl-1.0.1f.tar.gz [root@nginx opt]# tar -xvf openssl-1.0.1f.tar.gz -C /usr/src/ [root@nginx opt]# mv /usr/src/openssl-1.0.1f/ /usr/src/openssl [root@nginx opt]# wget wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz [root@nginx opt]# ls -l pcre-8.34.tar.gz -rw-r--r-- 1 root root 1933734 Apr 6 2014 pcre-8.34.tar.gz [root@nginx opt]# tar -xvf pcre-8.34.tar.gz -C /usr/src/ [root@nginx opt]# mv /usr/src/pcre-8.34/ /usr/src/pcre [root@nginx opt]# wget http://zlib.net/zlib-1.2.8.tar.gz [root@nginx opt]# ls -l zlib-1.2.8.tar.gz -rw-r--r-- 1 root root 571091 Apr 6 2014 zlib-1.2.8.tar.gz [root@nginx opt]# tar -xf zlib-1.2.8.tar.gz -C /usr/src/ [root@nginx opt]# mv /usr/src/zlib-1.2.8/ /usr/src/zlib [root@nginx opt]# useradd nginx -M -s /sbin/nologin [root@nginx opt]# mkdir /etc/nginx [root@nginx opt]# mkdir /var/log/nginx [root@nginx opt]# mkdir /tmp/nginx/client_body_temp -p [root@nginx opt]# mkdir /tmp/nginx/proxy_temp [root@nginx opt]# touch /var/run/nginx.pid [root@nginx opt]# touch /var/log/nginx/error.log [root@nginx opt]# touch /var/log/nginx/access.log [root@nginx opt]# touch /var/lock/nginx [root@nginx opt]# chown nginx.nginx /etc/nginx/ [root@nginx opt]# chown -R nginx.nginx /var/log/nginx/ [root@nginx opt]# chown nginx.nginx /var/run/nginx.pid [root@nginx opt]# chown nginx.nginx /var/lock/nginx [root@nginx opt]# chown nginx.nginx /tmp/nginx -R [root@nginx opt]# mkdir /user/local/nginx/objs -p [root@nginx opt]# chown nginx.nginx /user/local/nginx -R [root@nginx opt]# wget http://nginx.org/download/nginx-1.4.7.tar.gz [root@nginx opt]# cd /opt/ [root@nginx opt]# ll total 752 -rw-r--r-- 1 root root 769153 Apr 6 2014 nginx-1.4.7.tar.gz [root@nginx opt]# tar -xvf nginx-1.4.7.tar.gz -C /usr/src/ [root@nginx opt]# cd /usr/src/ [root@nginx src]# ls debug kernels nginx-1.4.7 [root@nginx src]# mv nginx-1.4.7/ nginx [root@nginx src]# cd nginx/ [root@nginx nginx]# ls auto CHANGES.ru configure html man src CHANGES conf contrib LICENSE README [root@nginx nginx]# ./configure --prefix=/usr/local/nginx --sbin-path=/sbin/nginx --conf-path=/etc/nginx/nginx.conf --with-cc=/usr/bin/gcc --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --builddir=/usr/local/nginx/objs --with-perl=/usr/bin/perl --http-log-path=/var/log/nginx/access.log --user=nginx --group=nginx --http-proxy-temp-path=/tmp/nginx/proxy_temp --with-pcre --with-pcre=/usr/src/pcre --with-openssl=/usr/src/openssl --with-zlib=/usr/src/zlib --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_mp4_module --with-http_flv_module [root@nginx nginx]# make && make install [root@nginx ~]# nginx [root@nginx ~]# ps -ef | grep nginx root 20808 1 0 06:06 ? 00:00:00 nginx: master process nginx nginx 20809 20808 0 06:06 ? 00:00:00 nginx: worker process root 20811 1597 0 06:06 pts/0 00:00:00 grep nginx ################################ -----安装nginx 脚本 yum install gcc -y yum install gcc-c++ -y yum install pcre pcre-devel -y yum install zlib -y yum install zlib-devel -y yum install openssl openssl-devel -y yum install perl -y yum install make -y cd /opt yum install wget -y wget http://www.openssl.org/source/openssl-1.0.1f.tar.gz tar -xvf openssl-1.0.1f.tar.gz -C /usr/src/ mv /usr/src/openssl-1.0.1f/ /usr/src/openssl wget http://ftp.gnu.org/pub/gnu/glibc/glibc-2.7.tar.gz wget wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz tar -xvf pcre-8.34.tar.gz -C /usr/src/ mv /usr/src/pcre-8.34/ /usr/src/pcre wget http://zlib.net/zlib-1.2.8.tar.gz tar -xf zlib-1.2.8.tar.gz -C /usr/src/ mv /usr/src/zlib-1.2.8/ /usr/src/zlib useradd nginx -M -s /sbin/nologin mkdir /etc/nginx mkdir /var/log/nginx mkdir /tmp/nginx/client_body_temp -p mkdir /tmp/nginx/proxy_temp touch /var/run/nginx.pid touch /var/log/nginx/error.log touch /var/log/nginx/access.log touch /var/lock/nginx chown nginx.nginx /etc/nginx/ chown -R nginx.nginx /var/log/nginx/ chown nginx.nginx /var/run/nginx.pid chown nginx.nginx /var/lock/nginx chown nginx.nginx /tmp/nginx -R mkdir /usr/local/nginx/objs -p --mkdir /usr/src/pcre/Makefile chown nginx.nginx /usr/local/nginx -R wget http://nginx.org/download/nginx-1.4.7.tar.gz tar -xvf nginx-1.4.7.tar.gz -C /usr/src/ cd /usr/src/ mv nginx-1.4.7/ nginx cd nginx/ ./configure --prefix=/usr/local/nginx --sbin-path=/sbin/nginx --conf-path=/etc/nginx/nginx.conf --with-cc=/usr/bin/gcc --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --builddir=/usr/local/nginx/objs --with-perl=/usr/bin/perl --http-log-path=/var/log/nginx/access.log --user=nginx --group=nginx --http-proxy-temp-path=/tmp/nginx/proxy_temp --with-pcre --with-pcre=/usr/src/pcre --with-openssl=/usr/src/openssl --with-zlib=/usr/src/zlib --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_mp4_module --with-http_flv_module make && make install nginx ps -ef | grep nginx
#!/bin/bash #脚本对日志文件进行切割 #脚本需要crontab 每天定时执行 #Nginx 日志文件的存放路径 logs_path="/../logs/" mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/ echo "-----------------" mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log kill -USER1 `cat /../nginx/nginx.pid`
crontab -e 00 00 * * * /bin/bash /…/…/cut_nginx_log.sh
[root@mail init.d]# nl /etc/init.d/nginx 1 #!/bin/bash 2 # chkconfig: - 85 15 3 # description: The Apache HTTP Server is an efficient and extensible \ 4 # server implementing the current HTTP standards. 5 # 6 # Source function library. 7 . /etc/rc.d/init.d/functions 8 nginx=/usr/local/nginx/sbin/nginx 9 case $1 in 10 start) 11 num=`netstat -lanput | grep nginx | wc -l` 12 if [ $num -gt 0 ] 13 then 14 echo "nginx is running" 15 else 16 $nginx && echo -ne "nginx is started\t\t\t[ \033[31;48mok\033[0m ]\n" 17 fi 18 ;; 19 stop) 20 num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l` 21 if [ $num2 -gt 0 ] 22 then 23 $nginx -s stop > /dev/null 2>&1 24 num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l` 25 if [ $num2 -gt 0 ] 26 then 27 pkill -9 nginx 28 fi 29 num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l` 30 if [ $num2 -eq 0 ] 31 then 32 echo -ne "nginx is stoped\t\t\t[ \033[31;48mok\033[0m ]\n" 33 else 34 echo -ne "nginx is stoped\t\t\t[ \033[31;48mfaild\033[0m ]\n" 35 fi 36 fi 37 ;; 38 restart) 39 num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l` 40 if [ $num2 -gt 0 ] 41 then 42 $nginx -s stop > /dev/null 2>&1 43 num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l` 44 if [ $num2 -gt 0 ] 45 then 46 pkill -9 nginx 47 fi 48 num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l` 49 if [ $num2 -eq 0 ] 50 then 51 echo -ne "nginx is stoped\t\t\t\t[ \033[31;48mok\033[0m ]\n" 52 else 53 echo -ne "nginx is stoped\t\t\t\t[ \033[31;48mfaild\033[0m ]\n" 54 fi 55 fi 56 num=`netstat -lanput | grep nginx | wc -l` 57 if [ $num -gt 0 ] 58 then 59 echo "nginx is running" 60 else 61 $nginx && echo -ne "nginx is started\t\t\t[ \033[31;48mok\033[0m ]\n" 62 fi 63 ;; 64 status) 65 num=`ps -ef|grep "nginx:"|grep -v grep|wc -l` 66 if [ $num -eq 0 ] 67 then 68 echo "nginx is stoped" 69 else 70 echo "nginx is runing" 71 fi 72 ;; 73 *) 74 echo "Usage: nginx {start|stop|restart|status}" 75 ;; 76 esac