You are here


在Drupal单站点,即一个web server(nginx或者apache),一个数据库,一个缓存服务器的架构下,绝大多数情况下都很完美。

但是对一些Drupal做了高可用,负载均衡等配置;会涉及到两台Web Server服务器,两台数据库服务器(Mysql的Master/Slave)等。这时候有些问题,就会暴露出某些问题。


因为服务器做了高可用,所以有两台Web Server服务器,上面安装了nginx+php-fpm。两台数据库服务器,做了主从配置。

To fix the error message: 'The form has become outdated. ...' try moving the 'drupal_private_key' in to the Drupal 7 settings.php file.

The Issue
drupal_get_private_key() is not a safe function.

When variable_get() doesn't return a $key (some outage, maybe a memcached restarted) you suddenly and silently get assigned a new drupal_get_private_key.

If you are using multiple server Drupal system where each server has it's own MySql database replicated from a Master DB, a Slave DB can end up with it's own key (which Master doesn't see) and when the slave gets it's key cached in memcached the fun begins.

Mean while back in the D7 Admin, forms and menus that once worked start failing!

The Fix
The only safe place in D7 whether using a single or multi-server setup is to move 'drupal_private_key' value to the settings.php file.

$conf['drupal_private_key'] = '...';

To get the value execute on the Staging server (MySql master)
drush ev 'print drupal_get_private_key();'
and assign the value above.

You should have something like this (these are example values, don't use)
$drupal_hash_salt = 'j8lnCx-XF3gq_2NmnnHZ61Q3xlbKHFSzZ9EmUouPwKU';
$conf['drupal_private_key'] = 'Fnll-1ZETTb03CgO6PW4COWT7CjTBeRSAQzXqerq6FA';

Check the hash_salt is behaving correctly (should match $drupal_hash_salt)
drush ev 'print drupal_get_hash_salt();'

Copy these setting to all other servers in the same Drupal cluster.

On Stage update 'drupal_private_key' row with value used in the settings.php file. This will replicate and reset any MySql slaves out of sync.
update variable set value = '[drupal_private_key]' where name = 'drupal_private_key';