一直没写过,现在整理一次完整的安装过程:
安装完成后使用saltstack把配置分发到每一台服务器上。
[root@192-168-171-146 src]# cd /usr/local/src
[root@192-168-171-146 src]# wget />
[talen@192_168_101_65 soft]$ for i in 6 7 8 ; do scp
Nginx_upstream_hash-0.3.1.tar.gz root@192.168.171.14$i:/usr/local/src/;
done
Nginx_upstream_hash-0.3.1.tar.gz
100% 5049 4.9KB/s 00:00
Nginx_upstream_hash-0.3.1.tar.gz
100% 5049 4.9KB/s 00:00
Nginx_upstream_hash-0.3.1.tar.gz
100% 5049 4.9KB/s 00:00
[root@192-168-171-146 src]# tar zxvf nginx-1.9.5.tar.gz
[root@192-168-171-146 src]# tar zxvf Nginx_upstream_hash-0.3.1.tar.gz
url_hash 是nginx的第三方模块,nginx本身不支持,需要打patch
.
Url_hash 你nginx在做负载均衡的时候。把转发的URL 以hash的形式保存。这样可以保证同一个URL始终
分给同一个real
server,来提高访问速度。
后端集群session没有共享,所以ip_hash,RR,weight,fair等负载均衡方式都将不适用,使用url_hash,编译第三方模块
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
upstream backserver {
server squid1:3128;
server squid2:3128;
hash $request_uri;
hash_method crc32;
}
[root@192-168-171-146 src]# cd nginx_upstream_hash-0.3.1/
[root@192-168-171-146 nginx_upstream_hash-0.3.1]# cat README
== ngx_http_upstream_hash_module ==
Installation:
cd nginx-0.7.62 # or whatever
patch -p0 < /path/to/this/directory/nginx.patch
./configure --add-module=/path/to/this/directory
make
make install
Usage:
upstream backend {
...
hash $request_uri;
hash_again 10; # default 0
}
See for more details.
Questions/patches to Evan Miller, emmiller@gmail.com.
按照README文件的操作进行。
[root@192-168-171-146 src]# cd nginx-1.9.5/
[root@192-168-171-146 nginx-1.9.5]# patch -p0 < ../nginx_upstream_hash-0.3.1/nginx.patch
patching file src/http/ngx_http_upstream.h
Hunk #1 succeeded at 115 (offset 10 lines).
[root@192-168-171-146 nginx-1.9.5]# ./configure --with-http_stub_status_module --add-module=../nginx_upstream_hash-0.3.1/
...
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
...
安装信赖包:
[root@192-168-171-146 nginx-1.9.5]# yum install pcre-devel -y
[root@192-168-171-146 nginx-1.9.5]# ./configure --with-http_stub_status_module --add-module=../nginx_upstream_hash-0.3.1/[root@192-168-171-146 nginx-1.9.5]# ./configure --with-http_stub_status_module --add-module=../nginx_upstream_hash-0.3.1/
checking for OS
+ Linux 2.6.32-573.3.1.el6.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
checking for gcc -pipe switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for O_PATH ... not found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... not found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
configuring additional modules
adding module in ../nginx_upstream_hash-0.3.1/
+ ngx_http_upstream_hash_module was configured
checking for PCRE library ... found
checking for PCRE JIT support ... not found
checking for md5 in system md library ... not found
checking for md5 in system md5 library ... not found
checking for md5 in system OpenSSL crypto library ... found
checking for sha1 in system md library ... not found
checking for sha1 in system OpenSSL crypto library ... found
checking for zlib library ... found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib library
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 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"
[root@192-168-171-146 nginx-1.9.5]# make
...
objs/src/http/modules/ngx_http_upstream_hash_module.o:(.data+0x0): first defined here
collect2: ld returned 1 exit status
make[1]: *** [objs/nginx] Error 1
make[1]: Leaving directory `/usr/local/src/nginx-1.9.5'
make: *** [install] Error 2
这里有一篇外文说:
I find why,in nginx-1.8.0 , it has integrated nginx_upstream, it don't need to add this module in configure.
所以这个插件不用编译了,我原来是1.6.5版本。删除重来。
[root@192-168-171-146 nginx-1.9.5]#
[root@192-168-171-146 src]# rm nginx-1.9.5 -rfv
[root@192-168-171-146 src]# tar zxvf nginx-1.9.5.tar.gz
[root@192-168-171-146 nginx-1.9.5]# ./configure --with-http_stub_status_module
[root@192-168-171-146 nginx-1.9.5]# make
[root@192-168-171-146 nginx-1.9.5]# make install
[root@192-168-171-146 nginx-1.9.5]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 32896880 1765052 29454108 6% /
tmpfs 4023744 12 4023732 1% /dev/shm
/dev/sda3 99671536 61028 94540788 1% /opt
[root@192-168-171-146 nginx-1.9.5]# mkdir -p /opt/nginx/logs
[root@192-168-171-146 nginx-1.9.5]# rm /usr/local/nginx/logs/ -rfv
[root@192-168-171-146 nginx-1.9.5]# ln -s /opt/nginx/logs/ /usr/local/nginx/logs
参考:
/>
http://blog.chinaunix.net/uid-14406129-id-143532.html
/>