CHAPTER ONE LOAD-BALANCING
1.1 Synopsis
In this part, we will explain how to create a load-balancer withnginxfor a lot of OpenERPservers.The
load-balancing
and the
multi-process
mode of OpenERPonly work with gunicorn.And in this case, the cron are not launched by the system.
1.2 Nginx
Nginx is a free, open-source, high-performance HTTP server and reverse proxyYou can copy/paste the code in
/etc/nginx/sites-enabled/
with a filenameYou will find the documentation about the upstream keyword at
http://wiki.nginx.org/HttpUpstreamModule
upstream
openerp_servers{
server
openerp-server1.back.local max_fails=3 fail_timeout=30s;
server
openerp-server2.back.local max_fails=3 fail_timeout=30s;
server
openerp-server3.back.local max_fails=3 fail_timeout=30s;}
serfver
{
listen
80;
server_name
openerp.example.com;
rewrite
^ https://$server_name$request_uri?permanent;}
server
{
listen
443;
server_name
openerp.example.com;
access_log
/var/log/nginx/openerp.example.com-access.log;
error_log
/var/log/nginx/openerp.example.com-error.log debug;
ssl
on;
ssl_certificate
/etc/nginx/ssl/server.crt;
ssl_certificate_key
/etc/nginx/ssl/server.key;
ssl_session_timeout
5m;
ssl_protocols
SSLv3 TLSv1;
ssl_ciphers
ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
ssl_prefer_server_ciphers
on;
location
/{
proxy_pass
http://openerp_servers;
proxy_set_header
Host$http_host;
proxy_set_header
X-Real-IP$remote_addr;
proxy_set_header
X-Forwarded-For$proxy_add_x_forwarded_for;}}
1.3 Gunicorn
Gunicornis a Python WSGI HTTP Server for UNIX.
We will use it for the multi-process mode of OpenERP.On the OpenERP servers, just install gunicorn via apt-get
# apt-get install python-gunicorn
1.4 OpenERP
You should configure OpenERP with the gunicorn mode.In the directory of the server, you can execute gunicorn with the following command
cd/home/openerp/servergunicorn openerp:wsgi.proxied.application -c gunicorn.conf.py
2.1 PostgreSQL
2.1.1 Synopsis
PostgreSQLis a free and open source database server.In this documentation, we will use PostgreSQL 9.x because this is the first release with theStreaming Replication.In PostgreSQL, there are two kind of replication.•
Warm Standby
It’s a simple replication without any access.•
Hot Standby
, in this mode, you can connect to the database but only in read access.We will use the
Hot Standby
mode for the Streaming Replication.In this tutorial, we suppose that you use an unix account, named
openerp
.Firstly, we have to configure two PostgreSQL servers, the master and the slave.
2.1.2 Streaming Replication
Here is the directory structure for the tutorial
root@vm:/# tree homehome|-> openerp|-> postgresql|-> master|-> standbymkdir /home/openerp/postgresql
Master
Via this command we initialize a new PostgreSQL cluster.
cd/home/openerp/postgresql/usr/lib/postgresql/9.1/bin/initdb -D master
The
wal_level
parameter specifies the
hot_standby
mode and the
max_wal_senders
is the number of slaveservers. In this case, the value is one.
cat >> master/postgresql.conf<< _EOF_ > include ’replication.conf’> _EOF_ cat >> master/replication.conf<< _EOF_ > wal_level = ’hot_standby’> max_wal_senders = 1> archive_mode = on> #archive_command = ’cp %p /home/stephane/postgresql/test/archives_xlog/%f’> _EOF_
We start the new PostgreSQL cluster
/usr/lib/postgresql/9.1/bin/pg_ctl -D master start
Authentication
We will use the replication via the network, in this case, we have to configure the PostgreSQL server to use a dedicateduser for the replication. In our case, this is the openerp user. It’s a normal postgresql user, don’t forget to set all therights for this user and a password.
createuser openerppsql -d postgres -c"ALTER USER openerp PASSWORD ’secret’;"
Note:
Here is a part of the content of the
master/pg_hba.conf
file
# The replication database is a virtual database used by the replication processhost replication openerp 127.0.0.1/32 md5
# Don’t forget to restart the master server before the slave because without that, the slave can’t b
/usr/lib/postgresql/9.1/bin/pg_ctl -D master restart
Slave
Tocreateabackupofthemasterfortheslave, youcanusethe
pg_basebackup
commandprovidedwithPostgreSQL9.1.
cd/home/openerp/postgresql/usr/lib/postgresql/9.1/bin/pg_ctl/pg_basebackup -D standby -v -P -Fp -l backup -h 127.0.0.1 -U open
We configure the standby server to listen to the port 5433 (because we are on the same physical server). If the standbyserver is another server, don’t forget to use 5432.
cat > standby/replication.conf<< _EOF_ > port = 5433> hot_standby = on> _EOF_
The
primary_conninfo
is used by the Streaming Replication, the parameter have the hostname of the master withthe port and the pair user/password.
cat > standby/recovery.conf<< _EOF_ > standby_mode = ’on’> primary_conninfo = ’host=127.0.0.1 port=5432 user=openerp password=secret’> trigger_file = ’/tmp/standby’> _EOF_
In this config file, the trigger_file key will be used by the server, if there is a touch on this file, the standby server willautomatically pass in the master mode with the read/write accesses.
2.2 PG-Pool II
For the load-balancing and the failover features, we will use PgPool2.
2.2.1 Installation
# apt-get install pgpool2# apt-get install postgresql-9.1-pgpool2
2.2.2 Configuration
Here is the basic configuration for the load-balancing and the failover.The
failover_command
is important because if pgpool can’t make a connection to the master, it will
touch/tmp/standby
file and this file will be triggered by the standby server.If you want to use this feature with a remote standby server, you can use
ssh
to touch a file on a remote server. Butdon’t forget to change the config file of the standby server and set the right value for the
trigger_file
parameter.
cat >> /etc/pgpool2/pgpool.conf << _EOF_ > port = 5434> load_balance_mode = on> backend_hostname0 = ’localhost’> backend_port0=5432> backend_weight0=1> backend_flag0 = ’ALLOW_TO_FAILOVER’> backend_hostname1 = ’localhost’> backend_port1=5433> backend_weight0=1> backend_flag1 = ’ALLOW_TO_FAILOVER’> failover_command = ’touch /tmp/standby’> _EOF_
CHAPTER ONE LOAD-BALANCING的更多相关文章
- NGINX Load Balancing – TCP and UDP Load Balancer
This chapter describes how to use NGINX Plus and open source NGINX to proxy and load balance TCP and ...
- NGINX Load Balancing - HTTP Load Balancer
This chapter describes how to use NGINX and NGINX Plus as a load balancer. Overview Load balancing a ...
- 【架构】How To Use HAProxy to Set Up MySQL Load Balancing
How To Use HAProxy to Set Up MySQL Load Balancing Dec 2, 2013 MySQL, Scaling, Server Optimization U ...
- CF# Educational Codeforces Round 3 C. Load Balancing
C. Load Balancing time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- UVA 12904 Load Balancing 暴力
Load Balancing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vi ...
- Load Balancing 折半枚举大法好啊
Load Balancing 给出每个学生的学分. 将学生按学分分成四组,使得sigma (sumi-n/4)最小. 算法: 折半枚举 #include <iostrea ...
- [zz] pgpool-II load balancing from FAQ
It seems my pgpool-II does not do load balancing. Why? First of all, pgpool-II' load balancing is &q ...
- How Network Load Balancing Technology Works--reference
http://technet.microsoft.com/en-us/library/cc756878(v=ws.10).aspx In this section Network Load Balan ...
- Network Load Balancing Technical Overview--reference
http://technet.microsoft.com/en-us/library/bb742455.aspx Abstract Network Load Balancing, a clusteri ...
随机推荐
- [BZOJ2553][BeiJing2011]禁忌 dp+AC自动机+矩阵快速幂
2553: [BeiJing2011]禁忌 Time Limit: 20 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 1206 Solved ...
- mongodb复制集搭建
注:mongodb当前版本是3.4.3 1.准备三个虚拟机做服务器 192.168.168.129:27017 192.168.168.130:27017 192.168.168.131:27017 ...
- 一个LaTeX 中文文档的简单而实用的模板
网上找的一个latex中文模板,感觉很简单,在我机器上有点小问题,完善记录一下. %要运行该模板,LaTex需要安装CJK库以支持汉字. %字体大小为12像素,文档类型为article %如果你要写论 ...
- ACM数论-欧几里得与拓展欧几里得算法
欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数. 基本算法:设a=qb+r,其中a,b,q,r都是整数,则gcd(a,b)=gcd(b,r),即gcd(a,b)=gcd(b,a%b). ...
- HDU1213 How Many Tables (并查集)
题目大意: 有一个人要过生日了,请他的朋友来吃饭,但是他的朋友互相认识的才能坐在一起,朋友的编号从1 ~ n,输入的两个数代表着这两个人互相认识(如果1和2认识,2和3认识,那么1和3也就认识了).问 ...
- 23、Flask实战第23天:Flask-Restful
Restful API规范 restful api是用于前端和后台进行通信的一套规范.使用这个规范可以让前后端开发变得更加轻松. 协议 采用http或者https 数据传输格式 数据之间传输的格式应该 ...
- Express处理GET/POST请求(POST请求包含文件)
Express处理GET/POST请求(POST请求包含文件) GET 使用简洁的pug模板引擎,写一个表单,提交方法是GET 前端页面代码 enctype,默认是application/x-www- ...
- [Lydsy1805月赛] 对称数
挺不错的一道数据结构题QWQ. 一开始发现这个题如果不看数据范围的话,妥妥的树上莫队啊23333,然鹅10组数据是不可能让你舒舒服服的树上莫队卡过的23333 于是想了想,这个题的模型就是,把u到v链 ...
- [Contest20171102]简单数据结构题
给一棵$n$个点的数,点权开始为$0$,有$q$次操作,每次操作选择一个点,把周围一圈点点权$+1$,在该操作后你需要输出当前周围一圈点点权的异或和. 由于输出量较大,设第$i$个询问输出为$ans_ ...
- 【母函数】hdu2082 找单词
普通型母函数详解见这里:http://www.wutianqi.com/?p=596 裸题,存个板子. #include<cstdio> #include<cstring> u ...