Skip to main content
  • Create new account
  • Reset your password
张文涛的个人博客
致力于提供Drupal开发,实践等方面的精品资讯

Main navigation

  • 首页
  • 关于
  • Glossary
  • 分享

Breadcrumb

  • Home
  • Drupal高可用坑之表单过期
By admin | 5:24 PM CST, Sat December 17, 2016

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

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

这里列出遇到表单过期的问题问题,并分享解决方法。


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

https://www.drupal.org/node/2241311

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
See
https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_ge...
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.

Add
$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';


Glossary

  • May 2023 (7)
  • March 2023 (1)
  • October 2022 (1)
  • October 2021 (2)
  • August 2021 (4)
  • June 2021 (2)
  • May 2021 (1)
  • April 2021 (2)
  • November 2020 (1)
  • June 2020 (2)
  • December 2019 (2)
  • November 2019 (1)
  • August 2019 (1)
  • February 2018 (1)
  • October 2017 (1)
  • September 2017 (1)
  • July 2017 (1)
  • June 2017 (2)
  • May 2017 (1)
  • March 2017 (3)
  • December 2016 (2)
  • November 2016 (4)
  • October 2016 (3)
  • June 2016 (1)
  • December 2015 (1)
  • November 2015 (6)
  • October 2015 (2)
  • September 2015 (1)
  • August 2015 (1)
  • July 2015 (1)
  • June 2015 (1)
  • May 2015 (1)
  • March 2015 (1)
  • January 2015 (1)
  • December 2014 (3)
  • October 2014 (5)
  • September 2014 (3)
  • August 2014 (1)
  • July 2014 (1)
  • June 2014 (1)
  • May 2014 (1)
  • April 2014 (2)
  • March 2014 (2)
  • February 2014 (2)
  • January 2014 (4)
  • December 2013 (1)
  • March 2013 (2)
  • February 2013 (2)
  • December 2012 (2)
  • November 2012 (4)
  • October 2012 (1)
  • September 2012 (6)
  • August 2012 (15)
  • July 2012 (5)
  • June 2012 (13)
  • May 2012 (9)
  • April 2012 (8)
  • March 2012 (9)
  • February 2012 (3)
  • January 2012 (1)
  • December 2011 (1)
  • November 2011 (6)
  • October 2011 (2)
  • September 2011 (17)
  • August 2011 (4)
  • July 2011 (4)
  • June 2011 (5)
  • May 2011 (4)

Copyright © 2025

苏ICP备14044171号-1