debian怎么配置静态ip地址
330
2022-11-10
大型网站架构——百万PV
简介
案例描述
本案例设计采用四层模式实现,主要分为前端反向代理,web层,数据库缓存层和数据库层。前端反向代理层采用主备模式,web层采用集群模式,数据库缓存采用主备模式,数据库层采用主从模式。
案例环境
主:192.168.177.145 centos7-1 从:192.168.177.135 centos7-2 节点1:192.168.177.132 centos7-3 节点2:192.168.177.133 centos7-4主服务器 从服务器
安装带有nginx rpm软件包的源
#rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/\ nginx-release-centos-7-0.el7.ngx.noarch.rpm 使用centos 默认仓库完成下面的安装 主 #yum install -y keepalived nginx #vim /etc/keepalived/keepalived.conf //从上修改三个参数 ! Configuration File for keepalived vrrp_script nginx { script "/opt/shell/nginx.sh" interval 2 } //添加 global_defs { route_id NGINX_HA //修改 } 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.177.188 //虚拟IP 192.168.200.188 } } #mkdir /opt/shell #cd /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 //变成可执行的脚本
从服务器与主服务器配置一样(内容要修改)
#yum install -y keepalived nginx #vim /etc/keepalived/keepalived.conf //从上修改三个参数 ! Configuration File for keepalived vrrp_script nginx { script "/opt/shell/nginx.sh" interval 2 } //添加 global_defs { route_id NGINX_HB //修改 } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 52 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } track_script { nginx } virtual_ipaddress { 192.168.177.188 //虚拟IP 192.168.200.188 } } #mkdir /opt/shell #cd /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 //变成可执行的脚本
配置nginx前端调度功能(主,从)
#vim /etc/nginx/nginx.conf //在#gzip on;下面添加: upstream tomcat_pool { server 192.168.177.132:8080; server 192.168.177.133:8080; ip_hash; #会话稳固功能,否则无法通过vip地址登陆 } server { listen 80; server_name 192.168.177.188; #虚拟出的IP location / { proxy_pass http://tomcat_pool; proxy_set_header X-Real-IP $remote_addr; } } #nginx -t -c /etc/nginx/nginx.conf //测试配置文件语法 #systemctl start keepalived.service //nginx启动会等待一会
两台节点都要做tomcat
#tar xf apache-tomcat-8.5.23.tar.gz #tar xf jdk-8u144-linux-x64.tar.gz #mv apache-tomcat-8.5.23/ /usr/local/tomcat8 #mv jdk1.8.0_144/ /usr/local/java #vim /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 大型网站架构之百万PV #ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup #ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown #tomcatup //开启服务 #netstat -anpt | grep 8080
#vim /usr/local/tomcat8/webapps/ROOT/index.jsp //修改默认网页内容 Server 132!!! //测试默认测试页是否正常显示(节点) http://192.168.177.133:8080/ 输入调度器地址,也就是虚拟地址,测试两台节点的调度情况。 将192.168.177.132宕机(tomcatdown),看看133!!!
#vim server.xml //跳到行尾,在Host name下新增 148行
导入数据库
先挂载 #mysql -u root -p < slsaledb-2014-4-10.sql #mysql -u root -p show databases; GRANT all ON slsaledb.* TO 'root'@'%' IDENTIFIED BY 'abc123'; flush privileges; 大型网站架构之百万PV 以下在两台tomcat节点做 #tar xf SLSaleSystem.tar.gz -C /usr/local/tomcat8/webapps/ #cd /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes #vim jdbc.properties //修改数据库IP地址是VRRP的虚拟IP,以及授权的用户名root和密码abc123。 大型网站架构之百万PV 网站测试 //默认的用户名admin 密码:123456 http://192.168.177.133:8080/ //输入虚拟地址测试登录,并且关闭主再测试登录
redis集群(主,从)
#yum install -y epel-release #yum install redis -y #vim /etc/redis.conf bind 0.0.0.0 #systemctl start redis.service #netstat -anpt | grep 6379 #redis-cli -h 192.168.177.145 -p 6379 //测试连接 192.168.177.145:6379> set name test //设置name 值是test 192.168.177.145:6379> get name //获取name值 ``` ## 配置redis集群主从切换,只在主服务器上操作
#redis-cli -h 192.168.177.145 info Replication //获取当前服务器的角色#vim /etc/redis-sentinel.conf17行 protected-mode no17G68行 sentinel monitor mymaster 192.168.177.145 6379 1 //1表示1台从 注意:修改98行 sentinel down-after-milliseconds mymaster 3000 //故障切换时间单位是毫秒#service redis-sentinel start //启动集群#netstat -anpt | grep 26379#redis-cli -h 192.168.177.145 -p 26379 info Sentinel //查看集群信息
## Mysql主从
mysql主服务器配置
#vim /etc/my.cnf //[mysqld]下
binlog-ignore-db=mysql,information_schemacharacter_set_server=utf8log_bin=mysql_binserver_id=1log_slave_updates=truesync_binlog=1
#systemctl restart mariadb#netstat -anpt | grep 3306#mysql -u root -pshow master status; //记录日志文件名称和 位置值grant replication slave on . to 'rep'@'192.168.177.%' identified by '123456';flush privileges;
大型网站架构之百万PVmysql从服务器配置
#vim /etc/my.cnf //[mysqld]下
binlog-ignore-db=mysql,information_schemacharacter_set_server=utf8log_bin=mysql_binserver_id=2log_slave_updates=truesync_binlog=1
#systemctl restart mariadb#netstat -anpt | grep 3306#mysql -u root -p
change master to master_host='192.168.177.145',master_user='rep',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=245;
start slave;
show slave status\G;
Slave_IO_Running: Yes Slave_SQL_Running: Yes
大型网站架构之百万PV
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~