Kevin Warrington

Loading clever subtitle...

Installing Solr 4 on CentOS 6

Verify CentOS Version

1
cat /etc/centos-release

Install Tomcat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# install java-1.7.0-openjdk
sudo yum -y install java-1.7.0-openjdk
# install tomcat6
sudo yum -y install tomcat6 tomcat6-webapps tomcat6-admin-webapps
# change port
sudo sed -i s/8080/8983/g /etc/tomcat6/server.xml
# install Simple Logging Facade for Java
wget -qO- http://www.slf4j.org/dist/slf4j-1.7.12.tar.gz | tar xvz
sudo cp -a slf4j-1.7.12/slf4j-*.jar /usr/share/tomcat6/lib
# remove android files that mess up startup
sudo rm -rf /usr/share/tomcat6/lib/slf4j-android*
# install Apache Commons Logging
wget -qO- http://apache.mirror.rafal.ca//commons/logging/binaries/commons-logging-1.2-bin.tar.gz | tar xvz
sudo cp -a commons-logging-1.2/commons-logging-1.2*.jar /usr/share/tomcat6/lib

To use the manager webapp you need to create a user with the role “manager”. Add a user to <tomcat-users> in /etc/tomcat6/tomcat-users.xml

1
2
3
<role rolename="manager" />
<role rolename="admin" />
<user username="admin" password="password" roles="manager,admin" />

Start tomcat

1
sudo service tomcat6 start

Open the Tomcat Web Application Manager

Install Solr

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
wget http://archive.apache.org/dist/lucene/solr/4.6.1/solr-4.6.1.tgz
tar xvf solr-4.6.1.tgz
# install solr app
sudo cp -a solr-4.6.1/dist/solr-4.6.1.war /var/lib/tomcat6/webapps/solr.war
# copy default example config to home, where data will live
sudo cp -a solr-4.6.1/example/solr /home/
# set appropriate permissions
sudo chown -R tomcat:tomcat /home/solr /var/lib/tomcat6/webapps/solr
# update solr home directory in WEB-INF
#    <env-entry>
#       <env-entry-name>solr/home</env-entry-name>
#       <env-entry-value>/home/solr</env-entry-value>
#       <env-entry-type>java.lang.String</env-entry-type>
#    </env-entry>
sudo vim /var/lib/tomcat6/webapps/solr/WEB-INF/web.xml
# restart so tomcat creates directory
sudo service tomcat6 restart

Create a new core

1
2
3
4
5
6
7
8
cd /home/solr
sudo cp -a collection1 document_library
# update core name
echo 'name=document_library' | sudo tee document_library/core.properties
# clean data directory
sudo rm -rf document_library/data
sudo mkdir document_library/data
sudo chown -R tomcat:tomcat document_library

Add drupal solr configuration to new core

1
2
3
sudo cp /vagrant/htdocs/sites/all/modules/apachesolr/solr-conf/solr-4.x/* /home/solr/document_library/conf/
sudo chown -R tomcat:tomcat document_library
sudo service tomcat6 restart

Using Results From the Find Command

The following will find all .patch files and copy them to some directory:

1
find . -name '*.patch' -print0 | xargs -0 -I % cp % some/directory

Explanation

Each result is printed to stdout, followed by an ASCII NUL character -print0. These are passed to xargs which is configured to expect the NUL character -0 as the separator. -I % is used to identify a substitution character, which will be replaced in the following command cp % some/directory.

Find a VirtualBox IP Address on Network

If you’ve recently connected to your VM, it should be in the arp cache.
Query the arp cache looking for a MAC address starting with 8:0:27

1
2
arp -an | grep 8:0:27
# ? (192.168.0.19) at 8:0:27:d:f1:55 on en0 ifscope [ethernet]

If you don’t see it, you need to do a bit more digging.

1
2
3
ifconfig
# en0:
#     inet 192.168.0.10 netmask 0xffffff00 broadcast 192.168.0.255

Since my network has a 192.168.0.10 with a netmask of 255.255.255.0, I can preform a “ping sweep” to count available machines on the network.

1
2
3
nmap -sn 192.168.0.0/24
# or
nmap -sn 192.168.0.*

This is “more reliable than pinging the broadcast address because many hosts do not reply to broadcast queries”.

1
ping 192.168.0.255

Now the arp cache should show the VM, if its running:

1
2
arp -an | grep 8:0:27
# ? (192.168.0.19) at 8:0:27:d:f1:55 on en0 ifscope [ethernet]

You can find more information on the device by preforming an aggressive scan

1
nmap -A -v 192.168.0.19

Setup MySQL With a Launch Agent

Install MySQL using brew:

1
2
3
brew update
brew search mysql
brew install mysql

Add a launch agent for MySQL, which runs on behalf of the current user:

1
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

Start the launch agent now:

1
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Setup PHP With Apache and on the CLI

Install PHP using brew:

1
2
3
brew update
brew search php5
brew install php56

Locate libphp.so

1
2
3
sudo /usr/libexec/locate.updatedb
locate libphp5.so
# /usr/local/Cellar/php56/5.6.5/libexec/apache2/libphp5.so

Tell Apache which PHP shared object .so to use:

1
2
3
4
5
httpd -V | grep ROOT
# -D HTTPD_ROOT="/usr"
vi /etc/apache2/httpd.conf
# this following path is relative to /usr
LoadModule php5_module local/Cellar/php56/5.6.5/libexec/apache2/libphp5.so

Add PHP to your path:

1
2
export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"
php -v

Git Snippets

Sort branches by last commit

1
git for-each-ref --sort=-committerdate --format='%(color:yellow)%(committerdate:short)%(color:reset) %(refname)' refs/heads refs/remotes

Manipulating Unix Routing Tables

For one of our latest projects, we needed to restrict incoming connections on the destination server prior to launching the our website.

So, we had our developers route their traffic through a VPN gateway by adding entries to the routing table:

1
sudo route -nv add IP_DESTINATION IP_GATEWAY

You can verify the route was added by using netstat

1
2
3
4
5
6
netstat -rn
# Routing tables
#
# Internet:
# Destination        Gateway            Flags        Refs      Use   Netif Expire
# IP_DESTINATION     IP_GATEWAY         UGHS            0        0     en0

You can verify the connection is going through the vpn by using traceroute

1
2
3
traceroute IP_DESTINATION
# traceroute to IP_DESTINATION, 64 hops max, 52 byte packets
#  1  IP_GATEWAY  1.586 ms  2.257 ms  0.885 ms

You can remove the route by using the delete option

1
2
sudo route delete IP_DESTINATION
# delete host IP_DESTINATION

How to Flush DNS

WinXP

Start > Run > cmd

ipconfig /flushdns

Win7

Start > Search programs and files > cmd > Right click > Run as administrator

ipconfig /flushdns

Win8

Start Screen > cmd > Right click > Run as administrator

ipconfig /flushdns

IPhone

Simply toggle “Airplane Mode”

MAC OS X 10.7+

sudo killall -HUP mDNSResponder

MAC OS X 10.6

sudo dscacheutil -flushcache

MAC OS X 10.5.1

sudo lookupd -flushcache

Linux

sudo /etc/init.d/nscd restart

SSL Certificate for Localhost

Create a self-signed certificate and move it to the apache conf directory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# generate private key
openssl genrsa -des3 -out server.key 1024

# generate csr
openssl req -new -key server.key -out server.csr

# remove passphrase from private key
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key

# create self-signed cert 
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

# move to apache conf dir
cp server.crt /etc/apache2/server.crt
cp server.key /etc/apache2/server.key

Enable the default ssl configuration, /etc/apache2/httpd.conf

1
2
# uncomment the following line
Include /private/etc/apache2/extra/httpd-ssl.conf

Add host entry for development site, /etc/hosts

1
127.0.0.1 devsite.local

Modify the default virtual host entry, /etc/apache2/extra/httpd-ssl.conf

1
2
3
# update config for site
DocumentRoot "/Library/WebServer/Documents/devsite"
ServerName devsite.local:433

Restart Apache

1
sudo apachectl restart

(Optional) - Add as trusted certificate

1
2
3
4
open /etc/apache2/server.crt

# Always trust for all users
# Always trust when using the certificate

Restart Chrome

Executing Drush Commands Outside of Vagrant Using Aliases

Drush aliases make it possible to run commands from outside your vagrant box, and even outside of your project directory.

To start, you need a ~/.drush/dev.aliases.drushrc.php file:

1
2
3
4
5
6
7
8
9
10
$aliases['project1'] = array(
  'root' => '/vagrant',
  'remote-host' => '10.0.0.124',
  'remote-user' => 'vagrant',
);
$aliases['project2'] = array(
  'root' => '/vagrant',
  'remote-host' => '10.0.0.125',
  'remote-user' => 'vagrant',
);

Next, you need to copy your public key to your vagrant box, the password is vagrant:

1
ssh-copy-id -i ~/.ssh/id_rsa.pub vagrant@10.0.0.124

And finally, test the connection:

1
drush @project1 status

Drush will use your alias configuration to select the appropriate root directory and remote host. You should be able to run the above command from any directory.