wtorek, 22 kwietnia 2014

SSL certificate: DER, PEM and error 20

I had an SSL certificate in a https server, but whenever I connected to this my site, I saw certificate error. First I check that my certificate is in DER form which is not accepted by my server. I have to convert it to PEM :
root@prod:~/cert# openssl x509 -in my_cert.cer -out my_cert.pem -inform DER -outform PEM
Than I saw that I have stil problems with certificate
root@prod:~/cert# openssl verify my_cert.pem: [details removed] error 20 at 0 depth lookup:unable to get local issuer certificate
I googled and found that I should get issuer certificate and combine it with my certificate. I downloaded issuer certificate in DER format and converted it to PEM.
root@prod:~/cert# openssl x509 -in l4.cer -out l4.pem -inform DER -outform PEM
Than I checked if everything is OK:
root@prod:~/cert# openssl verify -CAfile l4.pem my_cert.pem: OK
Final step was combined my_cert.pem with l4.pem :
root@prod:~/cert# cat my_cert.pem l4.pem >> my_cert.crt
I copied my_cert.crt and my_cert.key to /etc/ssl/ and configured my nginx to use it. No more certificate error.

piątek, 11 kwietnia 2014

Solr configure logging to file

First download solr and commons-logging:
root@testing:# wget http://ftp.ps.pl/pub/apache/lucene/solr/4.7.1/solr-4.7.1.tgz root@testing:# wget http://ftp.piotrkosoft.net/pub/mirrors/ftp.apache.org//commons/logging/binaries/commons-logging-1.1.3-bin.tar.gz
Unpack both.
root@testing:# tar -zxf solr-4.7.1.tgz root@testing:# tar -zxf commons-logging-1.1.3-bin.tar.gz
Copy solr-4.7.1.war to temp directory i.e:
root@testing:# mkdir tmp root@testing:# cd tmp root@testing:tmp# cp ../solr-4.7.1/dist/solr-4.7.1.war .
Unpack solr*.war
root@testing:tmp# jar -xf solr-4.7.1.war
Copy from solr-4.7.1 log4j*.jar and slf4j*.jar to WEB-INF/lib/
root@testing:tmp# cp ../solr-4.7.1/example/lib/ext/{log4j-1.2.16.jar,slf4j*} WEB-INF/lib/
Copy from commons-logging commons-logging*.jar :
root@testing:tmp# cp ../commons-logging-1.1.3/commons-logging-1.1.3.jar WEB-INF/lib/
Create directory classess in WEB-INF/
root@testing:tmp# mkdir WEB-INF/classes
Copy from solr*/example/resources/ log4j.properties to WEB-INF/classes
root@testing:tmp# cp ../solr-4.7.1/example/resources/log4j.properties WEB-INF/classes/ root@testing:tmp# cat WEB-INF/classes/log4j.properties # Logging level solr.log=/var/log/solr log4j.rootLogger=INFO, file, CONSOLE log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x \u2013 %m%n #- size rotation with log cleanup. log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.MaxFileSize=4MB log4j.appender.file.MaxBackupIndex=9 #- File to log to and log format log4j.appender.file.File=${solr.log}/solr.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%-5p - %d{yyyy-MM-dd HH:mm:ss.SSS}; %C; %m\n log4j.logger.org.apache.zookeeper=WARN log4j.logger.org.apache.hadoop=WARN # set to INFO to enable infostream log messages log4j.logger.org.apache.solr.update.LoggingInfoStream=OFF
Create log directory which configured in log4j.properties and change owner to user which running tomcat
root@testing:tmp# mkdir /var/log/solr root@testing:tmp# chown tomcat7:tomcat7 /var/log/solr
Pack everything back to solr*.war
root@testing:tmp# jar -cf solr-4.7.1.war META-INF WEB-INF admin.html css favicon.ico img js tpl
If everything is OK you should enjoy logs in log directory:
root@testing:tmp# cat /var/log/solr/solr.log INFO - 2014-04-11 12:23:58.890; org.apache.solr.servlet.SolrDispatchFilter; SolrDispatchFilter.init() INFO - 2014-04-11 12:23:58.916; org.apache.solr.core.SolrResourceLoader; Using JNDI solr.home: /srv/solr INFO - 2014-04-11 12:23:58.919; org.apache.solr.core.SolrResourceLoader; new SolrResourceLoader for directory: '/srv/solr/' INFO - 2014-04-11 12:23:59.145; org.apache.solr.core.ConfigSolr; Loading container configuration from /srv/solr/solr.xml INFO - 2014-04-11 12:23:59.358; org.apache.solr.core.CorePropertiesLocator; Config-defined core root directory: /srv/solr INFO - 2014-04-11 12:23:59.372; org.apache.solr.core.CoreContainer; New CoreContainer 1409622974 INFO - 2014-04-11 12:23:59.372; org.apache.solr.core.CoreContainer; Loading cores into CoreContainer [instanceDir=/srv/solr/] INFO - 2014-04-11 12:23:59.398; org.apache.solr.handler.component.HttpShardHandlerFactory; Setting socketTimeout to: 0 INFO - 2014-04-11 12:23:59.398; org.apache.solr.handler.component.HttpShardHandlerFactory; Setting urlScheme to: null INFO - 2014-04-11 12:23:59.406; org.apache.solr.handler.component.HttpShardHandlerFactory; Setting connTimeout to: 0 INFO - 2014-04-11 12:23:59.406; org.apache.solr.handler.component.HttpShardHandlerFactory; Setting maxConnectionsPerHost to: 20 INFO - 2014-04-11 12:23:59.406; org.apache.solr.handler.component.HttpShardHandlerFactory; Setting corePoolSize to: 0 INFO - 2014-04-11 12:23:59.407; org.apache.solr.handler.component.HttpShardHandlerFactory; Setting maximumPoolSize to: 2147483647 INFO - 2014-04-11 12:23:59.407; org.apache.solr.handler.component.HttpShardHandlerFactory; Setting maxThreadIdleTime to: 5 INFO - 2014-04-11 12:23:59.407; org.apache.solr.handler.component.HttpShardHandlerFactory; Setting sizeOfQueue to: -1 INFO - 2014-04-11 12:23:59.407; org.apache.solr.handler.component.HttpShardHandlerFactory; Setting fairnessPolicy to: false INFO - 2014-04-11 12:23:59.588; org.apache.solr.logging.LogWatcher; SLF4J impl is org.slf4j.impl.Log4jLoggerFactory INFO - 2014-04-11 12:23:59.589; org.apache.solr.logging.LogWatcher; Registering Log Listener [Log4j (org.slf4j.impl.Log4jLoggerFactory)] INFO - 2014-04-11 12:23:59.591; org.apache.solr.core.CoreContainer; Host Name: INFO - 2014-04-11 12:23:59.677; org.apache.solr.core.CorePropertiesLocator; Looking for core definitions underneath /srv/solr INFO - 2014-04-11 12:23:59.678; org.apache.solr.core.CorePropertiesLocator; Found 0 core definitions INFO - 2014-04-11 12:23:59.680; org.apache.solr.servlet.SolrDispatchFilter; user.dir=/var/lib/tomcat7 INFO - 2014-04-11 12:23:59.680; org.apache.solr.servlet.SolrDispatchFilter; SolrDispatchFilter.init() done INFO - 2014-04-11 12:24:15.866; org.apache.solr.servlet.SolrDispatchFilter; [admin] webapp=null path=/admin/cores params={indexInfo=false&_=1397211686406&wt=json} status=0 QTime=69 INFO - 2014-04-11 12:24:15.941; org.apache.solr.servlet.SolrDispatchFilter; [admin] webapp=null path=/admin/info/system params={_=1397211686554&wt=json} status=0 QTime=16 INFO - 2014-04-11 12:24:20.785; org.apache.solr.servlet.SolrDispatchFilter; [admin] webapp=null path=/admin/info/logging params={_=1397211691410&since=0&wt=json} status=0 QTime=2 INFO - 2014-04-11 12:24:22.578; org.apache.solr.servlet.SolrDispatchFilter; [admin] webapp=null path=/admin/cores params={_=1397211693200&wt=json} status=0 QTime=0 INFO - 2014-04-11 12:24:24.230; org.apache.solr.servlet.SolrDispatchFilter; [admin] webapp=null path=/admin/info/properties params={_=1397211694858&wt=json} status=0 QTime=1

piątek, 21 marca 2014

Packt’s amazing Buy One, Get One Free

Check out #Packt’s amazing Buy One, Get One Free offer #Packt2k

piątek, 17 stycznia 2014

Secure web directory with exclude

Last time I needed to secure on of my websites. I set password, used htaccess and ...I got error on my main page. The reason was simple - main page invoked to file in my secure directory. I needed to exclude this file from my secure directory. Below is solution.
# password protection allowing multiple resources AuthType Basic AuthName "Restricted Area" AuthUserFile /home/path/.htpasswd AuthGroupFile /dev/null Require valid-user # allow public access to the following resources SetEnvIf Request_URI "(path/to/directory_01/)$" allow SetEnvIf Request_URI "(path/to/directory_02/)$" allow SetEnvIf Request_URI "(path/to/file\.php)$" allow SetEnvIf Request_URI "(path/to/file\.html)$" allow SetEnvIf Request_URI "(path/to/another/resource/)$" allow SetEnvIf Request_URI "(path/to/yet/another/resource/)$" allow Order allow,deny Allow from env=allow Satisfy any
Of course you can also use "Allow from " to limiting access to secure directory.

środa, 20 listopada 2013

mdadm "lost" discs

A few days ago I had to stop my systems. One of them had different kind of storage like: luns, nfs and software raids. After turned on system I realized that I had had no software raid. I checked if everything was connected and checked if discs exists.
mdadm --examine /dev/sd[b-t] /dev/sdc: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : da8f3a5d:10f75bee:f074ba7e:f0494c09 Update Time : Tue Dec 11 13:59:58 2012 Checksum : d24bdccc - correct Events : 0 Chunk Size : 512K Device Role : Active device 7 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdd: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : c4d19ddc:f5dc1884:c6ef0844:3abe1c66 Update Time : Tue Dec 11 13:59:58 2012 Checksum : 98af3bd - correct Events : 0 Chunk Size : 512K Device Role : Active device 8 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sde: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 51e205a2:40aa348f:3f2041a9:872d3e1f Update Time : Tue Dec 11 13:59:58 2012 Checksum : f868715b - correct Events : 0 Chunk Size : 512K Device Role : Active device 9 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdf: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 1832c689:2cb35bfc:d2c97cf5:d84c985d Update Time : Tue Dec 11 13:59:58 2012 Checksum : d7e592ea - correct Events : 0 Chunk Size : 512K Device Role : Active device 0 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdg: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 5a9a6781:53904dfc:0f5789c9:e0df60e8 Update Time : Tue Dec 11 13:59:58 2012 Checksum : 2e4df89a - correct Events : 0 Chunk Size : 512K Device Role : Active device 1 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdh: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : afa5008b:efc248ab:5ab3bce0:2def6ad1 Update Time : Tue Dec 11 13:59:58 2012 Checksum : e71fa223 - correct Events : 0 Chunk Size : 512K Device Role : Active device 2 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdi: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : c8e16d74:a1940d4c:5a802c6a:5173a94c Update Time : Tue Dec 11 13:59:58 2012 Checksum : 76000112 - correct Events : 0 Chunk Size : 512K Device Role : Active device 3 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdj: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 53051171:604d9634:a7f5c2b6:14c2bddd Update Time : Tue Dec 11 13:59:58 2012 Checksum : 38d6a16e - correct Events : 0 Chunk Size : 512K Device Role : Active device 4 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdk: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : fc3706df:d1f2df92:f50a37a7:55fd1845 Update Time : Tue Dec 11 13:59:58 2012 Checksum : 5ce4ca18 - correct Events : 0 Chunk Size : 512K Device Role : Active device 5 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdl: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 6ae2fd1e:30297e6c:4a26a015:2edcfe2c Update Time : Tue Dec 11 13:59:58 2012 Checksum : ccc9a512 - correct Events : 0 Chunk Size : 512K Device Role : Active device 6 Array State : AAAAAAAAAA ('A' == active, '.' == missing)
Than I realized that in my mdadm.conf were entries with /dev/dm-*. It means that something was wrong because in /dev I had only 4 entries contained dm*. It turned out that my multipath configuration blocked other dm-* devices to be discovered. I switched dm to disk/by-id.
root@testing:~# cat /etc/mdadm/mdadm.conf | grep -v ^# CREATE owner=root group=disk mode=0660 auto=yes HOMEHOST MAILADDR root DEVICE /dev/disk/by-id/scsi-SATA_MARVELL_*
Did:
root@testing:~# mdadm --assemble --scan
and
root@testing:~# mount -a
Now everything works as it should.