Version 9 (modified by 15 years ago) ( diff ) | ,
---|
Installation on MySQL
Replacing the simple SQLite database with MySQL allows greater scalability
Notes
- The databases directory contains what web2py knows about your database
- You need to set Migrate=True in
models/00_db.py
before you update the code and switch back to Migrate=False later on. - In case of database mismatches - check the databases directory for the appropriate table ( cat the file ) and change accordingly.
Install Python support for MySQL
apt-get install python-mysqldb
or
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz tar zxvf MySQL-python-1.2.3c1.tar.gz cd MySQL-python-1.2.3c1 python setup.py install
Create the database
Database should be created within MySQL before Web2Py can see it to add the relevant tables:
mysqladmin --user=root -p create sahana mysql -p GRANT USAGE ON sahana.* TO 'sahana'@'localhost' IDENTIFIED BY 'mypassword';
Configure Eden
Suggest to use connection pools to reuse connections in models/00_db.py
:
db=SQLDB('mysql://user:mypassword@hostname/sahana',pools=20)
How many pools?
Whatever you choose, it always starts with one and grows with the number of concurrent requests up to the value of pools (the max number of concurrent pools). So pools should be the max number of concurrent requests you expect. That is the max value of:
<number of requests/second> / <average time per request in seconds>
MySQL optimisation
For Production instances, give the MySQL database plenty of RAM:
innodb_buffer_pool_size = 2048M innodb_file_per_table innodb_thread_concurrency = 8
MySQL Replication
In order to have a backup instance, configure replication from the Master node to a Backup node:
On Master:
pico /etc/mysql/my.cnf #bind-address = 127.0.0.1 server-id = 1 log_bin = /var/log/mysql/mysql-bin.log binlog_do_db = sahana /etc/init.d/mysql restart mysql -u root -p GRANT REPLICATION SLAVE ON sahana.* to username@'sl.av.e.ip' IDENTIFIED BY 'mypassword'; FLUSH PRIVILEGES; SHOW MASTER STATUS;
Read log filename & position for configuring the slave (see below).
On Slave:
pico /etc/mysql/my.cnf server-id = 2 master-host = ma.st.er.ip master-user = username master-password = mypassword master-connect-retry = 60 replicate-do-db = sahana /etc/init.d/mysql restart mysql -u root -p) SLAVE STOP; CHANGE MASTER TO MASTER_HOST='ma.st.er.ip', MASTER_USER='username', MASTER_PASSWORD='mypassword', MASTER_LOG_FILE='log_file', MASTER_LOG_POS=log_position; SLAVE START; crontab -e # m h dom mon dow command 55 * * * * /home/instance/scripts/automysqlbackup 55 * * * * /home/instance/scripts/sync-dir
IP Failover
Can configure the slave to adopt the same IP as the master using a Heartbeat.
If using Slicehost: