Wednesday, July 29, 2015

Building a distcache RPM

Required for building the httpd RPM if you need the mod_socache_dc RPM.
Download distcache-1.5.1.tar.bz2 from http://sourceforge.net/projects/distcache/files
Save in /root/rpmbuild/SOURCES, where /root/rpmbuild is the value returned by:
# rpm --eval '%{_topdir}'
Save the text after the dotted line in /root/rpmbuild/SPECS/distcache.spec
# cd /root/rpmbuild/SPECS
# rpmbuild -ba distcache.spec
This will create /root/rpmbuild/RPMS/x86_64/distcache-devel-1.5.1-1.x86_64.rpm
# rpm -ivh /root/rpmbuild/RPMS/x86_64/distcache-devel-1.5.1-1.x86_64.rpm


================== distcache.spec =============
Name:           distcache-devel
Version:        1.5.1
Release:        1
Summary:        Distributed session caching

Group:          Development/Libraries
License:        GNU Library or Lesser General Public License version 2.0 (LGPLv2)
URL:            http://sourceforge.net/projects/distcache/
Source0:        distcache-%{version}.tar.bz2
BuildRoot:      %{_builddir}/distcache-%{version}-root

%description
Distributed session caching tools and APIs, primarily for SSL/TLS servers though perhaps useful for other (non-SSL/TLS) circumstances. Also includes a self-contained network abstraction library (libnal), and the sslswamp SSL/TLS benchmark/test utility.

%prep
%setup -q -n distcache-%{version}
# Update proto_fd.c to avoid the LONG_MIN undeclared error. Just one line, so we don't need a patch file.
# rpmbuild untars source and cd's in the directory, so we use a relative path for proto_fd.c
sed -i.bak '29 i\#include <limits.h>' libnal/proto_fd.c
%build
./configure CFLAGS="-fPIC"
make
%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(755,root,root,-)
/usr/local/bin/dc_client
/usr/local/bin/dc_server
/usr/local/bin/dc_snoop
/usr/local/bin/dc_test
/usr/local/bin/nal_echo
/usr/local/bin/nal_hose
/usr/local/bin/nal_ping
/usr/local/bin/nal_pong
/usr/local/bin/nal_proxy
/usr/local/bin/nal_test
/usr/local/bin/piper
/usr/local/bin/sslswamp
/usr/local/lib/libdistcache.la
/usr/local/lib/libdistcacheserver.la
/usr/local/lib/libnal.la
/usr/local/lib/libnalssl.la
%defattr(644,root,root,-)
/usr/local/include/distcache/dc_client.h
/usr/local/include/distcache/dc_plug.h
/usr/local/include/distcache/dc_server.h
/usr/local/include/libnal/nal_devel.h
/usr/local/include/libnal/nal.h
/usr/local/include/libnal/nal_ssl.h
/usr/local/lib/libdistcache.a
/usr/local/lib/libdistcacheserver.a
/usr/local/lib/libnal.a
/usr/local/lib/libnalssl.a
/usr/local/man/man1/dc_client.1
/usr/local/man/man1/dc_server.1
/usr/local/man/man1/dc_snoop.1
/usr/local/man/man1/dc_test.1
/usr/local/man/man1/sslswamp.1
/usr/local/man/man2/DC_CTX_new.2
/usr/local/man/man2/DC_PLUG_new.2
/usr/local/man/man2/DC_PLUG_read.2
/usr/local/man/man2/DC_SERVER_new.2
/usr/local/man/man2/NAL_ADDRESS_new.2
/usr/local/man/man2/NAL_BUFFER_new.2
/usr/local/man/man2/NAL_CONNECTION_new.2
/usr/local/man/man2/NAL_decode_uint32.2
/usr/local/man/man2/NAL_LISTENER_new.2
/usr/local/man/man2/NAL_SELECTOR_new.2
/usr/local/man/man8/distcache.8
/usr/local/share/swamp/A-client.pem
/usr/local/share/swamp/CA.pem
%doc

%changelog

Saturday, July 25, 2015

Building apache httpd RPMs from source on Centos 6

Probably works on RHEL as well. I used a fresh install of Centos 6.6.

# mkdir -p ~/rpmbuild/{SOURCES,SPECS,BUILD,RPMS,SRPMS}
# cd ~rpmbuild/SOURCES

Wget the latest source for httpd and apr, apr-util from your closest mirror:
# wget http://apache.mirrors.pair.com/httpd/httpd-2.4.16.tar.bz2
# wget http://apache.arvixe.com/apr/apr-1.5.2.tar.bz2
# wget http://apache.arvixe.com/apr/apr-util-1.5.4.tar.bz2

Build and install apr:
# rpmbuild -tb apr-1.5.2.tar.bz2
# rpm -ivh ~/rpmbuild/RPMS/x86_64/apr-1.5.2-1.x86_64.rpm \
~/rpmbuild/RPMS/x86_64/apr-devel-1.5.2-1.x86_64.rpm

Build apr-util:
 # rpmbuild -tb apr-util-1.5.4.tar.bz2
error: Failed build dependencies:
        expat-devel is needed by apr-util-1.5.4-1.x86_64
        libuuid-devel is needed by apr-util-1.5.4-1.x86_64
        freetds-devel is needed by apr-util-1.5.4-1.x86_64
        unixODBC-devel is needed by apr-util-1.5.4-1.x86_64

Alrighty then:
# yum -y install expat-devel libuuid-devel freetds-devel unixODBC-devel
freetds is from the epel repo. Be sure to enable that, since it isn't installed by default.

# rpmbuild -tb apr-util-1.5.4.tar.bz2 => OK!
# rpm -ivh ~/rpmbuild/RPMS/x86_64/apr-util-1.5.4-1.x86_64.rpm \
~/rpmbuild/RPMS/x86_64/apr-util-devel-1.5.4-1.x86_64.rpm

Httpd requires distcache for mod_socache_dc. Distcache doesn't have an RPM. If there is no need for  mod_socache_dc, you can try commenting out the following lines in httpd.spec:
%package -n mod_socache_dc
Group: System Environment/Daemons
Summary: Distcache shared object cache module for the Apache HTTP server
BuildRequires: distcache-devel
Requires: httpd = %{version}-%{release}, httpd-mmn = %{mmn}

Otherwise:
1. Use this distcache.spec file and follow instructions. If you go this this route you don't need to use "--nodeps" in the rpmbuild process in the final step.
2. Download distcache-1.5.1.tar.bz2 and build the old way from http://sourceforge.net/projects/distcache/files.
# tar xjf distcache-1.5.1.tar.bz2
# cd distcache-1.5.1
-fPIC fixed a weird httpd build issue for me. May not be needed otherwise.
# ./configure CFLAGS="-fPIC"
# make
Make fails with 'error "LONG_MIN" undeclared' . Fix it by adding:
# include <limits.h>
on line 29 of /distcache-1.5.1/libnal/proto_fd.c
# make
# make install

Now that distcache has been installed (or skipped), we can build httpd:
# rpmbuild -tb httpd-2.4.16.tar.bz2
error: Failed build dependencies:
     pcre-devel is needed by httpd-2.4.16-1.x86_64
     lua-devel is needed by httpd-2.4.16-1.x86_64
     distcache-devel is needed by httpd-2.4.16-1.x86_64
Alrighty then:
# yum -y install pcre-devel lua-devel

If we installed distcache the old school way (compiling without RPMs!) use --nodeps to ignore distcache-devel. If you created an RPM for distcache-devel you wouldn't need --nodeps.
# rpmbuild -tb --nodeps httpd-2.4.16.tar.bz2
# rpm -ivh ~/rpmbuild/RPMS/x86_64/httpd-2.4.16-1.x86_64.rpm \
~/rpmbuild/RPMS/x86_64/httpd-tools-2.4.16-1.x86_64.rpm \
~/rpmbuild/RPMS/x86_64/httpd-devel-2.4.16-1.x86_64.rpm \
~/rpmbuild/RPMS/x86_64/mod_ssl-2.4.16-1.x86_64.rpm

That's it!

Thanks to:
http://www.erikwebb.net/blog/compile-and-install-apache-24-red-hat-enterprise-linux-rhel-6-or-centos-6/

For having me look in the right direction.


Saturday, July 11, 2015

Using format built-in in Python2.7+

Simple example: print ("Stuff: {0}".format(str))

More information:

https://mkaz.com/2012/10/10/python-string-format/

Wednesday, July 1, 2015

How to restore a MySQL database with a different name

Possible scenarios:

  • You made a backup of db1 on one system, but want to restore it as db2 on another.
  • You want to rename your existing database, db1 to db2.

mysqldump -p  --databases db1 > db1_backup

On the new system (or the same system if you're renaming):
mysqladmin -p  create db2
Before running db1_backup through mysql, make sure db1_backup doesn't have the command "use db1" in it, otherwise you will keep overwriting the old database!
mysql -p db2 < db1_backup