激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

Linux|Centos|Ubuntu|系統進程|Fedora|注冊表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服務器之家 - 服務器系統 - Centos - CentOS6.5環境安裝nginx服務器及負載均衡配置操作詳解

CentOS6.5環境安裝nginx服務器及負載均衡配置操作詳解

2022-03-07 16:19ASIH Centos

這篇文章主要介紹了CentOS6.5環境安裝nginx服務器及負載均衡配置操作,結合實例形式較為詳細的分析了CentOS6.5環境安裝nginx服務器及負載均衡配置具體步驟、命令與相關問題解決方法,需要的朋友可以參考下

本文實例講述了centos6.5環境安裝nginx服務器及負載均衡配置操作。分享給大家供大家參考,具體如下:

1、下載pcre, 是一個用c語言編寫的正則表達式函數庫

?
1
2
3
[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、下載zlib庫

?
1
2
3
[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、下載ssl

?
1
2
3
4
[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、下載nginx

?
1
2
[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、安裝

?
1
2
3
4
5
6
7
8
9
10
11
12
13
[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、啟動nginx

?
1
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

8、測試

在確保可以連接到服務器的電腦上,瀏覽器輸入裝了nginx的機器的ip地址,會看到welcome to nginx!的提示說明安裝配配置成功了。

CentOS6.5環境安裝nginx服務器及負載均衡配置操作詳解

9、設置開機自動啟動(shell腳本處理)

?
1
[root@localhost logs]# vi /etc/init.d/nginx

添加以下shell腳本。

?
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
#!/bin/bash
# nginx startup script for the nginx http server
# it is v.0.0.2 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=/var/run/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 /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" 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 $retval

保存后,設置權限讓所有人可以操作。

?
1
2
3
4
5
6
7
8
9
10
[root@localhost ~]# chmod a+x /etc/init.d/nginx
[root@localhost logs]# /etc/init.d/nginx status
nginx (pid 2417 2416) is running...
[root@localhost logs]# /etc/init.d/nginx stop
stopping nginx: [ ok ]
[root@localhost logs]# /etc/init.d/nginx start
starting nginx: [ ok ]
[root@localhost logs]# /etc/init.d/nginx status
nginx (pid 2454 2452) is running...
[root@localhost ~]# vi /etc/rc.local

添加:

?
1
/etc/init.d/nginx start

重啟電腦就會生效。

注意:腳本里面關于啟動目錄的,如果你的安裝地址不一樣,要進行修改。

負載均衡配置:

現有兩部服務器:

192.168.137.197     (按照以上操作安裝有nginx,作為轉發機,虛擬機)
192.168.137.33     (無安裝nginx,運行有測試用的web工程,虛擬機)
10.10.33.59    (無安裝nginx,運行有測試用的web工程,本地電腦地址)
,運行有測試用的web工程
127.0.0.1 web_app

?
1
[root@a conf]# vi /usr/local/nginx/conf/nginx.conf

配置如下展示:

?
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
worker_processes 8;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 102400;
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 logs
log_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.197:8080 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.137.33:8080 weight=1 max_fails=2 fail_timeout=30s;
server 10.10.33.59:8080 weight=1 max_fails=2 fail_timeout=30s;
}
####chinaapp.sinaapp.com
server {
  listen 80;
  server_name chinaapp.sinaapp.com;
  index index.jsp index.html index.htm;
  #發布目錄/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;
  }
 }
}

設置host:

?
1
[root@a conf]# vi /etc/hosts

添加hosts:

?
1
127.0.0.1 web_app

啟動nginx

?
1
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

啟動三部服務器的web應用:

在192.168.137.197執行指令:

?
1
[root@a program]# curl "http://web_app/index.jsp"

測試結果如下:

CentOS6.5環境安裝nginx服務器及負載均衡配置操作詳解

常見問題及解決辦法:

1、安裝pcre時提示configure: error: you need a c++ compiler for c++ support.

原因是沒有安裝c++編譯器,采用下面的命令安裝:

?
1
[root@localhost pcre-8.37]# yum install -y gcc gcc-c++

2、啟動nginx失敗

?
1
2
[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

原因是64bit的系統,但是默認取了/usr/local/lib里面的包

檢查方法:

?
1
2
3
4
5
[root@localhost nginx]# cd /usr/local/
[root@localhost local]# ls /lib64/ |grep pcre
libpcre.so.0
libpcre.so.0.0.1
[root@localhost local]# ls /lib/ |grep pcre

說明缺失的包在lib64

設置軟連接來解決:

?
1
2
3
[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、啟動報錯:

報錯:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: address already in use)

解決辦法:sudo fuser -k 80/tcp

端口被占用,關閉占用端口

希望本文所述對大家centos服務器配置有所幫助。

原文鏈接:https://blog.csdn.net/hanzheng260561728/article/details/51884108

延伸 · 閱讀

精彩推薦
  • CentosCentOS6.5下Redis安裝與配置詳細步驟

    CentOS6.5下Redis安裝與配置詳細步驟

    本篇文章主要介紹了CentOS6.5下Redis安裝與配置詳細步驟,詳細介紹redis單機單實例安裝與配置,服務及開機自啟動。有興趣的可以了解一下。...

    飛流11452021-12-24
  • CentosCentOS 6.6實現永久修改DNS地址的方法

    CentOS 6.6實現永久修改DNS地址的方法

    這篇文章主要介紹了CentOS 6.6實現永久修改DNS地址的方法,涉及針對CentOS配置文件的相關設置技巧,具有一定參考借鑒價值,需要的朋友可以參考下 ...

    Linux社區4472020-08-21
  • CentosCentOS下Uptime命令詳解

    CentOS下Uptime命令詳解

    在Linux下,我們可以使用uptime命令,而且此命令不必使用root權限。uptime命令在系統中已經默認安裝了。今天小編為大家帶來的是CentOS下Uptime命令詳解;希望...

    CentOS之家11482019-06-19
  • Centoscentos 安裝與操作方法

    centos 安裝與操作方法

    這篇文章主要介紹了centos 安裝與操作方法,需要的朋友可以參考下...

    centos之家5272019-07-11
  • CentosCentos7運用/dev/shm進行網站優化

    Centos7運用/dev/shm進行網站優化

    這篇文章主要介紹了LINUX中Centos7運用/dev/shm進行網站優化相關知識點,對此有興趣的朋友參考學習下。...

    彬菌9912022-03-02
  • CentosCentos 7開啟網卡自動獲取IP的詳細方法

    Centos 7開啟網卡自動獲取IP的詳細方法

    本篇文章主要介紹了Centos 7開啟網卡自動獲取IP的詳細方法,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧...

    凌鋒8972021-12-29
  • Centoscentos不小心刪除/root目錄該如何解決?

    centos不小心刪除/root目錄該如何解決?

    一些朋友最近在問小編centos不小心刪除/root目錄該如何解決?今天小編就為大家分享centos不小心刪除/root目錄解決辦法;希望對大家會有幫助,有需要的朋友...

    腳本之家8022019-05-29
  • CentosCentOS7設置日期和時間方法以及基本概念介紹

    CentOS7設置日期和時間方法以及基本概念介紹

    這篇文章主要介紹了CentOS7設置日期和時間方法以及基本概念介紹,本文講解使用CentOS7中的新命令timedatectl設置日期時間方法,需要的朋友可以參考下 ...

    CentOS之家6522019-09-19
主站蜘蛛池模板: 久久草草影视免费网 | 国产精品视频免费网站 | 一边吃奶一边摸下娇喘 | bt 自拍 另类 综合 欧美 | 羞羞的视频免费 | 亚洲国产在 | 欧美成在线视频 | 久久精品a一级国产免视看成人 | 成人性视频在线 | 精品国产91久久久久久 | 视频在线色 | 久久免费看片 | 久久久久久久久久久久免费 | 全黄性色大片 | 久久草在线观看视频 | 精品成人在线 | 精品国产一区二区三 | 一区二区三区手机在线观看 | 麻豆蜜桃在线观看 | 人成免费网站 | 日本不卡中文字幕 | 久综合| 免费看性xxx高清视频自由 | 久久精品国产99久久久古代 | 99热1| 国产精品久久久不卡 | 日本在线播放一区二区 | 欧洲精品久久 | 思思久而久而蕉人 | 久久大陆 | 成人毛片视频在线观看 | aa国产视频一区二区 | 亚洲国产馆| 欧美一级久久久久久久大片 | 亚洲最新无码中文字幕久久 | 日韩在线视频观看免费 | 国产精品免费观看视频 | 日日操夜夜操视频 | 国产在线精品区 | 日本娇小videos高潮 | 免费黄色小网站 |