百万PV1网站架构
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了百万PV1网站架构相关的知识,希望对你有一定的参考价值。
主机名 | IP地址 | 系统版本 | 用途 |
master | 192.168.80.181 | CentOS 7.4 | 前端反向代理主机,redis缓存主机,mysql数据库 |
backup | 192.168.80.182 | CentOS 7.4 | 前端反向代理主机,redis缓存主机,mysql数据库 |
tomcat-nodel1 | 192.168.80.183 | CentOS 7.4 | web服务 |
tomcat-nodel2 | 192.168.80.184 | CentOS 7.4 | web服务 |
一.181 IP master服务器要联网配置:
1.安装带有nginx rpm软件包的源
[[email protected] ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/\
> nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.centos 默认仓库完成下面的安装
[[email protected] ~]# yum install -y keepalived nginx
[[email protected] ~]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
route_id NGINX_HA
}
vrrp_script nginx {
script "/opt/shell/nginx.sh"
interval 2
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
nginx
}
virtual_ipaddress {
192.168.80.188
192.168.0.119
}
}
[[email protected] ~]# mkdir /opt/shell
[[email protected] ~]# vi /opt/shell/nginx.sh
[[email protected] ~]# chmod +x /opt/shell/nginx.sh
3.配置nginx前端调度功能
vi /etc/nginx/nginx.conf
[[email protected] ~]# nginx -t -c /etc/nginx/nginx.conf //测试配置文件语法
二.80.182 IP backup服务器要联网配置:
[[email protected] yum.repos.d]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/\
> nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y keepalived nginx
[[email protected] yum.repos.d]# vi /etc/keepalived/keepalived.conf
mkdir /opt/shell
vi /opt/shell/nginx.sh
#!/bin/bash
k=`ps -ef | grep keepalived | grep -v grep | wc -l`
if [ $k -gt 0 ];then
/bin/systemctl start nginx.service
else
/bin/systemctl stop nginx.service
fi
chmod +x /opt/shell/nginx.sh
[[email protected] yum.repos.d]# mkdir /opt/shell
[[email protected] yum.repos.d]# vi /opt/shell/nginx.sh
[[email protected] yum.repos.d]# chmod +x /opt/shell/nginx.sh
[[email protected] yum.repos.d]# vi /etc/nginx/nginx.conf
[[email protected] yum.repos.d]# nginx -t -c /etc/nginx/nginx.conf
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
三、---------80.184安装web服务器---------
[[email protected] ~]# tar xf apache-tomcat-8.5.23.tar.gz
[[email protected] ~]# tar xf jdk-8u144-linux-x64.tar.gz
cp -rv jdk1.8.0_144/ /usr/local/java
[[email protected] ~]# vi /etc/profile
[[email protected] ~]# source /etc/profile
[[email protected] ~]# 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)
[[email protected] ~]# cp -r apache-tomcat-8.5.23 /usr/local/tomcat8
[[email protected] ~]# ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup
[[email protected] ~]# ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown
[[email protected] ~]# tomcatup
Using CATALINA_BASE: /usr/local/tomcat8
Using CATALINA_HOME: /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME: /usr/local/java/jre
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.
[[email protected] ~]# netstat -anpt | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 1149/java
[[email protected] ~]# vi /usr/local/tomcat8/webapps/ROOT/index.jsp
---------80.185安装web服务器---------
Last login: Thu May 3 05:27:47 2018 from 192.168.80.8
[[email protected] ~]# tar xf apache-tomcat-8.5.23.tar.gz
[[email protected] ~]# tar xf jdk-8u144-linux-x64.tar.gz
cp -rv jdk1.8.0_144/ /usr/local/java
vi /etc/profile
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export PATH=$PATH:/usr/local/java/bin
export CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib
[[email protected] ~]# source /etc/profile
[[email protected] ~]#
[[email protected] ~]# 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)
[[email protected] ~]# cp -r apache-tomcat-8.5.23 /usr/local/tomcat8
[[email protected] ~]# ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup
[[email protected] ~]# ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown
[[email protected] ~]# tomcatup
[[email protected] ~]# netstat -anpt | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 1004/java
http://192.168.80.188/ 输入调度器地址,也就是虚拟地址,测试两台节点的调度情况。
vi /usr/local/tomcat8/webapps/ROOT/index.jsp //修改默认网页内容 <head>下行加
<h1>Server 185!!</h1>
http://192.168.80.188/ 输入调度器地址,也就是虚拟地址,测试两台节点的调度情况。
vi server.xml //跳到行尾,在Host name下新增
<Context path="" docBase="SLSaleSystem" reloadable="true" debug="0"></Context>
四、mysql安装在master and backup服务器上
----使用7.4光盘自带仓库--在主从服务器做------
yum install -y mariadb-server mariadb
[[email protected] ~]# systemctl start mariadb.service
[[email protected] ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[[email protected] ~]#
[[email protected] ~]# netstat -anpt | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 19566/mysqld
[[email protected] ~]#
[[email protected] ~]# mysql_secure_installation
----------导入数据库-----------
mysql -u root -p < slsaledb-2014-4-10.sql
mysql -uroot -p
show databases;
GRANT all ON slsaledb.* TO 'root'@'%' IDENTIFIED BY '123456';
flush privileges;
五、----------------以下在两台tomcat节点web服务器配置----------------
[[email protected] ~]# tar xf SLSaleSystem.tar.gz -C /usr/local/tomcat8/webapps/
[[email protected] ~]# cd /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes
[[email protected] classes]#
[[email protected] classes]# vi jdbc.properties
---------解决虚拟地址不能访问的问题------
cd /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF
vi web.xml
<welcome-file>index.jsp</welcome-file> //修改使用相对路径
cp pages/index.jsp /usr/local/tomcat8/webapps/SLSaleSystem/
http://192.168.80.188/index.jsp //输入虚拟地址测试,并且关闭主再测试
[[email protected] WEB-INF]# tomcatdown
[[email protected] WEB-INF]# tomcatup
六-------------在两台web服务器节点上-------------
[[email protected] WEB-INF]# vi /usr/local/tomcat8/conf/server.xml
route add -net 224.0.0.0 netmask 240.0.0.0 dev ens33 //组播报错解决
netstat -gn
----------在两台节点上做测试页---------注意hosts文件中要有主机名---
vi /usr/local/tomcat8/webapps/SLSaleSystem/test.jsp
SessionID:<%=session.getId()%>
<BR>
SessionPort:<%=request.getServerPort()%>
<%
out.println("This is Tomcate Server 192.168.80.184!");
%>
以上是关于百万PV1网站架构的主要内容,如果未能解决你的问题,请参考以下文章