標籤:nginx apache upstream ip_hash svn nfs rpcbind
先上個規劃圖,自己隨便畫的,大家也隨便看看
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/4D/91/wKioL1RTUAeQsDmnAAFAnW_wHjY774.jpg" title="1.png" alt="wKioL1RTUAeQsDmnAAFAnW_wHjY774.jpg" />
192.168.1.119為nginx做反向 Proxy並處理靜態頁面,apache處理動態網頁面,nfs共用網站家目錄,svn代碼管理。
192.168.101為apache處理動態網頁面,掛載192.168.1.119的共用目錄。
192.168.1.96為mysql資料庫,允許兩台web服務的串連許可權。
系統使用centos6.5
一,配置192.168.1.119
1.首先在192.168.1.119上安裝nginx+apache+php+nfs+svn
yum install -y nginx httpd php php-mysql nfs-utils portmap subversion
2.修改nginx設定檔
vim /etc/nginx/nginx.confuser www www;worker_processes auto;error_log /home/wwwlogs/nginx_error.log crit;pid /usr/local/nginx/logs/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 51200;events { use epoll; worker_connections 51200; multi_accept on; }http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; #limit_conn_zone $binary_remote_addr zone=perip:10m; ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section. #log format log_format access ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" $http_x_forwarded_for‘;upstream backend_http { server 192.168.1.101:80; server 127.0.0.1:88;}server { listen 80 default; #listen [::]:80 default ipv6only=on; server_name 192.168.1.119; index index.html index.htm index.php; root /home/wwwroot/repo; access_log logs/access.log combined; #location / { # try_files $uri @apache; # } #location @apache { # internal; # proxy_pass http://127.0.0.1:88; # include proxy.conf; # } location ~ [^/]\.php(/|$) { proxy_pass http://backend_http; include proxy.conf; } location /nginx_status { stub_status on; access_log off; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } access_log /home/wwwlogs/access.log access; }include vhost/*.conf;}檢查設定檔nginx -t啟動服務nginx重新載入配置nginx -s reload
3.修改apache設定檔
vim /etc/httpd/conf/httpd.conf<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /home/wwwroot/repo ServerName 192.168.1.119</VirtualHost>啟動服務service httpd startchkconfig httpd on
4.建立svn倉庫
mkdir /opt/svn && svnadmin create /opt/svn/repo使用密碼認證vim /opt/svn/repo/conf/svnerve.confpassword = 取消這行的注釋添加使用者和密碼echo "charlie = charlie" >> /opt/svn/repo/conf/passwd啟動服務svnserve -d -r /opt/svn取出svn倉庫cd /home/wwwrootsvn co svn://localhost/repo修改svn更新後直接到網站家目錄cd /opt/svn/repo/hookscp post-commit.tmpl post-commitvim post-commitexport LANG=en_CN.UTF-8svn update /home/wwwroot/repo --username charlie --password charlie --no-auth-cache#mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf (此行注釋)添加執行許可權chmod +x post-commit
5.配置共用目錄
vim /etc/exports/home/wwwroot/repo 192.168.1.0/24(sync,rw,no_root_squash)啟動服務/etc/init.d/rpcbind start/etc/init.d/nfs start查看共用目錄exportfs -v載入共用目錄使生效exportfs -r
二,配置192.168.1.101
6.安裝httpd
yum install -y httpd php php-mysql
7.配置apache
vim /etc/httpd/conf/httpd.conf<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /home/wwwroot/repo ServerName 192.168.1.101</VirtualHost>
8.掛載共用目錄
mkdir /home/wwwroot/repo -pvmount -t nfs 192.168.1.119:/home/wwwroot/repo /home/wwwroot/repo
9.啟動服務
service httpd startchkconfig httpd on
三,安裝mysql
10.安裝mysql
yum install -y mysql mysql-server
11.啟動服務
service mysqld startchkconfig mysqld on
12.mysql建立密碼
mysqladmin -uroot -password charlie
13.授權使用者
mysql -uroot -pcharliegrant all on *.* to [email protected]‘192.168.1.%‘ identified by ‘charlie‘;flush privileges;
四,測試網站
14.svn匯出到本地
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4D/92/wKiom1RTVuDjR0CAAAE9-vJnSv4985.jpg" style="float:none;" title="2.png" alt="wKiom1RTVuDjR0CAAAE9-vJnSv4985.jpg" />
建立個測試頁面
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/4D/92/wKioL1RTVzvwBt83AABZGGTMuX0158.jpg" style="float:none;" title="3.png" alt="wKioL1RTVzvwBt83AABZGGTMuX0158.jpg" />
然後訪問測試
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/4D/92/wKiom1RTVuHgwc26AACP9c9ac78718.jpg" style="float:none;" title="4.png" alt="wKiom1RTVuHgwc26AACP9c9ac78718.jpg" />
重新整理後版本不同,證明用戶端請求php頁面會輪詢給後端的apache伺服器。
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/4D/92/wKioL1RTVzuDaaMyAACj7w5g-EY125.jpg" style="float:none;" title="5.png" alt="wKioL1RTVzuDaaMyAACj7w5g-EY125.jpg" />
如果用戶端請求的頁面不能保持會話,會經常切換頁面導致使用者賬戶登入等問題,所以需要更改nginx配置
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/4D/92/wKiom1RTVuHwnx-yAABgjlmiERo615.jpg" style="float:none;" title="6.png" alt="wKiom1RTVuHwnx-yAABgjlmiERo615.jpg" />
添加ip_hash保持會話串連,然後重啟nginx -s reload
再次重新整理頁面不會切換
測試連接資料庫,下面頁面是測試頁
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/4D/92/wKiom1RTVuKQUQccAADIwANIdgM606.jpg" style="float:none;" title="7.png" alt="wKiom1RTVuKQUQccAADIwANIdgM606.jpg" />
添加並確認
到兩台網站伺服器上查看是否存在該檔案,並檢查內容是否一致!
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4D/92/wKioL1RTVz3yWBDnAAEINc8d2c0435.jpg" style="float:none;" title="8.png" alt="wKioL1RTVz3yWBDnAAEINc8d2c0435.jpg" />
然後訪問,證明成功串連後端資料庫
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4D/92/wKiom1RTVuLRT89eAABOsnOUSK8040.jpg" style="float:none;" title="9.png" alt="wKiom1RTVuLRT89eAABOsnOUSK8040.jpg" />
本文出自 “charlie_cen” 部落格,請務必保留此出處http://charlie928.blog.51cto.com/3741218/1570476
nginx做反向 Proxy+apache