Drupal, Memcache and Solr on Windows
-
Upload
alessandro-pilotti -
Category
Technology
-
view
2.842 -
download
3
description
Transcript of Drupal, Memcache and Solr on Windows
Drupal, Memcached and Solr on Windows
Alessandro Pilotti@alexpilotti
MVP ASP.NET / IIS
MCSD, MCAD, MCSE, MCDBA, MCTRed Hat Certified Engineer
Why Memcached?It’s a very popular object caching system
To speed up web sites by offloading work from the DBMS
Simple key / value store with cache invalidation
Low CPU usage
Half client / half server
Servers are unaware of each other (no sync)
Memcached on Windows Memcached supports *nix daemon mode
Ports for Windows exist Most binaries available on the web are old (1.2.x)
The official git repository contains a Windows compatible branch git clone --branch engine-pu https://github.com/memcached/
memcached.git Currently version 1.6.0 beta
Older version 1.3.3 available here: https://github.com/trondn/memcached.git
Building Memcached on Windows is not difficult: http://trondn.blogspot.de/2010/03/building-memcached-windows.html
Build x64 version if you need more than 4GB of memory per instance
Prebuilt binaries: http://www.cloudbasesolutions.com/downloads/memcached_x86_1_3_3.zip http
://www.cloudbasesolutions.com/downloads/memcached_x86_1_6_0_beta1.zip
Installing Memcached on Windows
The best way is to run it as a service
We can use e.g. Apache Procrun to wrap it http://www.apache.org/dist/commons/daemon/binaries/wi
ndows/
For security reasons don’t use an account like Administrator or System to run it!
Open the required firewall port(s) Default: 11211
Limit the client IP range as a best practice
If possible use SASL for authentication
Script 1/2Create user:
net user memcached yourpassword /addwmic path Win32_UserAccount where
Name='memcached' set PasswordExpires=false
Set service rights note: using free Windows 2003 Resource Kitntrights –u memcached +r SeServiceLogonRightntrights –u memcached +r SeBatchLogonRight
Script 2/2Create Windows service using Apache Procrun
prunsrv install memcached --Startup=auto --StartMode=exe
--StartImage="c:\memcached\memcached.exe"
++StartParams=-p;11211;-m;256;-l;127.0.0.1
--ServiceUser=.\memcached --ServicePassword=yourpassword
For remote host access Remove “–l 127.0.0.1” Open firewall port
netsh advfirewall firewall add rule name="memcached" dir=in action=allow protocol=TCP localport=11211
Start service net start memcached
Memcached and PHPIt requires a PECL extension, two are available:
MemcacheWin32 binary: http://downloads.php.net/pierre/
MemcachedMore advanced
Drupal works with both
Memcached protocolMemcache can use an ascii (default) or binary
protocol (faster)
Binary protocol supported from version 1.3
Memcache PECL extension: PHP.INI
memcache.protocol = binary
Memcached PECL extension: Drupal settings.php
$conf['memcache_options'] = array(
Memcached::OPT_BINARY_PROTOCOL => TRUE,
);
Memcached and Drupal 7 drush @Drupal7 dl memcache
In “\sites\all\modules\memcache\dmemcache.inc”: comment //drupal_set_message(t('You must enable the PECL
memcached or memcache extension to use memcache.inc.'), 'error');
drush @Drupal7 -y en memcache_admin
In settings.php $conf['cache_backends'][] =
'sites/all/modules/memcache/memcache.inc'; $conf['cache_default_class'] = 'MemCacheDrupal'; $conf['memcache_key_prefix'] = 'drupal7';
You can now setup separate bins and servers Examples: http://drupal.org/node/1131468
Apache SolrOpen source search platform
Full text searchOptimized for high volume web trafficBased on Apache Lucene
Download version 3.5.0 from:http://www.apache.org/dyn/closer.cgi/lucene/solr
Solr, Windows and Drupal 7
Drupal
drush @Drupal7 dl apachesolr
Expand the content of “example” in “apache-solr-3.5.0.zip“ to e.g. c:\Solr
Move c:\Solr\Solr\Conf folder to c:\Solr\ConfReplace solrconfig.xml and schema.xml and
protwords.txt with copies from: <drupal site>\sites\all\modules\apachesolr\
solr-conf Version 3.x: solrconfig-solr3x.xml schema-solr3x.xml
Create Windows Solr usernet user solr yourpassword /add
wmic path Win32_UserAccount where Name='solr' set PasswordExpires=false
ntrights -u solr +r SeServiceLogonRight
ntrights -u solr +r SeBatchLogonRight
Set proper folder permissions icacls c:\solr /inheritance:d /grant solr:(OI)
(CI)(F) /remove Users
Create Windows service Download and install Java JRE 7
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Using Apache Procrun x64:
prunsrv install solr --Startup=auto --StartMode=jvm ++JvmOptions=-Dsolr.solr.home=C:/solr/;-Djetty.home=C:/solr/;-Djetty.logs=C:/solr/logs/ --ServiceUser=.\solr –ServicePassword=yourpassword --Classpath=C:/solr/lib/*.jar;C:/solr/start.jar --StartClass=org.mortbay.start.Main
Start service Net start solr
Open firewall port if remote access is required netsh advfirewall firewall add rule name="solr" dir=in action=allow
protocol=TCP localport=8983
Setup Drupal 7 Solr searchEnable solr search module:
drush @drupal7 en –y apachesolr_search
http://yourdrupalsite/admin/config/search/settingsSet Apache Solr Search as the only active search
moduleSet Apache Solr Search as the default search module
http://drupal7/admin/config/search/apachesolr/settingsSet your Solr url, e.g.: http://solrserver:8983/solr
Autocommit maxTimeDefault settings is 120s
In Drupal, this means that after your data changes are received by Solr, your search results will not be updated for 2 minutes
To have a shorter delay (e.g. 20s) change maxTime in solrconfig.xml (in ms):
<maxTime>20000</maxTime>
Drupal cronDrupal sends data to Solr for indexing using cron
This might provide big delays between data changes
Download elysia_cron moduledrush @drupal7 dl elysia_crondrush @drupal7 en elysia_cron –y
Set cron scheduling as: Never / Use external crontab
Set apachesolr_cron settings to (e.g. every 2’)*/2 * * * *
“crontab” on Windows Windows uses scheduled tasks instead of crontab
To create a scheduled task for Drupal elysia_cron to run e.g. every 2’:
schtasks.exe /create /tn drupal7_cron /tr "wget -O - -q -t 1 http://drupal7/sites/all/modules/elysia_cron/cron.php?cron_key=yourcronkey" /sc MINUTE /mo 2 /ru solr /rp put wget.exe in the path Get your cron key from:
http://yourdrupalsite/admin/config/system/cron/settings
To run the task once (troubleshooting, etc): schtasks.exe /run /tn drupal7_cron
To delete the task: schtasks.exe /delete /tn drupal7_cron
Drush integration
drush @drupal7 solr-search something
drush @drupal7 solr-index
drush @drupal7 solr-reindex
drush @drupal7 solr-delete-index