Linux 系统集群架构线上项目配置实战 (一)
Linux 系统集群架构线上项目配置实战 (二)
前面介绍了分发文件管理, 前端反向代理与管理后台服务器的配置操作, 今天介绍下前端负载与 App 服务器 (用户与商家), 官网, FTP 服务器的配置操作
1, 前端负载均衡配置
安装所需的依赖包
yum install pcre-devel zlib-devle openssl-devel gcc-c++ -y
编译安装 nginx
- cd /download/tools/
- wget http://nginx.org/download/nginx-1.12.1.tar.gz
- tar zxf nginx-1.12.1.tar.gz
- cd nginx-1.12.1
- ./configure --prefix=/App/nginx-1.12.1
- 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/
- [root@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;
- }
- }
2, 后端 App 服务器配置
后端 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
3, 官网与图片服务器配置
基本的架构也是一样使用反向代理, 为了后期整体架构扩展
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;
- }
上传图片进行测试
通过前端反向代理直接访问域名来读取图, 来实现应用程序调用图片的功能在其它前台页面展示的功能
发现也是可以正常访问的
来源: https://segmentfault.com/a/1190000021580890