百万PV1网站架构

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了百万PV1网站架构相关的知识,希望对你有一定的参考价值。

技术分享图片


主机名IP地址系统版本用途
master192.168.80.181CentOS 7.4前端反向代理主机,redis缓存主机,mysql数据库
backup192.168.80.182CentOS 7.4前端反向代理主机,redis缓存主机,mysql数据库
tomcat-nodel1192.168.80.183CentOS 7.4web服务
tomcat-nodel2192.168.80.184CentOS 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服务器---------

[email protected]

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网站架构的主要内容,如果未能解决你的问题,请参考以下文章

大型网站架构之百万PV

在CentOS7上部署百万PV网站架构

超详解百万PV网站架构案例部署(内附安装包)

大型网站架构

大型网站架构——百万PV网站

大型网站架构之百万PV网站架构案例