centos7.x编译安装淘宝tengine-2.1.2,


下载所有包,jemalloc(可选)用于优化内存

1 2 3 4 5 6 7 8 9 10 11 12 yum groups install "Development Tools" -y yum -y install bzip2 wget -c ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz wget -c http://www.openssl.org/source/openssl-1.0.2g.tar.gz wget -c http://www.zlib.net/zlib-1.2.11.tar.gz wget -c http://tengine.taobao.org/download/tengine-2.1.2.tar.gz #wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2 tar -zxf pcre-8.40.tar.gz -C /usr/local/src/ tar -zxf openssl-1.0.2g.tar.gz -C /usr/local/src/ tar -zxf zlib-1.2.11.tar.gz  -C /usr/local/src/ tar -zxf tengine-2.1.2.tar.gz -C /usr/local/src/ #tar jxvf jemalloc-3.6.0.tar.bz2 -C /usr/local/src/

1、安装pcre

1 2 3 4 5 6 7 8 9 mkdir /usr/local/pcre   cd /usr/local/src/pcre-8.40   ./configure --prefix=/usr/local/pcre   make -j   make install

2、安装openssl

1 2 3 4 5 6 7 8 9 10 11 mkdir /usr/local/openssl   cd /usr/local/src/openssl-1.0.2g/   ./config --prefix=/usr/local/openssl   make depend   make -j   make install

vi /etc/profile

1 2 3 export PATH=$PATH:/usr/local/openssl/bin or echo "export PATH=$PATH:/usr/local/openssl/bin" >> /etc/profile

:wq!

1 source /etc/profile

3、安装zlib

1 2 3 4 5 6 7 8 9 mkdir /usr/local/zlib   cd /usr/local/src/zlib-1.2.11   ./configure --prefix=/usr/local/zlib   make -j   make install

4、安装Nginx

1 2 3 4 5 6 7 8 9 10 11 12 groupadd www   useradd -g www www -s /bin/false   cd /usr/local/src/tengine-2.1.2/   #开启jemalloc内存优化 ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.2g --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre-8.40 --with-jemalloc=/usr/local/src/jemalloc-3.6.0   make   make install

注意:--with-openssl=/usr/local/src/openssl-1.0.2g --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre-8.40指向的是源码包解压的路径,而不是安装的路径,否则会报错


5、添加开机启动脚本

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 /usr/local/nginx/sbin/nginx #启动Nginx   设置nginx开机启动   vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容   ############################################################   #!/bin/sh   #   # nginx - this script starts and stops the nginx daemon   #   # chkconfig: - 85 15   # description: Nginx is an HTTP(S) server, HTTP(S) reverse \   # proxy and IMAP/POP3 proxy server   # processname: nginx   # config: /etc/nginx/nginx.conf   # config: /usr/local/nginx/conf/nginx.conf   # pidfile: /usr/local/nginx/logs/nginx.pid   # Source function library.   /etc/rc.d/init.d/functions   # Source networking configuration.   /etc/sysconfig/network   # Check that networking is up.   "$NETWORKING" "no" ] && exit 0   nginx="/usr/local/nginx/sbin/nginx"   prog=$(basename $nginx)   NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"   [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx   lockfile=/var/lock/subsys/nginx   make_dirs() {   # make required directories   user=`$nginx -V 2>&1 | grep "configure arguments:" sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`   if [ -z "`grep $user /etc/passwd`" ]; then   useradd -M -s /bin/nologin $user   fi   options=`$nginx -V 2>&1 | grep 'configure arguments:'`   for opt in $options; do   if [ `echo $opt | grep '.*-temp-path'` ]; then   value=`echo $opt | cut -d "=" -f 2`   if [ ! -d "$value" ]; then   # echo "creating" $value   mkdir -p $value && chown -R $user $value   fi   fi   done   }   start() {   [ -x $nginx ] || exit 5   [ -f $NGINX_CONF_FILE ] || exit 6   make_dirs   echo -n $"Starting $prog: "   daemon $nginx -c $NGINX_CONF_FILE   retval=$?   echo   [ $retval -eq 0 ] && touch $lockfile   return $retval   }   stop() {   echo -n $"Stopping $prog: "   killproc $prog -QUIT   retval=$?   echo   [ $retval -eq 0 ] && rm -f $lockfile   return $retval   }   restart() {   #configtest || return $?   stop   sleep 1   start   }   reload() {   #configtest || return $?   echo -n $"Reloading $prog: "   killproc $nginx -HUP   RETVAL=$?   echo   }   force_reload() {   restart   }   configtest() {   $nginx -t -c $NGINX_CONF_FILE   }   rh_status() {   status $prog   }   rh_status_q() {   rh_status >/dev/null 2>&1   }   case "$1" in   start)   rh_status_q && exit 0   $1   ;;   stop)   rh_status_q || exit 0   $1   ;;   restart|configtest)   $1   ;;   reload)   rh_status_q || exit 7   $1   ;;   force-reload)   force_reload   ;;   status)   rh_status   ;;   condrestart|try-restart)   rh_status_q || exit 0   ;;   *)   echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"   exit 2   esac   ############################################################   :wq! #保存退出   chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限   chkconfig nginx on #设置开机启动   /etc/rc.d/init.d/nginx restart #重启程序

在浏览器中打开服务器IP地址,会看到下面的界面,说明Nginx安装成功。


附./configure检测配置结果

1 <br data-filtered="filtered">
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 # Configuration summary   + using PCRE library: /usr/local/src/pcre-8.40   + using OpenSSL library: /usr/local/src/openssl-1.1.0e   + md5: using OpenSSL library   + sha1: using OpenSSL library   + using zlib library: /usr/local/src/zlib-1.2.11   + jemalloc library is disabled     #这个是我之前没有添加jemalloc内存优化的配置,这只是范例参考     nginx path prefix: "/usr/local/nginx"   nginx binary file"/usr/local/nginx/sbin/nginx"   nginx configuration prefix: "/usr/local/nginx/conf"   nginx configuration file"/usr/local/nginx/conf/nginx.conf"   nginx pid file"/usr/local/nginx/logs/nginx.pid"   nginx error log file"/usr/local/nginx/logs/error.log"   nginx http access log file"/usr/local/nginx/logs/access.log"   nginx http client request body temporary files: "client_body_temp"   nginx dso module path: "/usr/local/nginx/modules/"   nginx http proxy temporary files: "proxy_temp"   nginx http fastcgi temporary files: "fastcgi_temp"   nginx http uwsgi temporary files: "uwsgi_temp"   nginx http scgi temporary files: "scgi_temp"



扩展阅读:


Nginx配置txt、pdf、doc、xls等文件直接下载的方法


在nginx配置文件中添加以下代码


location / {


if ($request_filename ~* ^.*?\.(txt|pdf|doc|xls)$){


add_header Content-Disposition: 'attachment;';


}


}


参考:

http://www.osyunwei.com/archives/10057.html

http://blog.csdn.net/elong490/article/details/54913193



本文转自 yanconggod 51CTO博客,原文链接:http://blog.51cto.com/yanconggod/1945117


相关内容