In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
The knowledge of this article "CentOS6.5 environment installation nginx server and load balancer configuration method" is not understood by most people, so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "CentOS6.5 environment installation nginx server and load balancer configuration method" article.
1. Download pcre, which is a regular expression function library written in c language
[root@localhost pcre-8.36] # cd / tmp/download/ [root@localhost download] # wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz[root@localhost download] # tar zxvf pcre-8.36.tar.gz
2. Download the zlib library
[root@localhost pcre-8.36] # cd / tmp/download/ [root@localhost download] # wget http://ncu.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz[root@localhost download] # tar-zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
4. Download ssl
[root@localhost zlib-1.2.8] # cd. [root@localhost download] # wget http://www.openssl.org/source/openssl-1.0.1p.tar.gz[root@localhost download] # cd openssl-1.0.1c [root@localhost openssl-1.0.1c] # tar-zxvf openssl-1.0.1c.tar.gz
5. Download nginx
[root@localhost download] # wget http://nginx.org/download/nginx-1.2.8.tar.gz[root@localhost download] # tar-zxvf nginx-1.2.8.tar.gz
6. Installation
[root@localhost download] mv pcre-8.36 / usr/local/ [root@localhost download] mv zlib-1.2.8 / usr/local/ [root@localhost download] mv openssl-1.0.1c / usr/local/ [root@localhost download] mv nginx-1.2.8 / usr/local/ [root@localhost download] cd / usr/local/ [root@localhost local] # cd pcre-8.36 [root@localhost pcre-8.36] #. / configure&&make&&make Install [root@localhost pcre-8.36] cd.. / zlib-1.2.8 [root@localhost zlib-1.2.8] #. / configure & & make & & make install [root@localhost zlib-1.2.8] # cd.. / openssl-1.0.1c [root@localhost openssl-1.0.1c] #. / config & & make & & make install [root@localhost openssl-1.0.1c] # cd. / nginx-1.2.8 [root @ localhost nginx-1.2.8] #. / configure-- prefix=/usr/local/nginx & & make & & make install
7. Start nginx
[root@localhost nginx] # / usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.conf
8. Testing
On the computer that makes sure you can connect to the server, the browser enters the ip address of the machine with nginx installed, and you will see welcome to nginx! The prompt indicates that the installation and configuration is successful.
9. Set up automatic boot (shell script processing)
[root@localhost logs] # vi / etc/init.d/nginx
Add the following shell script.
#! / bin/bash# nginx startup script for the nginx http server# it is v.0.0.2 version.# chkconfig:-85 "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.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/var/run/nginx.pidretval=0prog= "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 nginx_pid start nginx daemons functions.start () {if [- e $nginx_pid]; then echo "nginx already running...." Exit 1fi 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 / var/run/nginx.pid} # reload nginx service functions.reload () {echo-n $"reloading $prog:" # kill-hup `cat ${nginx_pid} `killproc $nginxd-hup retval=$? Echo} # see how we were called.case "$1" instart) start;; stop) stop;; reload) reload;; restart) stop start;; status) status $prog retval=$?;; *) echo $"usage: $prog {start | stop | restart | reload | status | help}" exit 1esacexit $retval
After saving, set permissions so that everyone can operate.
[root@localhost ~] # chmod axix / etc/init.d/nginx [root@localhost logs] # / etc/init.d/nginx statusnginx (pid 2417 2416) is running... [root@localhost logs] # / etc/init.d/nginx stopstopping nginx: [ok] [root@localhost logs] # / etc/init.d/nginx startstarting nginx: [ok] [root@localhost logs] # / etc/init.d/nginx statusnginx (pid 2454 2452) is running... [root@localhost ~] # vi / etc/rc.local
Add:
/ etc/init.d/nginx start
Restart the computer and it will take effect.
Note: the startup directory in the script should be modified if your installation address is different.
Load balancer configuration:
There are two existing servers:
192.168.137.197 (nginx is installed as a repeater and virtual machine in accordance with the above)
192.168.137.33 (no nginx installed, running web project with testing, virtual machine)
10.10.33.59 (no nginx installed, running web project with testing, local computer address)
To run the web project for testing
127.0.0.1 web_app
[root@a conf] # vi / usr/local/nginx/conf/nginx.conf
The configuration is shown as follows:
Worker_processes 8 to pid / usr/local/nginx/nginx.pid;worker_rlimit_nofile 102400 to events {use epoll;worker_connections 102400;} http {include mime.types; default_type application/octet-stream; fastcgi_intercept_errors on; charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 4k; large_client_header_buffers 4 32k; client_max_body_size 300m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; client_body_buffer_size 512k Proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on # 2012-12-19 change nginx logslog_format main'$http_x_forwarded_for-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"''"$http_user_agent" $request_time $remote_addr';upstream web_app {server 192.168.137.1977 remote_addr';upstream web_app 8080 weight=1 max_fails=2 fail_timeout=30s;server 192.168.137.33 remote_addr';upstream web_app weight=1 max_fails=2 fail_timeout=30s Server 10.10.33.59 chinaapp.sinaapp.comserver 8080 weight=1 max_fails=2 fail_timeout=30s;} # chinaapp.sinaapp.comserver {listen 80; server_name chinaapp.sinaapp.com; index index.jsp index.html index.htm; # release directory / data/www root / data/www; location / {proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr Proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_pass http://web_app; expires 3D;}
Set up the host:
[root@a conf] # vi / etc/hosts
Add hosts:
127.0.0.1 web_app
Start nginx
[root@localhost nginx] # / usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.conf
Start the web application of the three servers:
Execute the instruction at 192.168.137.197:
[root@a program] # curl "http://web_app/index.jsp"
The test results are as follows:
Common problems and solutions:
1. Prompt configure: error: you need a C++ compiler for C++ support when installing pcre. com
The reason is that the C++ compiler is not installed, install it with the following command:
[root@localhost pcre-8.37] # yum install-y gcc gcc-c++
2. Failed to start nginx
[root@localhost nginx] # / usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.conf/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: no such file or directory
The reason is the 64bit system, but the package in / usr/local/lib is taken by default.
Inspection method:
[root@localhost nginx] # cd / usr/local/ [root@localhost local] # ls / lib64/ | grep pcrelibpcre.so.0libpcre.so.0.0.1 [root@localhost local] # ls / lib/ | grep pcre
Indicates that the missing package is in lib64
Set up a soft connection to solve:
[root@localhost local] # ln-s / lib64/libpcre.so.0.0.1 / lib64/libpcre.so.1 [root@localhost local] # cd nginx [root@localhost nginx] # / usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.conf
3. Start the error report:
Error: nginx: [emerg] bind () to 0.0.0.0 failed 80 failed (98: address already in use)
Solution: sudo fuser-k 80/tcp
Port is occupied, shut down occupied port
The above is the content of this article on "how to install nginx server and load balancer configuration in CentOS6.5 environment". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to learn more about related knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.