本文主要以实例的形式去熟悉sls的部署流程及相关模块的使用

文件下载:https://github.com/unixhot/saltbook-code

目录结构

[root@k8s_master saltbook-code-master]# tree saltstack-haproxy/
saltstack-haproxy/
├── pillar
│ └── base
│ ├── top.sls
│ └── zabbix
│ └── agent.sls
└── salt
├── base
│ ├── init
│ │ ├── audit.sls
│ │ ├── dns.sls
│ │ ├── env_init.sls
│ │ ├── epel.sls
│ │ ├── files
│ │ │ ├── resolv.conf
│ │ │ └── zabbix_agentd.conf
│ │ ├── history.sls
│ │ ├── sysctl.sls
│ │ └── zabbix_agent.sls
│ └── top.sls
└── prod
├── cluster
│ ├── files
│ │ ├── haproxy-outside.cfg
│ │ └── haproxy-outside-keepalived.conf
│ ├── haproxy-outside-keepalived.sls
│ └── haproxy-outside.sls
├── haproxy
│ ├── files
│ │ ├── haproxy-1.5..tar.gz
│ │ └── haproxy.init
│ └── install.sls
├── keepalived
│ ├── files
│ │ ├── keepalived-1.2..tar.gz
│ │ ├── keepalived.init
│ │ └── keepalived.sysconfig
│ └── install.sls
├── libevent
│ ├── files
│ │ └── libevent-2.0.-stable.tar.gz
│ └── install.sls
├── memcached
│ ├── files
│ │ └── memcached-1.4..tar.gz
│ ├── install.sls
│ └── service.sls
├── nginx
│ ├── files
│ │ ├── nginx-1.9..tar.gz
│ │ ├── nginx.conf
│ │ └── nginx-init
│ ├── install.sls
│ └── service.sls
├── pcre
│ ├── files
│ │ └── pcre-8.37.tar.gz
│ └── install.sls
├── php
│ ├── files
│ │ ├── init.d.php-fpm
│ │ ├── memcache-2.2..tgz
│ │ ├── php-5.6..tar.gz
│ │ ├── php-fpm.conf.default
│ │ ├── php.ini-production
│ │ └── redis-2.2..tgz
│ ├── install.sls
│ ├── php-memcache.sls
│ └── php-redis.sls
├── pkg
│ └── pkg-init.sls
├── user
│ └── www.sls
└── web
├── bbs.sls
└── files
└── bbs.conf

目录结构

1)、pillar

[root@k8s_master saltstack-haproxy]# tree pillar/
pillar/
└── base
├── top.sls
└── zabbix
└── agent.sls directories, files [root@k8s_master base]# cat base/top.sls
base:
'*':
- zabbix.agent
[root@k8s_master base]# cat base/zabbix/agent.sls     #配置zabbix server的变量及值
zabbix-agent:
Zabbix_Server: 192.168.56.21

pillar目录结构及文件解析说明

2)、salt(全部目录结构看上面)

[root@k8s_master base]# cat top.sls
base:
'*':
- init.env_init                  ##首先跳到init目录下的环境初始化sls
prod:                           #然后跳到对所有主机安装haproxy 目录下的sls
'*':
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived
- web.bbs
'saltstack-node2.example.com':          #最后对特定主机安装memcache服务
- memcached.service

salt目录结构说明

init目录(入口),初始化环境配置

#目录结构:
[root@k8s_master base]# tree init/
init/
├── audit.sls
├── dns.sls
├── env_init.sls
├── epel.sls
├── files
│   ├── resolv.conf
│   └── zabbix_agentd.conf
├── history.sls
├── sysctl.sls
└── zabbix_agent.sls directory, files

入口sls文件为env_init.sls

[root@k8s_master init]# cat env_init.sls
include:
- init.dns
- init.history
- init.audit
- init.sysctl
- init.epel
- init.zabbix_agent

对初始化环境sls文件进行分析(根据eve_init.sls中的位置依次查看)

dns.sls分析及扩展(涉及模块file.managed)

[root@k8s_master init]# cat dns.sls
/etc/resolv.conf:
file.managed:
- source: salt://init/files/resolv.conf      #表示将source所指目录下的文件覆盖到/etc/resolv.conf(其他写法看下面扩展)
- user: root
- gourp: root
- mode: 644 #file.managed 其他用法(扩展)
[root@k8s_master salt]# cat test.sls
test:                              #随意命名
file.managed:
- name: /tmp/aaa.txt                  #表示将source指定的文件拷贝到/tmp目录,并命名为aaa.txt(此处不能直接写目录)
- source: salt://top.sls
- backup: minion                  #表示先备份在进行source操作
#- source: salt://nginx/nginx.conf #注释的这两行要同时存在,表示以jinja模板引擎进行覆盖(其中nginx.conf里内容可以以pillar,grains变量的内容存在)
#- template: jinja
           
[root@k8s_master salt]# cat /tmp/aaa.txt
base:
'*':
- test
#此处的source还支持从http,https/ftp 上下载,但是需要提供hash值
示例:
tomdroid-src-0.7.3.tar.gz:
file.managed:
- name: /tmp/tomdroid-src-0.7.3.tar.gz       #从source下载到指定目录,并命名
- source: https://launchpad.net/tomdroid/beta/0.7.3/+download/tomdroid-src-0.7.3.tar.gz
- source_hash: https://launchpad.net/tomdroid/beta/0.7.3/+download/tomdroid-src-0.7.3.hash

history.sls(涉及模块file.append)

[root@k8s_master init]# cat history.sls 
/etc/profile:
file.append:                      #将text下内容添加到/etc/profile文件
- text:
- export HISTTIMEFORMAT="%F %T `whoami` " #其他用法(扩展)
/etc/profile:
file.append:
- text: "export ...."          #可直接写成此格式

audit.sls

[root@k8s_master init]# cat audit.sls 
/etc/bashrc:
file.append:
- text:
- export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(whoami):[`pwd`]"$msg"; }'

sysctl.sls(涉及模块sysctl)

[root@k8s_master init]# cat sysctl.sls         #用sysclt内核参数模块,进行内核文件sysctl的配置(格式固定)
net.ipv4.ip_local_port_range:
sysctl.present:
- value: 10000 65000
fs.file-max:
sysctl.present:
- value: 2000000
net.ipv4.ip_forward:
sysctl.present:
- value: 1
vm.swappiness:
sysctl.present:
- value: 0

epel.sls(涉及模块pkg,方法unless)

[root@k8s_master init]# cat epel.sls 
yum_repo_release:
pkg.installed:
- sources:
- epel-release: http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
- unless: rpm -qa | grep epel-release-6-8        #除非结果为真,否则安装(个人理解)

zabbix_agents.sls(涉及模块:pkg,file,service,方法watch,watch_in)

[root@k8s_master init]# cat zabbix_agent.sls 
zabbix-agent:                    #stateID,标签
pkg.installed:                  #pkg模块(状态定义)调用installed函数(函数定义)
- name: zabbix22-agent
file.managed:
- name: /etc/zabbix_agentd.conf
- source: salt://init/files/zabbix_agentd.conf        ##拷贝并覆盖文件(从source指定目录到name指定目录)
- template: jinja                          #使用jinja模板引擎,针对source使用
- defaults:
Server: {{ pillar['zabbix-agent']['Zabbix_Server'] }}
- require:                #require,这里表示在zabbix-agent标签下pkg模块执行成功的情况下执行file模块下的任务(pkg为一个模块,installed为pkg下的一个函数)
- pkg: zabbix-agent
service.running:              
- enable: True             #表示开机自动启动
- watch:                 #watch表示监视 pkg和file函数是否执行成功(是否有变化),如果成功(有变化),则执行running和enable()
- pkg: zabbix-agent
- file: zabbix-agent
zabbix_agentd.conf.d:                #定义又一个stateID,标签
file.directory:                     #调用file的directory函数
- name: /etc/zabbix_agentd.conf.d  
- watch_in:                      #name所指定的目录 应该被zabbix-agent下的service模块变化watch
- service: zabbix-agent
- require:                       #同上面require
- pkg: zabbix-agent
- file: zabbix-agent

files(resolv.conf/zabbix_agentd.conf)(以下配置文件根据实际情况更改

[root@k8s_master files]# cat resolv.conf
; generated by /sbin/dhclient-script
nameserver 202.106.0.20
nameserver 114.114.114.114
[root@k8s_master files]# cat zabbix_agentd.conf |grep -v '^#\|^$'
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server={{pillar['zabbix-agent']['Zabbix_Server']}}  #此处server已经在pillar里设置,直接引用即可,另:这里可以直接写ip,毕竟zabbix-server的数量有限,定义变量也麻烦
ServerActive={{pillar['zabbix-agent']['Zabbix_Server']}}
Hostname={{ grains['ip4_interfaces']['ens33'][0] }}   #这里应该写客户端ip地址或者主机名(通过grains获取),如,这里写的是ipv4网卡名为ens33的ip地址
Include=/etc/zabbix_agentd.conf.d/

主任务线,安装haproxy服务包

继续回到/srv/salt/top.sls

[root@k8s_master base]# cat top.sls
base:
'*':
- init.env_init
prod:
'*':
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived
- web.bbs
'saltstack-node2.example.com':
- memcached.service

进入pod目录,首先调用cluster.haproxy-outside(include)

[root@k8s_master cluster]# cat haproxy-outside.sls
include:      
- haproxy.install                    #首先调用haproxy目录下的install.sls(下面讲解) haproxy-service:
file.managed:
- name: /etc/haproxy/haproxy.cfg
- source: salt://cluster/files/haproxy-outside.cfg      #下面列出
- user: root
- group: root
- mode: 644
service.running:
- name: haproxy
- enable: True
- reload: True               #启用重启
- require:                 #这里表示的是service.running依赖于haproxy目录下install.sls里的haproxy-init标签下的cmd模块以及所调用函数是否执行成功,
- cmd: haproxy-init
- watch:                   #监视 haproxy-service 标签 file模块下配置文件的变动
- file: haproxy-service

cluster/files/haproxy-outside.cfg

[root@k8s_master haproxy]# cat ../cluster/files/haproxy-outside.cfg
global
maxconn
chroot /usr/local/haproxy
uid
gid
daemon
nbproc
pidfile /usr/local/haproxy/logs/haproxy.pid
log 127.0.0.1 local3 info defaults
option http-keep-alive
maxconn
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms listen stats
mode http
bind 0.0.0.0:
stats enable
stats uri /haproxy-status
stats auth haproxy:saltstack frontend frontend_www_example_com
bind 192.168.56.21:
mode http
option httplog
log global
default_backend backend_www_example_com backend backend_www_example_com
option forwardfor header X-REAL-IP
option httpchk HEAD / HTTP/1.0
balance source
server web-node1 192.168.56.21: check inter rise fall
server web-node2 192.168.56.22: check inter rise fall

haproxy.cfg

haproxy目录下的install.sls

[root@k8s_master haproxy]# cat install.sls
include:                      #调用pkg目录下的pkg-init.sls
- pkg.pkg-init
haproxy-install:
file.managed:
- name: /usr/local/src/haproxy-1.5.3.tar.gz
- source: salt://haproxy/files/haproxy-1.5.3.tar.gz
- mode: 755
- user: root
- group: root
cmd.run:
- name: cd /usr/local/src && tar zxf haproxy-1.5.3.tar.gz && cd haproxy-1.5.3 && make TARGET=linux26 PREFIX=/usr/local/haproxy && make install PREFIX=/usr/local/haproxy
- unless: test -d /usr/local/haproxy        #除非haproxy目录存在
- require:                        #依赖于
- pkg: pkg-init
- file: haproxy-install
/etc/init.d/haproxy:
file.managed:
- source: salt://haproxy/files/haproxy.init
- mode: 755
- user: root
- group: root
- require:                        #依赖于haproxy-install 下的cmd模块执行成功
- cmd: haproxy-install
net.ipv4.ip_nonlocal_bind:                 #内核参数设置
sysctl.present:
- value: 1
haproxy-config-dir:
file.directory:                      #默认是创建目录
- name: /etc/haproxy
- mode: 755
- user: root
- group: root
haproxy-init:                        
cmd.run:
- name: chkconfig --add haproxy
- unless: chkconfig --list | grep haproxy
- require:
- file: /etc/init.d/haproxy             #依赖于 标签 /etc/init.d/haproxy 下的file模块执行成功

files/proxy_init

#!/bin/sh

if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit
fi # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ ${NETWORKING} = "no" ] && exit # This is our service name
BASENAME=`basename $`
if [ -L $ ]; then
BASENAME=`find $ -name $BASENAME -printf %l`
BASENAME=`basename $BASENAME`
fi [ -f /etc/$BASENAME/$BASENAME.cfg ] || exit RETVAL= start() {
/usr/local/haproxy/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
if [ $? -ne ]; then
echo "Errors found in configuration file, check it with '$BASENAME check'."
return
fi echo -n "Starting $BASENAME: "
daemon /usr/local/haproxy/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p /var/run/$BASENAME.pid
RETVAL=$?
echo
[ $RETVAL -eq ] && touch /var/lock/subsys/$BASENAME
return $RETVAL
} stop() {
echo -n "Shutting down $BASENAME: "
killproc $BASENAME -USR1
RETVAL=$?
echo
[ $RETVAL -eq ] && rm -f /var/lock/subsys/$BASENAME
[ $RETVAL -eq ] && rm -f /var/run/$BASENAME.pid
return $RETVAL
} restart() {
/usr/local/haproxy/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
if [ $? -ne ]; then
echo "Errors found in configuration file, check it with '$BASENAME check'."
return
fi
stop
start
} reload() {
/usr/local/haproxy/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
if [ $? -ne ]; then
echo "Errors found in configuration file, check it with '$BASENAME check'."
return
fi
/usr/local/haproxy/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p /var/run/$BASENAME.pid -sf $(cat /var/run/$BASENAME.pid)
} check() {
/usr/local/haproxy/sbin/$BASENAME -c -q -V -f /etc/$BASENAME/$BASENAME.cfg
} rhstatus() {
status $BASENAME
} condrestart() {
[ -e /var/lock/subsys/$BASENAME ] && restart || :
} # See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
condrestart
;;
status)
rhstatus
;;
check)
check
;;
*)
echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}"
exit
esac exit $?

haproxy.init

pkg/pkg.sls

[root@k8s_master prod]# cat pkg/pkg-init.sls
pkg-init:
pkg.installed:
- names:
- gcc
- gcc-c++
- glibc
- make
- autoconf
- openssl
- openssl-devel

2.3)主任务线,keepalived包安装及配置

回到top.sls cluster.haproxy-outside-keepalived(claster目录)

[root@k8s_master cluster]# cat haproxy-outside-keepalived.sls
include:                      #首先安装keepalived(下面解释)
- keepalived.install
keepalived-server:                #配置keepalived
file.managed:
- name: /etc/keepalived/keepalived.conf
- source: salt://cluster/files/haproxy-outside-keepalived.conf
- mode: 644
- user: root
- group: root
- template: jinja                             #使用模板引擎
{% if grains['fqdn'] == 'saltstack-node1.example.com' %}      #修改keepalived配置文件
- ROUTEID: haproxy_ha
- STATEID: MASTER
- PRIORITYID: 150
{% elif grains['fqdn'] == 'saltstack-node2.example.com' %}
- ROUTEID: haproxy_ha
- STATEID: BACKUP
- PRIORITYID: 100
{% endif %}
service.running:
- name: keepalived
- enable: True
- watch:                                  #监视 标签keepalive-server的file动作
- file: keepalived-server

文件haproxy-outside-keepalived.conf 模板文件(需要自己定义)

[root@k8s_master files]# cat haproxy-outside-keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
saltstack@example.com
}
notification_email_from keepalived@example.com
smtp_server 127.0.0.1
smtp_connect_timeout
router_id {{ROUTEID}}
} vrrp_instance haproxy_ha {
state {{STATEID}}
interface eth0
virtual_router_id
priority {{PRIORITYID}}
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.56.20
}
}

keepalived/install.sls (安装keepalived)

[root@k8s_master keepalived]# cat install.sls
keepalived-install:
file.managed:
- name: /usr/local/src/keepalived-1.2.17.tar.gz
- source: salt://keepalived/files/keepalived-1.2.17.tar.gz
- mode: 755
- user: root
- group: root
cmd.run:
- name: cd /usr/local/src && tar zxf keepalived-1.2.17.tar.gz && cd keepalived-1.2.17 && ./configure --prefix=/usr/local/keepalived --disable-fwmark && make && make install
- unless: test -d /usr/local/keepalived    #需要目录存在
- require:                  #需要keepalived.tar.gz文件存在
- file: keepalived-install /etc/sysconfig/keepalived:
file.managed:
- source: salt://keepalived/files/keepalived.sysconfig
- mode: 644
- user: root
- group: root /etc/init.d/keepalived:
file.managed:
- source: salt://keepalived/files/keepalived.init
- mode: 755
- user: root
- group: root keepalived-init:
cmd.run:
- name: chkconfig --add keepalived
- unless: chkconfig --list | grep keepalived
- require:
- file: /etc/init.d/keepalived          #需要上面/etc/init.d/keepalived标签下的file状态执行成功 /etc/keepalived:
file.directory:
- user: root
- group: root

keepalived/file/{keepalived.sysconfig,keepalived.init}

[root@k8s_master keepalived]# cat files/keepalived.sysconfig |grep -v "^#\|^$"
KEEPALIVED_OPTIONS="-D"
[root@k8s_master keepalived]# cat files/keepalived.init |grep -v "^#\|^$"
. /etc/rc.d/init.d/functions
. /etc/sysconfig/keepalived
RETVAL=
prog="keepalived"
start() {
echo -n $"Starting $prog: "
daemon /usr/local/keepalived/sbin/keepalived ${KEEPALIVED_OPTIONS}
RETVAL=$?
echo
[ $RETVAL -eq ] && touch /var/lock/subsys/$prog
}
stop() {
echo -n $"Stopping $prog: "
killproc keepalived
RETVAL=$?
echo
[ $RETVAL -eq ] && rm -f /var/lock/subsys/$prog
}
reload() {
echo -n $"Reloading $prog: "
killproc keepalived -
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
status)
status keepalived
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|reload|restart|condrestart|status}"
RETVAL=
esac
exit $RETVAL

安装web服务器,主top.sls下的web.bbs(省略。。太尼玛多了,不过总体也就是这样了)

saltstack SLS 安装haproxy+nginx实例分析学习的更多相关文章

  1. saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived

    saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived 安装配置Keepalived 1.编写功能模块 #创建keepalived目录# mkdir -p ...

  2. saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy

    saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy 下载haproxy1.6.2.tar.gz下载地址:http://www.haproxy.org/download/1. ...

  3. Saltstack sls文件:批量安装服务

    一.使用saltstack 批量安装nginx 1.创建salt目录 mkdir /srv/{salt,pillar} 2.再/srv/salt/下创建sls文件 vim nginx_install. ...

  4. SaltStack自动化安装配置haproxy

    准备环境node1:192.168.217.149 (saltstack master)node2:192.168.217.150(saltstack minion)下载haproxy1.6.2.ta ...

  5. openstack私有云布署实践【4.2 上层代理haproxy+nginx配置 (办公网测试环境)】

    续上一节说明 一开始我也是使用haproxy来做的,但后来方式改了,是因为物理机controller的高配置有些浪费,我需要1组高可用的上层nginx代理服务器来实现其它域名80代理访问,很多办公网测 ...

  6. HAProxy+Nginx 负载均衡

    一.什么是HAProxy HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点, ...

  7. Haproxy Nginx cluster构建

    -----client---------haproxy-------nginx1---------nginx2------192.168.1.250 192.168.1.1 192.168.1.10 ...

  8. linux下安装haproxy作为端口转发服务器,以及安装keepalived作为haproxy高可用方案

    一.安装haproxy作为端口转发服务器(主服务器:172.28.5.4,备服务器:172.28.5.8,浮点IP为:172.28.5.6) 1.安装依赖包 yum -y install wget g ...

  9. SaltStack自动化安装zabbix-server

    使用SaltStack自动化安装zabbix-server 1,设置ntp时间同步 2,安装zabbix-agent 3,安装zabbix-server 4,安装及配置mariadb(mariadb与 ...

随机推荐

  1. [Codeforces261D]Maxim and Increasing Subsequence——树状数组+DP

    题目链接: Codeforces261D 题目大意:$k$次询问,每次给出一个长度为$n$的序列$b$及$b$中的最大值$maxb$,构造出序列$a$为$t$个序列$b$连接而成,求$a$的最长上升子 ...

  2. 微信小程序——安装开发工具和环境【二】

    准备 开发工具下载 获取APPID 安装工具 安装 接受协议 选择安装位置 等待安装完成 安装完成 选择项目 选择小程序 填写信息 确定 无误后,点击确定进入开发页面 建立普通快速启动模板界面

  3. P1280 尼克的任务 dp

    思路: 倒着DP  f[i]表示i时刻的空闲时间最大值 在当前时间没有任务开始 f[i]=f[i+1]+1;    上一分钟最大空闲时间+1 在当前时间有任务开始  f[i]=max(f[i],f[i ...

  4. Hdoj 2289.Cup 题解

    Problem Description The WHU ACM Team has a big cup, with which every member drinks water. Now, we kn ...

  5. 【SPOJ】Power Modulo Inverted(拓展BSGS)

    [SPOJ]Power Modulo Inverted(拓展BSGS) 题面 洛谷 求最小的\(y\) 满足 \[k\equiv x^y(mod\ z)\] 题解 拓展\(BSGS\)模板题 #inc ...

  6. hexo从零开始

    部署Hexo Hexo官方文档 新建一个文件夹,比如,Blog,然后进入该文件夹下: npm install hexo-cli -g hexo version 安装依赖包 npm install 配置 ...

  7. 【原创】tyvj1038 忠诚 & 计蒜客 管家的忠诚 & 线段树(单点更新,区间查询)

    最简单的线段树之一,中文题目,不翻译.... 注释讲的比较少,这已经是最简单的线段树,如果看不懂真的说明最基础的理论没明白 推荐一篇文章http://www.cnblogs.com/liwenchi/ ...

  8. bzoj3796(后缀数组)(SA四连)

    bzoj3796Mushroom追妹纸 题目描述 Mushroom最近看上了一个漂亮妹纸.他选择一种非常经典的手段来表达自己的心意——写情书.考虑到自己的表达能力,Mushroom决定不手写情书.他从 ...

  9. django pymysql

    此处django版本为1.11.13 设置setting.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NA ...

  10. 洛谷P2468 SDOI 2010 粟粟的书架

    题意:给你一个矩形书架,每个点是这本书的页数,每次询问(x1,y1)(x2,y2)这个小矩形里最少需要取几本书使得页数和等于Hi. 题解:小数据二位前缀和预处理+二分答案,大数据一行所以用主席树做,感 ...