寫在前面
html
前面介紹了分發文件管理、前端反向代理與管理後臺服務器的配置操做,今天介紹下前端負載與APP服務器(用戶與商家)、官網、FTP服務器的配置操做前端
安裝所需的依賴包java
yum install pcre-devel zlib-devle openssl-devel gcc-c++ –ylinux
編譯安裝nginxnginx
cd /download/tools/c++
wget http://nginx.org/download/nginx-1.12.1.tar.gzweb
tar zxf nginx-1.12.1.tar.gz apache
cd nginx-1.12.1bootstrap
./configure --prefix=/app/nginx-1.12.1vim
make && make install
[root@centos ~]# cd /app/
[root@centos app]# ln -s nginx-1.12.1 nginx
[root@centos ~]# cd /app/nginx/conf/
[root@centos conf]# mkdir extra
[root@centos conf]# cp nginx.conf nginx.conf.bak
在nginx.conf文件後增長下面的配置
include extra/*.conf;
[root@centos conf]# cd extra/
oot@centos extra]# vim user.app.conf
#
# HTTPS server configuration
#
upstream userapp {
server 10.0.0.4:8080;
server 10.0.0.4:8081;
}
server {
listen 80;
server_name app.mingongge.com;
location / {
proxy_pass http://userapp;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
}
[root@centos conf]# cd extra/
[root@centos conf]# vim sj.app.conf
#
# HTTPS server configuration
#
upstream sjapp {
server 10.0.0.5:8080;
server 10.0.0.5:8081;
}
server {
listen 80;
server_name sjapp.mingongge.com;
location / {
proxy_pass http://sjapp;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
}
}
後端APP服務器JAVA環境安裝配置
[root@centos tools]# ll
total 181168
-rw-r--r-- 1 root root 185515842 Sep 20 15:52 jdk-8u144-linux-x64.tar.gz
[root@centos tools]# tar zxf jdk-8u144-linux-x64.tar.gz -C /usr/local/
[root@centos tools]# ln -s /usr/local/jdk1.8.0_144 /usr/local/jdk
[root@centos tools]# cat >>/etc/profile<<EOF
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
EOF
[root@centos tools]# tail -3 /etc/profile
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.CLASSPATH:/lib/dt.jar:/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
[root@centos tools]# source /etc/profile
[root@centos tools]# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
後端tomcat 配置
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz
[root@centos tools]# tar zxf apache-tomcat-8.5.20.tar.gz -C /usr/local/
[root@centos tools]# ln -s /usr/local/apache-tomcat-8.5.20 /usr/local/tomcat
[root@centos tools]# cd /usr/local/apache-tomcat-8.5.20/conf/
[root@centos conf]# vim server.xml
-------------此處省略N行--------------
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="/www/userapp" debug="0" reloadable="true" crossContext="true" />
#增長上述站點目錄
[root@centos conf]# mkdir /www/userapp -p
echo "this is the frist userapp server" >/www/userapp/index.html
[root@centos conf]# ../bin/startup.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-8.5.20
Using CATALINA_HOME: /usr/local/apache-tomcat-8.5.20
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-8.5.20/temp
Using JRE_HOME: /usr/local/jdk
Using CLASSPATH: /usr/local/apache-tomcat-8.5.20/bin/bootstrap.jar:/usr/local/apache-tomcat-8.5.20/bin/tomcat-juli.jar
Tomcat started.
[root@centos conf]# lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 1587 root 48u IPv6 18137 0t0 TCP *:webcache (LISTEN)
另一臺用戶APP 服務器按上述的配置進行
[root@centos conf]# mkdir /www/userapp -p
echo "this is the second userapp ">/www/userapp/index.html
商家APP環境配置請參考上面的配置
[root@centos conf]# mkdir /www/sjapp -p
echo "this is the frist sjapp ">/www/userapp/index.html
echo "this is the second sjapp ">/www/userapp/index.html
接下來測試下負載均衡
前端負載均衡測試
[root@centos conf]# curl http://10.0.0.1
this is the userapp server
[root@centos conf]# curl http://10.0.0.1
this is the second userapp
[root@centos conf]# curl http://app.mingongge.com
this is the userapp server
[root@centos conf]# curl http://app.mingongge.com
this is the second userapp
[root@centos extra]# curl http://sjapp.mingongge.com
this is the first sjapp server
[root@centos extra]# curl http://sjapp.mingongge.com
this is the second sjapp
瀏覽器訪問測試
本地瀏覽器測試須要配置hosts文件
10.0.0.1 app.mingongge.com
10.0.0.1 sjapp.mingongge.com
基本的架構也是同樣使用反向代理,爲了後期總體架構擴展
Nginx FTP的安裝就再也不描述了,太簡單了,扯多了累
前面反向代理配置以下
[root@centos extra]# vim web.mingongge.conf
#
# HTTPS server configuration
#
server {
listen 80;
server_name www.mingongge.com;
location / {
proxy_pass http://10.0.0.8;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
}
}
[root@centos extra]# vim ftp.mingongge.com
#
# HTTPS server configuration
#
server {
listen 80;
server_name ftp.mingongge.com;
location / {
proxy_pass http://10.0.0.8:88;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
}
}
後端WEB服務器配置
[root@centos html]# vim index.html
welcome to mingongge.s web stie!!!!!!!!!!!!!
[root@centos ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@centos ~]# /usr/local/nginx/sbin/nginx
[root@centos ~]# curl 10.0.0.8
welcome to mingongge.s web stie!!!!!!!!!!!!!
FTP這塊的配置實際上是就是管理後臺經過應用程序上傳圖片,前面用戶經過nginx能訪問到正確的頁面便可,因爲線下測試環境,不可能拿生產代碼來作實驗,所以管理後臺上傳圖片沒法模擬,過程就是後臺上傳圖片是經過FTP的功能上傳到指定的目錄,而後前端經過nginx來調用這個圖片去顯示
所以就配置下訪問圖片便可
[root@centos conf]# cd extra/
[root@centos extra]# vim ftp.mingongge.conf
server {
listen 88;
server_name localhost;
location / {
root /www/ftp;
}
上傳圖片進行測試
經過前端反向代理直接訪問域名來讀取圖,來實現應用程序調用圖片的功能在其它前臺頁面展現的功能
發現也是能夠正常訪問的
寫在最後
這次項目實戰的全部文章,凡是每篇都轉發三個渠道或以上的朋友(轉發後可截圖保存等整個項目文檔發佈結束後發給我),我會在整個項目文檔完成以後將文檔整理髮送給他,而且會抽取其中某篇文章留言點贊前十(需超過20個贊)的朋友,我提供此項目線下測試環境搭建的過程當中全程問題解答!!!!!