Wednesday, March 18, 2015

How to setup Solr on Linux machine (1) ?

System Environment
Linux Version: 2.6.32-358.23.2.el6.x86_64
Solr Version: 5.0.0
Postgresql database version: 8.4

Configure a new Core

1. Copy the basic configuration from "/opt/solr-5.0.0/server/solr/configsets/basic_configs" directory to "/opt/solr-5.0.0/server/solr/configsets" directory.

# cd /opt/solr-5.0.0/server/solr/configsets
# cp -rf basic_configs ../
2. Rename the directory as new application name, for example, "myapp".

# cd ..
# mv basic_configs myapp
3. Open the server admin module "http://localhost:8983/solr/", fill in the information

name: myapp
instanceDir: myapp
dataDir: data
config: solrconfig.xml
schema: schema.xml


4. Click on "Add Core" button, new core will be added.

Index data from Postgresql database use data import handler

1. Download Posgresql database driver (postgresql-8.4-703.jdbc4.jar) and place it in "/opt/solr-5.0.0/contrib/dataimporthandler/lib" directory.

2. Make sure jar files as listed below exists in "/opt/solr-5.0.0/dist" directory.
- solr-dataimporthandler-5.0.0.jar
- solr-dataimporthandler-extras-5.0.0.jar

3. To index the data from "booktown" database "books" table, edit solrconfig.xml located at "/opt/solr-5.0.0/server/solr/myapp/conf" directory

<lib dir="/opt/solr-5.0.0/contrib/dataimporthandler/lib" regex=".*\.jar"/>
<lib dir="/opt/solr-5.0.0/dist/" regex="solr-dataimporthandler-.*\.jar"/>
...
...
...
<requesthandler class="org.apache.solr.handler.dataimport.DataImportHandler" name="/dataimport">
 <lst name="defaults">
  <str name="config">db-data-config.xml</str>
 </lst>
</requesthandler>

4.Create db-data-config.xml at  "/opt/solr-5.0.0/server/solr/myapp/conf" directory. Below are sample configuration file.

<dataConfig>
  <dataSource type="JdbcDataSource" 
              driver="org.postgresql.Driver"
              url="jdbc:postgresql://localhost:5432/booktown" 
              user="solr" 
              password="solr"/>
  <document>
    <entity name="books"  
      pk="id"
      query="select id, title from books"
      deltaImportQuery="SELECT id, title from books WHERE id='${dih.delta.id}'"
      >
       <field column="id" name="id"/>
       <field column="title" name="title"/>       
    </entity>
  </document>
</dataConfig>

5. Edit schema.xml located at "/opt/solr-5.0.0/server/solr/myapp/conf".

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
<field name="title" type="text_general" indexed="true" stored="true"/>

6. Open the Solr browser, select "myapp" in the dropdown box. Click on "Data Import" and "Execute" button. Click on "Refresh status" button. Data from Postgresql will be indexed.


7. Click on "Query" menu follow by "Execute Query" button. The search will be displayed.








Tuesday, March 17, 2015

How to setup Solr on Linux machine?

System Environment
Linux Version: 2.6.32-358.23.2.el6.x86_64
Solr Version: 5.0.0

Need to upgrade JDK to version 1.7.0.55 and above for Solr to work

1. Download JDK version 1.7.0_75 (jdk-7u75-linux-x64.tar.gz)
2. Copy jdk-7u75-linux-x64.tar.gz to "/usr/lib" directory
3. Run the command to untar the zip files
tar xzf jdk-7u75-linux-x64.tar.gz
4. Run  the command below to install the JDK
alternatives --install /usr/bin/java java /usr/lib/jdk1.7.0_75/bin/java 2
5. Run the command below to select the java command to use
alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   3           /usr/lib/jdk1.7.0_75/bin/java

Enter to keep the current selection[+], or type selection number: 3
6. Run the command below to install

alternatives --install /usr/bin/jar jar /usr/lib/jdk1.7.0_75/bin/jar 2
alternatives --install /usr/bin/javac javac /usr/lib/jdk1.7.0_75/bin/javac 2
alternatives --set jar /usr/lib/jdk1.7.0_75/bin/jar
alternatives --set javac /usr/lib/jdk1.7.0_75/bin/javac 

Solr Installation

1. Download Solr from Apache website. Note: "solr-5.0.0.tgz" has been downloaded
2. Copy solr-5.0.0.tgz to "/opt" directory
3. Run the command below to unzip the Solr installer
tar zxf solr-5.0.0.tgz
3. Run the command below to start the Solr instance. The default port is 8983
# cd /opt/solr-5.0.0/
# bin/solr start
4. To shutdown the Solr instance, run the command below.
# bin/solr stop

Open Firewall to allow port 8983

1. Run the command below to open port 8983 on the machine
# iptables -I INPUT -p tcp -m tcp --dport 8983 -j ACCEPT
#service iptables save
2. Type the URL (http://[server_address]:8983/) in any browser, Solr admin screen will be displayed.

Monday, November 24, 2014

How to record test script in JMeter and run through command line?

Below are the steps to record test scripts using JMeter

1. First launch your JMeter app, right click on the "Test Plan" node, select "Add" -> "Threads (Users)" -> "Thread Group"


2. Select "Thread Group" node and right click. Select "Add" -> "Config Element" -> "Http Request Default"


3. In "HTTP Request Defaults" page, enter the value in "Server Name or IP" field. For example, "jmeter.apache.org".

Note: If your portal are using SSL, please enter "443" to the port. The "Path" field can leave it as an empty field.


4. Select "Thread Group" node and right click. Select "Add" -> Logic Controller -> "Recording Controller".



5. Select "Workbench" node and right click. Select "Add" -> "Non-Test Elements" -> "HTTP(S) Test Script Recorder".

6. In "URL Patterns to Include" section, add the value ".*\.html".



Note: Make sure "Target Controller" is selected. Should select the the "Recording Controller" that have created in "Test Plan".

7. Select "HTTP(S) Test Script Recorder" and right click. Select "Add" -> "Listener" -> "View Results Tree"


8. Click on the "HTTP(S) Test Script Recorder", click on "Start" button. "Root CA certificate: ApacheJMeterTemporaryRootCA created in JMeter bin directory" message is displayed.

Configure browser to use JMeter proxy

1. Open the "Chrome", click on the "Setting" menu. Click on "Change Proxy Settings" button in the "Network" section.

2. Click on "LAN settings" button, set the value as Address: localhost Port: 8080


3. Open the Chrome browser and type in the command as "http://jmeter.apache.org/", the activity request will be captured at jmeter tools.


4. Make sure the "Recording Controller" consists of the intercept request. Click on "File" -> "Save Test Plan as" to save the test plan in jmx extension.



5. Run the jmeter test script through the command line as described below. Assume the test plan file name is "jmeter.jmx"
jmeter -n -t jmeter.jmx
Install SSL certificate browser to intercept the request

1. When the JMeter tool is started, a temporary SSL certificate "ApacheJMeterTemporaryRootCA.crt" will be generated. It always located at [JMETER_HOME]\bin.

2. Import the certificate "ApacheJMeterTemporaryRootCA.crt" into browser.



Tuesday, October 21, 2014

How to solve pod stop working once upgraded to "OS X Yosemite"?

Once I upgraded my Mac machine to "OS X Yosemite", I execute the command "pod install" to update the library, I encounter the error as showed below

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- xcodeproj/prebuilt/universal.x86_64-darwin14-2.0.0/xcodeproj_ext (LoadError)
 from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.17.0/lib/xcodeproj/ext.rb:6:in `rescue in '
 from /Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.17.0/lib/xcodeproj/ext.rb:3:in `'
 from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.17.0/lib/xcodeproj.rb:30:in `'
 from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/lib/cocoapods.rb:2:in `'
 from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/bin/pod:32:in `'
 from /usr/bin/pod:23:in `load'
 from /usr/bin/pod:23:in `
To resolve the error as described above, uninstall cocoapod, reinstall xcodeproj and cocoapods.

    $ sudo gem uninstall cocoapod 
    $ sudo gem install xcodeproj 
    $ sudo gem install cocoapods

Saturday, October 18, 2014

How to solve WAMP server unable to start due to conflict of port 80?

Stop HTTP.sys server by using the command as described below

- Run command window using administrator rights (Right click "Command Window" icon and click on "Run as administrator" menu)

net stop http /y
sc config http start= disabled

Sunday, July 6, 2014

How to setup Ubuntu on Virtual Box?

Wish to explore Ubuntu but lack of machine to deploy and try. This is really frustrated especially for poor programmer like me who always struggling to upgrade my technical knowledge but not well equipped with neither hardware nor software. Out of disappointment, manage to discover virtual box as other option in setup Ubuntu on top of my Window 7 machine for exploration.

Note: 
1. Assume VirtualBox 4.3.12 has been installed on Window 7. Refer to http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html?ssSourceSiteId=otnjp

2. Assume Ubuntu version 14.04 installer CD is ready.

Create New Virtual Machine


- Click on "New" button, enter the details as described below

Name: Ubuntu
Type: Linux
Version: Ubuntu (32 bit)


- Click on "Next" button, allocate memory size as "1024" MB


- Click on "Next" button, hard drive allocation screen is displayed. Use the default allocation size as 8GB.


- Click on "Create" button, "Hard drive file type" screen will be displayed. Use the default "VDI (VirtualBox Disk Image" file type.


- Click on "Next" button, "Storage on physical hard drive" page is displayed. Select "Dynamically allocated" radio button.


- Click on "Next" button, "File location and size" screen is displayed. Default the name of virtual harddrive as "Ubuntu" and allocate the size limit of the file data on the hard drive as "40GB"


- Click on "Create" button, a new virtual machine is created and is as shown in the screenshot below 


Install Ubuntu

- Click on "Start" button, "Select start-up disk" page is displayed.   


- Make sure the Ubuntu start-up disk is inserted into the "Hard Drive D:". Click on "Start" button. Ubuntu installation screen is displayed.


- After few minutes of loading, the Ubuntu installation screen is displayed.


- Click on "Install Ubuntu" button to kick start the installation."Preparing to install Ubuntu" page is displayed.


- Checked the options below during the installation

1. Download updates while installing
2. Install this third party software

- Click on "Continue" button. "Installation Type" screen is displayed. Use the default setting as shown below. Click on "Install Now" button, the installation kick started. 


- Current location page as shown below is displayed. Select your current location. Click on "Continue" button.


- "Keyboard Layout" page as shown in the screenshot below is displayed. Follow the instruction as prompted in the screen. Once "Continue" button is enabled, click on "Continue" button.


- "Who are you" page as shown in the screenshot below is displayed. Enter all the necessary information. Click on  "Continue" button.


- The installation complete screen as shown in the screenshot below is displayed when the installation completed.


Voila, you will have Ubuntu run on your Window machine once you have restarted your virtualbox.

Friday, June 13, 2014

How to enable your Postgres database accessible by PgAdmin client from other machine remotely?

It is really inconvenience when I found out that I can't connect to my Postgres database (sit in Linux server) remotely through PgAdmin client tools to conduct my troubleshooting works. Even though from security perspective, should turn off the remote access. But, if my PgAdmin client is sitting within the same private network (behind the firewall), I think it is no harm to enable it. The reality is PgAdmin client on Window  is much more user friendly then I use command line tool on Linux.

Step 1 - Edit the Postgres database configuration file to enable remote machine to connect

vi /var/lib/pgsql/data/pg_hba.conf
Add the line as described below:-

host    all         all         [REMOTE MACHINE IP ADDRESS]/24       trust
Step 2 - Enable Postgres database to listen to all the IP address

vi /var/lib/pgsql/data/postgresql.conf
Edit the setting as described below

listen_addresses = '*'
Step 3 - Restart your postgresql database

service postgresql restart
Note: iptables on my Linux box has been turned off. You might want to edit the iptables setting (/etc/sysconfig/iptables) to enable port 5432 for your Linux server

iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d [REMOTE MACHINE IP ADDRESS]  --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s [REMOTE MACHINE IP ADDRESS] --sport 5432 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT

Note: Just in case "/etc/sysconfig/iptables" doesn't exists, maybe due to the first configuration, please type in command "service iptables save". This will save the rules at "/etc/sysconfig/iptables".