标签:ups grant mariadb grep -v img 缓存 eve pool 解释
PV简介PV(Page View,页面浏览量)即点击量,通常意义上说PV的多少是衡量一个网络新闻频道或网站甚至一条网络新闻的主要指标。pv的解释是这样的:一个访问者在24小时(0点-23点)内到底看了网站的几个页面。需要注意的是:同一个人浏览网站的同一个页面,不重复计算pv量,点击100次页只算1次。
本次实验设计采用四层模式实现,主要分为前端反向代理层、web层、数据库缓存层和数据库层。前端反向代理层采用主备模式,web层采用集群模式,数据库缓存层采用主备模式,数据库层采用主从模式。
主机名 | ip地址 | 角色 |
---|---|---|
master | 192.168.0.106 | nginx+keepalived主、redis主、mysql数据主库 |
backup | 192.168.0.115 | nginx+keepalived备、redis备、mysql数据从库 |
web1 | 192.168.0.104 | 后端tomcat服务 |
web2 | 192.168.0.105 | 后端tomcat服务 |
VIP | 192.168.0.188 | 虚拟IP地址 |
systemctl stop firewalld.service
setenforce 0
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y keepalived nginx
rpm -qa | grep mysql
rpm -qa|grep -i mariadb
rpm -qa|grep mariadb|xargs rpm -e --nodeps
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server -y
yum install -y epel-release #更新epel源
yum install redis -y #安装redis
systemctl stop firewalld.service #关闭防火墙
setenforce 0
tar xf jdk-8u101-linux-x64.tar.gz -C /usr/local
cd /usr/local/
mv jdk1.8.0_101 java
sed -i ‘$aJAVA_HOME=/usr/local/java\nCLASSPATH=$JAVA_HOME/lib\nPATH=$PATH:$JAVA_HOME/bin\nexport PATH JAVA_HOME CLASSPATH‘ /etc/profile
source /etc/profile
java -version
tar xvf apache-tomcat-8.5.43.tar.gz -C /usr/local #解压
cd /usr/local
mv apache-tomcat-8.5.43 tomcat #重命名
chmod +x tomcat/bin/* #给脚本授权
ln -s /usr/local/tomcat/bin/startup.sh /usr/bin/tomcatup #建立软连接
ln -s /usr/local/tomcat/bin/shutdown.sh /usr/bin/tomcatdown
vim /etc/keepalived/keepalived.conf #修改三个参数
! Configuration File for keepalived
global_defs {
route_id NGINX_HA #备机要改 NGINX_HB
}
vrrp_script nginx { #nginx监控脚本,后面会创建
script "/opt/shell/nginx.sh"
interval 2
}
vrrp_instance VI_1 {
state MASTER #备机改为BACKUP
interface ens33
virtual_router_id 53 #2台必须一样
priority 100 #优先级,备机要比这个小,如90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
nginx
}
virtual_ipaddress {
192.168.0.188 #虚拟ip地址
}
}
vim /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream tomcatpool {
server 192.168.0.105:8080; #节点服务器1的ip地址,端口号
server 192.168.0.104:8080; #节点服务器2的ip地址,端口号
ip_hash; #会话稳固功能,否则无法通过vip地址登陆
}
server {
listen 80;
server_name 192.168.0.188; #虚拟ip地址
location / {
proxy_pass http://tomcatpool;
proxy_set_header X-Real-IP $remote_addr;
}
}
include /etc/nginx/conf.d/*.conf;
}
mkdir /opt/shell
vim /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 #脚本授权
备注:2.台nginx服务配置,nginx脚本都一样!
配置都没有报错,vip也实现漂移了,但网页打开就是报错,查看nginx日志,也看到不到啥问题
配置完成后,2台都没有出现VIP(虚拟ip)
1.keepalived配置文件不对,2台state必须一主一备,不能都为master
2.2台virtual_router_id必须相同
3.以上2点需要都满足才行
配置没有报错,也看到vip漂移了,在后面使用web服务连接数据库,使用vip地址连接,不能登录网站,只能看到网页。但是,使用数据库真实ip地址就可以登录网页。
vim /etc/my.cnf
在[mysqld]下加入
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=1
log_slave_updates=true
sync_binlog=1
systemctl start mysqld #启动服务
mysql < slsaledb-2014-4-10.sql #导入商城数据
mysql
show databases; #查看数据是否导入
GRANT all ON slsaledb.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘; #slsaledb数据库授权
grant replication slave on *.* to ‘rep‘@‘192.168.0.%‘ identified by ‘123456‘; #从库授权
flush privileges;
show master status;
vim /etc/my.cnf
在[mysqld]下加入
server_id=2
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index
systemctl start mysqld #启动服务
mysql < slsaledb-2014-4-10.sql #导入商城数据
mysql
show databases; #查看数据是否导入
GRANT all ON slsaledb.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘; #slsaledb数据库授权
mysql
change master to master_host=‘192.168.0.106‘,master_user=‘rep‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=406;
start slave;
show slave status \G
tar xf SLSaleSystem.tar.gz -C /usr/local/tomcat/webapps/
vim /usr/local/tomcat/conf/server.xml
在Host name下新增 在149行
#作用是让用户访问时不使用项目名可以直接访问
<Context path="" docBase="SLSaleSystem" reloadable="true" debug="0"></Context>
cd /usr/local/tomcat/webapps/SLSaleSystem/WEB-INF/classes
vim jdbc.properties
driverClassName=com.mysql.jdbc.Driver
#填写虚拟ip地址
url=jdbc\:mysql\://192.168.0.188\:3306/slsaledb?useUnicode\=true&characterEncoding\=UTF-8
#填写授权时的用户名密码
uname=root
password=123456
minIdle=10
maxIdle=50
initialSize=5
maxActive=100
maxWait=100
removeAbandonedTimeout=180
removeAbandoned=true
tomcatup
netstat -ntap |grep 8080
1.先访问2台节点服务器网址
http://192.168.0.104:8080
http://192.168.0.105:8080
2.在访问虚拟IP地址
http://192.168.0.188
vim /etc/redis.conf
在61行修改为
bind 0.0.0.0
systemctl start redis.service #启动服务
netstat -anpt | grep 6379
redis-cli -h 192.168.0.106 -p 6379 #测试连接
192.168.0.106:6379> set name test
OK
192.168.0.106:6379> get name
"test"
192.168.0.106:6379> exit
vi /etc/redis.conf
bind 0.0.0.0 #61行
slaveof 192.168.0.106 6379 #266行,主服务器的IP
systemctl start redis.service #启动服务
redis-cli -h 192.168.0.115 -p 6379 #查看
192.168.0.115:6379> get name
"test" #同步成功
192.168.0.115:6379> exit
配置商城项目中连接redis的参数
vi /usr/local/tomcat/webapps/SLSaleSystem/WEB-INF/classes/applicationContext-mybatis.xml
#填写虚拟IP地址,47行
<constructor-arg value="192.168.0.188"/>
<constructor-arg value="6379"/>
tomcatdown
tomcatup
redis-cli -h 192.168.0.188 -p 6379
192.168.0.188:6379> info
只在主服务器是操作
redis-cli -h 192.168.0.106 info Replication #获取当前服务器的角色
vim /etc/redis-sentinel.conf
protected-mode no #17 行
sentinel monitor mymaster 192.168.200.128 6379 1 #69行,1表示1台备机
sentinel down-after-milliseconds mymaster 3000 #98行,故障切换时间单位是毫秒
service redis-sentinel start #启动集群
netstat -anpt | grep 26379
redis-cli -h 192.168.0.106 -p 26379 info Sentinel #查看集群信息
在主服务器上(master)
systemctl stop redis.service
redis-cli -h 192.168.0.106 -p 26379 info Sentinel #查看集群信息
关掉所有主服务器(master)和一台tomcat服务(we1)
查看网页: http://192.168.0.188
标签:ups grant mariadb grep -v img 缓存 eve pool 解释
原文地址:https://blog.51cto.com/13760351/2473404