centos系统时间定时同步网络时间

yum install -y ntpdate
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yes | cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate cn.pool.ntp.org
crontab -l >/tmp/crontab.bak
echo "*/10 * * * * /usr/sbin/ntpdate cn.pool.ntp.org | logger -t NTP" >> /tmp/crontab.bak
crontab /tmp/crontab.bak

动手做了个IP代理池,定时拨号获取IP。因为拨号间隔较短,需要调用时查看下IP的存活期还剩多少(redis 哈希,set时加一个时间戳,调用时处理下即可):

Field Value
adsl1 user:passwd@ip:port_timestamp

但是调用时总是不对劲,和本地时间做差值和理想的不一样,才发现拨号服务器的本地时间没有同步网络时间,竟然差了23秒!IP存活期才20秒啊。

HAPROXY实现splash负载均衡

本来用了Nginx做了负载均衡,但是看到Nginx只有付费版才支持internal queque,所以用HAproxy重新做了负载均衡。

目的:减轻splash节点的负担并且更好地利用资源(splash重启也不怕!)

HA-Proxy version 1.5.18 2016/05/10。为什么要提版本呢?说多了都是泪,linux上的任何软件都有版本特性,比如崔大神的指南我用在了2.3最新版上就无法启动,原因是新版不用init.d脚本了:

https://cuiqingcai.com/4826.html

而且编译起来很麻烦,最后用了懒人办法 yum install haproxy,只需要写配置文件就可以了:

# HAProxy 1.7 config for Splash. It assumes Splash instances are executed
# on the same machine and connected to HAProxy using Docker links.
global
    # raise it if necessary
    maxconn 512
    # required for stats page
    stats socket /tmp/haproxy

userlist users
    user user insecure-password userpass

defaults
    log global
    mode http

    # remove requests from a queue when clients disconnect;
    # see https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#4.2-option%20abortonclose
    option abortonclose

    # gzip can save quite a lot of traffic with json, html or base64 data
    # compression algo gzip
    compression type text/html text/plain application/json

    # increase these values if you want to
    # allow longer request queues in HAProxy
    timeout connect 3600s
    timeout client 3600s
    timeout server 3600s


# visit 0.0.0.0:8036 to see HAProxy stats page
listen stats
    bind *:8036
    mode http
    stats enable
    stats hide-version
    stats show-legends
    stats show-desc Splash Cluster
    stats uri /
    stats refresh 10s
    stats realm Haproxy\ Statistics
    stats auth    username:password


# Splash Cluster configuration
# 代理服务器监听全局的8050端口
frontend http-in
    bind *:8050
    # 如果你需要开启Splash的访问认证
    # 则注释default_backend splash-cluster
    # 并放开其余default_backend splash-cluster 之上的其余注释
    # 账号密码为user  userpass
    # acl auth_ok http_auth(users)
    # http-request auth realm Splash if !auth_ok
    # http-request allow if auth_ok
    # http-request deny

    # acl staticfiles path_beg /_harviewer/
    # acl misc path / /info /_debug /debug

    # use_backend splash-cluster if auth_ok !staticfiles !misc
    # use_backend splash-misc if auth_ok staticfiles
    # use_backend splash-misc if auth_ok misc
    default_backend splash-cluster


backend splash-cluster
    option httpchk GET /
    balance leastconn

    # try another instance when connection is dropped
    retries 2
    option redispatch
    # 将下面IP地址替换为你自己的Splash服务IP和端口
    # 按照以下格式一次增加其余的Splash服务器
    server splash-0 x.x.x.x:8050 check maxconn 5 inter 2s fall 10 observe layer4
    server splash-1 x.x.x.x:8050 check maxconn 5 inter 2s fall 10 observe layer4

backend splash-misc
    balance roundrobin
    # 将下面IP地址替换为你自己的Splash服务IP和端口
    # 按照以下格式一次增加其余的Splash服务器
    server splash-0 x.x.x.x:8050 check fall 15
    server splash-1 x.x.x.x:8050 check fall 15