百万PV与RabbitMQ

百万PV:

联网下载
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@AndrewZhu ~]# cd /etc/yum.repos.d/
[root@AndrewZhu yum.repos.d]# mv back/* ./
[root@AndrewZhu yum.repos.d]# cd
[root@AndrewZhu ~]# yum install keepalived nginx -y
[root@AndrewZhu ~]# 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 ens32
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
}
}

[root@AndrewZhu ~]# mkdir /opt/shell
[root@AndrewZhu ~]# cd /opt/shell/
[root@AndrewZhu shell]# vi nginx.sh
[root@AndrewZhu shell]# chmod +x nginx.sh
[root@AndrewZhu shell]# vi /etc/nginx/nginx.conf
upstream tomcat_pool { #创建服务器池,地址为tomcat的IP地址
server 192.168.80.104:8080;
server 192.168.80.106:8080;
ip_hash;
}
server {
listen 80;
server_name 192.168.80.188;
location / {
proxy_pass http://tomcat_pool;
proxy_set_header X-Real-IP $remote_addr;
}
}

[root@AndrewZhu shell]# nginx -t -c /etc/nginx/nginx.conf
开启keepalived服务
systemctl start keepalived.service #nginx启动会等待一会

在backup上:
vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
route_id NGINX_HB #route_id主从修改为不同名称(可以不改,主要为了区分)
}

vrrp_script nginx { #定义函数库脚本
script “/opt/shell/nginx.sh” #添加创建脚本
interval 2 #每2s自动执行上面的脚本
}

vrrp_instance VI_1 {
state BACKUP #角色为master,从服务器为backup
interface ens33 #网卡接口为ens32
virtual_router_id 51
priority 90 #当发现虚拟IP不能漂流时,需要重新测试一下优先级
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}

track_script { #调用上面的函数脚本
nginx
}

virtual_ipaddress {
192.168.80.188 #定义VIP(虚拟IP)
}
}

vi /etc/nginx/nginx.conf
upstream tomcat_pool { #创建服务器池,地址为tomcat的IP地址
server 192.168.80.104:8080;
server 192.168.80.106:8080;
ip_hash;
}
server {
listen 80;
server_name 192.168.80.188;
location / {
proxy_pass http://tomcat_pool;
proxy_set_header X-Real-IP $remote_addr;
}
}

mkdir /opt/shell
cd /opt/shell/
vi nginx.sh
#!/bin/bash
A=$(ip addr | grep 192.168.80.188/32 | grep -v grep | wc -l)
if [ $A -gt 0 ]; then
/usr/bin/systemctl start nginx.service #要注意systemctl在什么目录下
else
/usr/bin/systemctl stop nginx.service
fi

systemctl start keepalived

测试keepalived的双机热备功能
关闭主机的Keepalived服务,查看虚拟IP是否可以自动漂移到备机上。

在两台节点服务器上安装Tomcat(配置相同)
解压jdk-8u144-linux-x64.tar.gz和apache-tomcat-8.5.23.tar.gz安装包到/opt/目录下

tar zxvf jdk-8u144-linux-x64.tar.gz -C /opt/
tar zxvf apache-tomcat-8.5.23.tar.gz -C /opt/

把解压后的文件移动到/usr/local目录下并且创建新的目录,方便管理。
cd /opt/
cd -rf jdk1.8.0_144/ /usr/local/java
cd -rf apache-tomcat-8.5.23/ /usr/local/tomcat8

.在/etc/profile配置文件行尾,添加以下内容:
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

source /etc/profile #生效

java -version检查java环境是否安装成功

ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup
ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown

启动tomcat服务并查看其8080端口是否开启
tomcatup
netstat -ntap | grep 8080

修改默认网页内容

cd /usr/local/tomcat8/webapps/ROOT/

vi index.jsp 只要能对两台tomcat进行区别即可
在192.168.80.104上:

在192.168.80.106上:

打开浏览器测试默认测试页是否正常显示

修改/usr/local/tomcat8/conf/server.xml在Host name下新增以下内容:
vi server.xml
找到Host name,在下面新增:
< Context path="" docBase=“SLSaleSystem” reloadable=“true” debug=“0”></ Context>
日志调试信息debug为0表示信息越少,docBase指定访问目录
以上两台tomcat都要做一遍

mysql数据库的安装部署(主从服务器都要部署)
使用yum仓库安装mariadb数据库
这里解释下,mariadb和mysql功能相同,但是安装更轻便,所以这里使用mariadb代替MySQL数据库

yum install -y mariadb-server mariadb
开启mariadb服务,并且加入开启自启动

systemctl start mariadb.service
systemctl enable mariadb.service

mariadb的常规安全设置
mysql_secure_installation

Enter current password for root (enter for none): #回车

Set root password? [Y/n] y 设置用户密码
New password: #abc123
Re-enter new password: #确认密码abc123
Remove anonymous users? 删除匿名用户 n
Disallow root login remotely? 不允许远程root登录吗? n
Remove test database and access to it? 删除测试数据库并访问它? n
Reload privilege tables now? 现在重新加载权限表吗? y
导入会员商城数据库至mariadb数据库

mysql -u root -pabc123 < slsaledb-2014-4-10.sql

登录mysql数据库查看,授权
mysql -u root -pabc123
show databases;

GRANT all ON slsaledb.* TO ‘root’@’%’ IDENTIFIED BY ‘abc123’; #授权
flush privileges; #刷新

在两台tomcat节点修改数据库IP地址是VRRP的虚拟IP,以及授权的用户名root和密码abc123。

tar zxvf SLSaleSystem.tar.gz -C /usr/local/tomcat8/webapps/
cd /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes/

vi jdbc.properties

driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://192.168.80.188:3306/slsaledb?useUnicode=true&characterEncoding=UTF-8
uname=root #用户名
password=abc123 #密码
minIdle=10
maxIdle=50
initialSize=5
maxActive=100
maxWait=100
removeAbandonedTimeout=180
removeAbandoned=true

安装并配置redis主从缓存服务器
yum install -y epel-release
yum install redis -y
vi /etc/redis.conf
bind 0.0.0.0 #61行

从服务器上多如下一行配置
slaveof 192.168.80.188 6379 #主服务器的IP不是虚拟IP(266行)
systemctl start redis.service
netstat -anpt | grep 6379

redis-cli -h 192.168.80.102 -p 6379
set name test #设置name 值是test
get name

redis-cli -h 192.168.80.103 -p 6379
get name

cd /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes/

vi applicationContext-mybatis.xml
<constructor-argvalue=“192.168.80.188”/> #47行
<constructor-argvalue=“6379”/> #48行

redis-cli -h 192.168.80.188 -p 6379
info
keyspace_hits:1 #keyspace_hits:1 或者 keyspace_misses:2//关注这个值,命中数和未命中数

登录商城,然后反复点击需要数据库参与的操作页面,再回来检查keyspace_hits或者keyspace_misses: 值变化。如果keyspace_hits:1 值变为2,说明redis在正常工作。

配置redis集群主从切换—只在主服务器是操作

vi /etc/redis-sentinel.conf
protected-mode no #17行 开启
sentinel monitor mymaster 192.168.80.100 6379 1 #1表示1台从 注意:修改为主IP
sentinel down-after-milliseconds mymaster 3000 #故障切换时间单位是毫秒

启动集群

service redis-sentinel start
netstat -anpt | grep 26379
redis-cli -h 192.168.80.100 -p 26379 info Sentinel #查看集群信息
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.126.138:6379,slaves=1,sentinels=1

验证主从切换

主服务器:
systemctl stop redis.service #关闭主服务器的redis服务
redis-cli -h 192.168.80.100 -p 26379 info Sentinel # Sentinel #发现主切换成从服务器的IP
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168…80.101:6379,slaves=1,sentinels=1

在主从服务器上配置Mysql主从复制

1.首选主库需要开启binlog日志,在打开主库的/etc/my.cnf文件里面增加以下内容:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=1
log_slave_updates=true
sync_binlog=1

在从库中将server_id 换成别的,如2等

2.重启数据库

[root@localhost ~]# systemctl restart mariadb.service
[root@localhost ~]# netstat -ntap | grep 3306

3.登录主库并授权,允许从库的指定用户从主库读取日志。

[root@localhost ~]# mysql -u root -p
MariaDB [(none)]> show master status \G; #记录日志文件名称和 位置值

MariaDB [(none)]> grant replication slave on . to ‘rep’@‘192.168.80.%’ identified by ‘123456’; #授权
MariaDB [(none)]> flush privileges;

3.Mysql从数据库配置

[root@localhost ~]# mysql -u root -p
MariaDB [(none)]> change master to master_host=‘192.168.80.102’,master_user=‘rep’,master_password=‘123456’,master_log_file=‘mysql_bin.000001’,master_log_pos=245;
MariaDB [(none)]> start slave;
riaDB [(none)]> show slave status\G;

4.测试主从同步
在Mysql主服务器上创建一个库,看从服务器上是否能够同步主服务器的新数据库。
主服务器:
MariaDB [(none)]> create database aa;
MariaDB [(none)]> show databases;
从服务器:
MariaDB [(none)]> show databases;

关闭主服务器使用VIP登录tomcat
systemctl stop keepalived.service

浏览器访问http://192.168.80.188
看有没有网页出现,
有,那到此,百万pv完成,没有,检查错误。

千万PV中的RabbitMQ的配置:

1.关闭防火墙及Selinux

setenforce 0
systemctl stop firewalld

2.分别修改三台服务器的主机名
2.1 rabbitmq01服务器
vi /etc/hostname
rabbitmq01

RabbitMQ消息队列集群
2.2 rabbitmq02服务器
vi /etc/hostname
rabbitmq02
2.3 rabbitmq03服务器
vi /etc/hostname
rabbitmq03
3.分别修改三台服务器的hosts文件
vi /etc/hosts
192.168.80.102 rabbitmq01
192.168.80.103 rabbitmq02
192.168.80.104 rabbitmq03
重启电脑(不要忘记防火墙)
4.安装最新repo源
yum -y install epel-release

5.安装rabbitmq-server软件包
yum -y install rabbitmq-server

6.查看已安装的插件
rabbitmq-plugins list

7.启动管理服务
rabbitmq-plugins enable rabbitmq_management

8.分别启动rabbitmq服务
systemctl start rabbitmq-server
rabbitmqctl cluster_status

看到这种状态,就表明rabbitmq服务安装完成,这只是第一台上的图片

rabbitmq集群部署
1.先停止rabbitmq服务
systemctl stop rabbitmq-server

2.进入cookie文件目录
cd /var/lib/rabbitmq/

3.编辑.erlang.cookie文件序列号(各节点需要有相同序列号值)
vi .erlang.cookie

4.再启动rabbitmq服务
systemctl start rabbitmq-server

5.停止rabbitmq应用
rabbitmqctl stop_app #只关闭02、03上的即可

6.将rabbitmq02、rabbitmq03加入rabbitmq01,使它们成为一个集群
rabbitmqctl join_cluster --ram rabbit@rabbitmq01

7.启动rabbitmq应用
rabbitmqctl start_app

8.分别查看rabbitmq服务器状态
rabbitmqctl cluster_status

通过客户端浏览器进行访问RabbitMQ (用户名:guest 密码:guest)
http://192.168.80.102:15672

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值