总结
我们总是喜欢瞻仰大厂的大神们,但实际上大神也不过凡人,与菜鸟程序员相比,也就多花了几分心思,如果你再不努力,差距也只会越来越大。实际上,作为程序员,丰富自己的知识储备,提升自己的知识深度和广度是很有必要的。
Mybatis源码解析
interval 1
weight 2
}
vrrp_script chk_haproxy {
script “killall -0 haproxy”
interval 1
weight 2
}
vrrp_instance VI_1 {
interface eth0
state MASTER
priority 100
virtual_router_id 125
garp_master_delay 1
authentication {
auth_type PASS
auth_pass 1e3459f77aba4ded
}
track_interface {
eth0
}
virtual_ipaddress {
172.16.25.10/16 dev eth0 label eth0:0
}
track_script {
chk_haproxy
}
notify_master “/etc/keepalived/notify.sh master 172.16.25.10”
notify_backup “/etc/keepalived/notify.sh backup 172.16.25.10”
notify_fault “/etc/keepalived/notify.sh fault 172.16.25.10”
}
vrrp_instance VI_2 {
interface eth0
state BACKUP
priority 99
virtual_router_id 126
garp_master_delay 1
authentication {
auth_type PASS
auth_pass 7615c4b7f518cede
}
track_interface {
eth0
}
virtual_ipaddress {
172.16.25.11/16 dev eth0 label eth0:1
}
track_script {
chk_haproxy
chk_maintaince_down
}
notify_master “/etc/keepalived/notify.sh master 172.16.25.11”
notify_backup “/etc/keepalived/notify.sh backup 172.16.25.11”
notify_fault “/etc/keepalived/notify.sh fault 172.16.25.11”
}
同理修改 172.16.25.110 节点上 keepalived.conf 配置,内容如下:
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from admin@lnmmp.com
smtp_connect_timeout 3
smtp_server 127.0.0.1
router_id LVS_DEVEL
}
vrrp_script chk_maintaince_down {
script “[[ -f /etc/keepalived/down ]] && exit 1 || exit 0”
interval 1
weight 2
}
vrrp_script chk_haproxy {
script “killall -0 haproxy”
interval 1
weight 2
}
vrrp_instance VI_1 {
interface eth0
state BACKUP
priority 99
virtual_router_id 125
garp_master_delay 1
authentication {
auth_type PASS
auth_pass 1e3459f77aba4ded
}
track_interface {
eth0
}
virtual_ipaddress {
172.16.25.10/16 dev eth0 label eth0:0
}
track_script {
chk_haproxy
chk_maintaince_down
}
notify_master “/etc/keepalived/notify.sh master 172.16.25.10”
notify_backup “/etc/keepalived/notify.sh backup 172.16.25.10”
notify_fault “/etc/keepalived/notify.sh fault 172.16.25.10”
}
vrrp_instance VI_2 {
interface eth0
state MASTER
priority 100
virtual_router_id 126
garp_master_delay 1
authentication {
auth_type PASS
auth_pass 7615c4b7f518cede
}
track_interface {
eth0
}
virtual_ipaddress {
172.16.25.11/16 dev eth0 label eth0:1
}
track_script {
chk_haproxy
}
notify_master “/etc/keepalived/notify.sh master 172.16.25.11”
notify_backup “/etc/keepalived/notify.sh backup 172.16.25.11”
notify_fault “/etc/keepalived/notify.sh fault 172.16.25.11”
}
vi /etc/keepalived/notify.sh
#!/bin/bash
Author: Jason.Yu admin@lnmmp.com
description: An example of notify script
contact=‘root@localhost’
notify() {
mailsubject=“hostname
to be $1: $2 floating”
mailbody=“date '+%F %H:%M:%S'
: vrrp transition, hostname
changed to be $1”
echo m a i l b o d y ∣ m a i l − s " mailbody | mail -s " mailbody∣mail−s"mailsubject" $contact
}
case “$1” in
master)
notify master $2
/etc/rc.d/init.d/haproxy restart
exit 0
;;
backup)
notify backup $2 # 在节点切换成backup状态时,无需刻意停止haproxy服务,防止chk_maintaince和chk_haproxy多次对haproxy服务操作;
exit 0
;;
fault)
notify fault $2 # 同上
exit 0
;;
*)
echo ‘Usage: basename $0
{master|backup|fault}’
exit 1
;;
esac
在两个节点上执行 keepalived 启动命令,命令如下:
$ service keepalived start
4、Haproxy部署
在两个节点上都需要执行安装 HAProxy,命令如下:
$ yum -y install haproxy
修改 172.16.25.109 和 172.16.25.110 节点上 haproxy.cfg 文件配置(两节点配置文件内容一致),命令如下:
$ vim /etc/haproxy/haproxy.cfg
配置文件内容如下:
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon # 以后台程序运行;
defaults
mode http # 选择HTTP模式,即可进行7层过滤;
log global
option httplog # 可以得到更加丰富的日志输出;
option dontlognull
option http-server-close # server端可关闭HTTP连接的功能;
option forwardfor except 127.0.0.0/8 # 传递client端的IP地址给server端,并写入“X-Forward_for”首部中;
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 30000
listen stats
mode http
bind 0.0.0.0:1080 # 统计页面绑定1080端口;
stats enable # 开启统计页面功能;
stats hide-version # 隐藏Haproxy版本号;
stats uri /haproxyadmin?stats # 自定义统计页面的访问uri;
stats realm Haproxy\ Statistics # 统计页面密码验证时的提示信息;
stats auth admin:admin # 为统计页面开启登录验证功能;
stats admin if TRUE # 若登录用户验证通过,则赋予管理功能;
frontend http-in
bind *:80
mode http
log global
option httpclose
option logasap
option dontlognull
capture request header Host len 20
capture request header Referer len 60
acl url_static path_beg -i /static /p_w_picpaths /javascript /stylesheets
acl url_static path_end -i .jpg .jpeg .gif .png .css .js .html
use_backend static_servers if url_static # 符合ACL规则的,请求转入后端静态服务器
default_backend dynamic_servers # 默认请求转入后端动态服务器
backend static_servers
balance roundrobin
server imgsrv1 192.168.0.25:80 check maxconn 6000 # 静态服务器,可配置多台,还可设置权重weight;
backend dynamic_servers
balance source # 对于动态请求利用source调度算法,可一定程度上实现session保持;但最好利用cookie绑定的方式实现session保持
server websrv1 192.168.0.35:80 check maxconn 1000 # 动态服务器,可配置多台,还可设置权重weight;
两个节点执行启动服务,命令如下:
$ service haproxy start
5、Nginx部署
yum -y groupinstall “Development tools”
yum -y groupinstall “Server Platform Development”
yum install gcc openssl-devel pcre-devel zlib-devel
groupadd -r nginx
useradd -r -g nginx -s /sbin/nologin -M nginx
tar xf nginx-1.4.7.tar.gz
cd nginx-1.4.7
mkdir -pv /var/tmp/nginx
./configure \
–prefix=/usr \
–sbin-path=/usr/sbin/nginx \
–conf-path=/etc/nginx/nginx.conf \
–error-log-path=/var/log/nginx/error.log \
–http-log-path=/var/log/nginx/access.log \
–pid-path=/var/run/nginx/nginx.pid \
–lock-path=/var/lock/nginx.lock \
–user=nginx \
–group=nginx \
–with-http_ssl_module \
–with-http_flv_module \
–with-http_stub_status_module \
–with-http_gzip_static_module \
–http-client-body-temp-path=/var/tmp/nginx/client/ \
–http-proxy-temp-path=/var/tmp/nginx/proxy/ \
–http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
–http-scgi-temp-path=/var/tmp/nginx/scgi \
–with-pcre
make && make install
配置服务脚本
vi /etc/init.d/nginx # 配置服务脚本
#!/bin/sh
nginx - this script starts and stops the nginx daemon
chkconfig: - 85 15
description: Nginx is an HTTP(S) server, HTTP(S) reverse \
proxy and IMAP/POP3 proxy server
processname: nginx
config: /etc/nginx/nginx.conf
config: /etc/sysconfig/nginx
pidfile: /var/run/nginx.pid
Source function library.
. /etc/rc.d/init.d/functions
Source networking configuration.
. /etc/sysconfig/network
Check that networking is up.
[ “$NETWORKING” = “no” ] && exit 0
nginx=“/usr/sbin/nginx”
prog=$(basename $nginx)
NGINX_CONF_FILE=“/etc/nginx/nginx.conf”
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
make required directories
user=nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -
options=$nginx -V 2>&1 | grep 'configure arguments:'
for opt in $options; do
复习的面试资料
这些面试全部出自大厂面试真题和面试合集当中,小编已经为大家整理完毕(PDF版)
- 第一部分:Java基础-中级-高级
- 第二部分:开源框架(SSM:Spring+SpringMVC+MyBatis)
- 第三部分:性能调优(JVM+MySQL+Tomcat)
- 第四部分:分布式(限流:ZK+Nginx;缓存:Redis+MongoDB+Memcached;通讯:MQ+kafka)
- 第五部分:微服务(SpringBoot+SpringCloud+Dubbo)
- 第六部分:其他:并发编程+设计模式+数据结构与算法+网络
进阶学习笔记pdf
- Java架构进阶之架构筑基篇(Java基础+并发编程+JVM+MySQL+Tomcat+网络+数据结构与算法)
- Java架构进阶之开源框架篇(设计模式+Spring+SpringMVC+MyBatis)
- Java架构进阶之分布式架构篇 (限流(ZK/Nginx)+缓存(Redis/MongoDB/Memcached)+通讯(MQ/kafka))
- Java架构进阶之微服务架构篇(RPC+SpringBoot+SpringCloud+Dubbo+K8s)
715409967090)]
[外链图片转存中…(img-tOteayHt-1715409967090)]
[外链图片转存中…(img-DylPHJie-1715409967090)]
- Java架构进阶之分布式架构篇 (限流(ZK/Nginx)+缓存(Redis/MongoDB/Memcached)+通讯(MQ/kafka))
[外链图片转存中…(img-o2fXBuWt-1715409967091)]
[外链图片转存中…(img-mhlOmQ1E-1715409967091)]
[外链图片转存中…(img-xqXj314E-1715409967091)]
- Java架构进阶之微服务架构篇(RPC+SpringBoot+SpringCloud+Dubbo+K8s)
[外链图片转存中…(img-hL3rFsBF-1715409967092)]
[外链图片转存中…(img-o8vmEULG-1715409967092)]