이 글에서는 주로 Nginx 로드 스케줄러 + 듀얼 Tomcat 로드 및 세션 공유 + MySQL 백엔드 데이터베이스를 소개합니다. 이제는 필요한 친구들이 참고할 수 있도록 공유합니다.
Nginx 로드 스케줄러+ 듀얼 Tomcat 로드 및 세션 복제 + MySQL 백엔드 데이터베이스
환경:
IP | Function |
---|---|
192.168.2.5 | nginx |
192.1 6 8.2.6 | tomcat1 |
192.168. 2.7 tomcat2 080, 3306, selinux | ② nginx 설치 |
[root@192 ~]# useradd -M -s /sbin/nologin nginx | [root @192 ~]# tar zxf nginx-1.13.9.tar.gz -C /usr/src |
nginx를 시작하지 마세요
③설치용 Tomcat 호스트 두 개jdk从官网下载需要许可,允许之后下载至本地,导入主机 tomcat从官网downloads找到tomcat7.0或者更高版本 wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.86/bin/apache-tomcat-7.0.86.tar.gz[root@192 ~]# tar zxf jdk-7u65-linux -x64.gz -C /usr/src[root@192 ~]# tar zxf apache-tomcat-7.0.54.tar.gz -C /usr/src [root@192 ~]# mv jdk1.7.0_65/ /usr/local/java[root@192 ~]# mv apache-tomcat-7.0.54/ /usr/local/tomcat7[root@192 ~ ]# vim /etc/profile
export JAVA_HOME=/usr/local/java export CATALINA_HOME=/usr/local/tomcat7 export PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH[root@192 ~]# 소스 /etc/profile
[root@192 ~]# java -version
java version "1.8.0_171" Java(TM) SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)[root@192 ~]# catalina.sh 버전
Using CATALINA_BASE: /usr/local/tomcat7 Using CATALINA_HOME: /usr/local/tomcat7 Using CATALINA_TMPDIR: /usr/local/tomcat7/temp Using JRE_HOME: /usr/local/java Using CLASSPATH: /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar Server version: Apache Tomcat/7.0. Server built: May 19 2014 10:26:15 Server number: 7.0.86.0 OS Name: Linux OS Version: 3.10.0-327.el7.x86_64 Architecture: amd64 JVM Version: 1.7.0_65-b17 JVM Vendor: Oracle CorporationTomcat 시작
[root@192 ~] # /usr/local/tomcat7/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat7 Using CATALINA_HOME: /usr/local/tomcat7 Using CATALINA_TMPDIR: /usr/local/tomcat7/temp Using JRE_HOME: /usr/local/java Using CLASSPATH: /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar Tomcat started.
테스트 접속
http://192.168.2.6:8080
http://192.168.2.7:80804두 개의 호스트에서 Tomcat 구성 파일 수정
[root@192 ~]#cd /usr/local/tomcat7/conf
[root@192 ~]#cp server.xml server.xml.bak
[root@192 ~ ]#vim server.xml
....... <engine> <host> <context></context></host></engine>
[root@192 ~]#mkdir -p /web/webapp1
[root@192 ~]#vim /web/webapp1/index.jsp
<title>tomcat-1</title> <h1 id="font-Session-serviced-by-tomcat-font"><font>Session serviced by tomcat</font></h1>
Session ID | |
Create on |
[root@ 192 ~]#shutdown.sh
[ root@192 ~]#startup.sh참고: 두 번째 호스트는 server.xml의 jvmRoute="tomcat-2"와
in index.jsp
http://192.168.2.7 :8008
두 번째, 세션 공유 구성
단계:
①두 호스트가 세션 공유 클러스터 구성
[root@192 ~]#vim /usr/local/tomcat7/conf/server.xml
....... <engine> <!--For clustering, please take a look at documentation at: /docs/cluster-howto.html (simple how to) /docs/config/cluster.html (reference documentation) --> <!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> --> <cluster> <manager></manager> <channel ina.tribes.group.groupchannel> <membership></membership> <receiver></receiver> <sender> <transport></transport> </sender> <interceptor></interceptor> <interceptor></interceptor> </channel> <valve></valve> <valve></valve> <deployer></deployer> <clusterlistener></clusterlistener> <clusterlistener></clusterlistener> </cluster> <!-- Use the LockOutRealm to prevent attempts to guess user passwords via a brute-force attack --> <realm> <!-- This Realm uses the UserDatabase configured in the global JNDI resources under the key "UserDatabase". Any edits that are performed against this UserDatabase are immediately available for use by the Realm. --> <realm></realm> </realm> <host> <context></context></host></engine>[root@192 ~ ]#mkdir /web/webapp1/WEB-INF
[root@192 ~]#cp /usr/local/tomcat7/conf/web.xml WEB-INF/
[root@192 ~]#vim WEB-INF /web.xml<web-app> <distributable></distributable> #添加这个单词,必须有这一步,否则用户的session没法使用</web-app>
방화벽이 켜져 있으면 다음을 활성화하세요
[root@192 ~]#firewall-cmd --add-port=45564/udp --permanent
[root@192 ~]#firewall-cmd --add-port=4000/tcp --permanent
Tomcat 다시 시작
[root@192 ~]#shutdown.sh[root@192 ~]#startup.sh
참고: 두 Tomcat 구성은 동일합니다. 수신자 섹션에서 두 번째 호스트의 IP 주소를 가리키기만 하면 됩니다
②nginx 구성[root@192 ~] #vim /usr/local/nginx/conf/nginx.conf
....... http { ....... upstream tomcat_server { server 192.168.2.6:8080 weight=1; server 192.168.2.7:8080 weight=1; } #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; proxy_pass http://tomcat_server; }nginx를 시작하고 nginx 주소를 방문한 후 페이지를 새로 고쳐 액세스를 테스트하세요
[root@192 ~]#nginxhttp://192.168.2.5
3. mysql 데이터베이스에 연결합니다.
단계:
1mysql을 데이터베이스 서버로 사용하고 mysql을 구성합니다. mysql>다음으로 식별되는 .
에 대한 모든 권한을 부여합니다. '123.com';
mysql> 데이터베이스 생성 javatest
mysql>javatest
사용mysql>테이블 testdata 생성(id int not null auto_increment 기본 키,foo varchar(25),bar varchar(10));
mysql>testdata(foo,bar) 값에 삽입('hello','123.com ')
mysql> testdata에서 * 선택;
②下载mysql-connector-java-5.1.22-bin.jar 复制到tomcat7/lib/目录下(两台tomcat都需要配置)
[root@192 ~]# cp mysql-connector-java-5.1.22-bin.jar /usr/local/tomcat7/lib/
③配置context.xml
[root@192 ~]# cp /usr/local/tomcat7/conf/context.xml /usr/local/tomcat7/conf/context.xml.bak
[root@192 ~]# vim /usr/local/tomcat7/conf/context.xml
<context> <!-- Default set of monitored resources --> <watchedresource>WEB-INF/web.xml</watchedresource> <resource></resource></context>
④配置web.xml
[root@192 ~]# vim /web/webapp1/web.xml
...... <distributable></distributable> <description>MySQL Test App</description> <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/TestDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
⑤编写连接数据库jsp文件
[root@192 ~]# vim /web/webapp1/test.jsp
<title>MySQL</title> connect MySQL<br> foo:"+rs.getString(2)+"bar:"+rs.getString(3)); } rs.close(); stmt.close(); conn.close(); %>
⑥重启tomcat,测试连接
[root@192 ~]# shutdown.sh
[root@192 ~]# startup.sh
http://192.168.2.5/test.jsp
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
위 내용은 Nginx 로드 스케줄러 + 듀얼 Tomcat 로드 및 세션 공유 + MySQL 백엔드 데이터베이스의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

本篇文章给大家带来了关于nginx的相关知识,其中主要介绍了nginx拦截爬虫相关的,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

高并发系统有三把利器:缓存、降级和限流;限流的目的是通过对并发访问/请求进行限速来保护系统,一旦达到限制速率则可以拒绝服务(定向到错误页)、排队等待(秒杀)、降级(返回兜底数据或默认数据);高并发系统常见的限流有:限制总并发数(数据库连接池)、限制瞬时并发数(如nginx的limit_conn模块,用来限制瞬时并发连接数)、限制时间窗口内的平均速率(nginx的limit_req模块,用来限制每秒的平均速率);另外还可以根据网络连接数、网络流量、cpu或内存负载等来限流。1.限流算法最简单粗暴的

实验环境前端nginx:ip192.168.6.242,对后端的wordpress网站做反向代理实现复杂均衡后端nginx:ip192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库1、在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据下面配置192.168.6.205这台服务器vim/etc/rsyncd.confuid=nginxgid=nginxport=873ho

nginx php403错误的解决办法:1、修改文件权限或开启selinux;2、修改php-fpm.conf,加入需要的文件扩展名;3、修改php.ini内容为“cgi.fix_pathinfo = 0”;4、重启php-fpm即可。

跨域是开发中经常会遇到的一个场景,也是面试中经常会讨论的一个问题。掌握常见的跨域解决方案及其背后的原理,不仅可以提高我们的开发效率,还能在面试中表现的更加

nginx部署react刷新404的解决办法:1、修改Nginx配置为“server {listen 80;server_name https://www.xxx.com;location / {root xxx;index index.html index.htm;...}”;2、刷新路由,按当前路径去nginx加载页面即可。

linux版本:64位centos6.4nginx版本:nginx1.8.0php版本:php5.5.28&php5.4.44注意假如php5.5是主版本已经安装在/usr/local/php目录下,那么再安装其他版本的php再指定不同安装目录即可。安装php#wgethttp://cn2.php.net/get/php-5.4.44.tar.gz/from/this/mirror#tarzxvfphp-5.4.44.tar.gz#cdphp-5.4.44#./configure--pr

nginx禁止访问php的方法:1、配置nginx,禁止解析指定目录下的指定程序;2、将“location ~^/images/.*\.(php|php5|sh|pl|py)${deny all...}”语句放置在server标签内即可。


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

드림위버 CS6
시각적 웹 개발 도구

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기
