24 November 2010

Synology as Web gateway (part1)

RedMine is a great tool for developpers: unfortunately it does not perform well on my synology DS-107+ (for various reasons i don't have time to inspect, low memory is probably a first answer)...

Anyway, as i'm having a-lot-of (probably too-much) machines available @ home: i choose to dedicate some horsepower to run a minimalistic virtual linux machine with Apache and RedMine (note that Bitnami is offering such packages ready for download).

So my idea was to use the Synology as a gateway between the internet and my home LAN, mainly to centralize security settings, and access point uniqueness.

Many topics are covered in this recipe:

1) Installing a virtual ubuntu server running redmine
2) Running a virtual machine as a service under Windows 7
3) Binding the Synology web frontend and a virtual server

Creating the virtual machine : ubuntu+redmine
Get VirtualBox, http://www.virtualbox.org/ . Eventually look for a portable edition.
    Create a new virtual machine: Ubuntu type, i dedicated 20gb of expandable disk space and 512Mo memory (but 5Go and 256Mo should be fine). Use Bridged Network Access for network connections (it should allow the virtual machine to have its own static IP address on your LAN).
      Note: to move a virtual server from one machine to another: ensure that you're using the same netword card between virtualbox installations: type of network card and MAC address must be the same. (note that if network is not working properly on virtualized linux, ensure that /etc/udev/rules.d/70-persistent-net.rules doesn't contain deprecated MAC entries).
      Grab Ubuntu server ISO, attach it to your virtua machine and perform the (blazingly fast) install: select Apache and MySQL components
        • Once connected to the console, you might notice a sluggish refresh:
        howto blackList vga mode :
        sudo nano /etc/modprobe.d/blacklist-framebuffer.conf
        add the following line:
        blacklist vga16fb
        Note: you can enable and use remote access to a virtualbox machine...
        Enforcing static IP use for the virtual Ubuntu Server (192.168.0.78 in my case)

            sudo vi /etc/network/interfaces
            change
            auto eth0
            iface eth0 inet dhcp
            into
            auto eth0
            iface eth0 inet static
            address 192.168.0.78
            netmask 255.255.255.0
            network 192.168.0.0
            broadcast 192.168.0.255
            gateway 192.168.0.254
            store your dns info via
            sudo vi /etc/resolv.conf
            you should read/add something like this
            nameserver 208.67.220.220
            nameserver 208.67.222.222
             and finally
            sudo /etc/init.d/networking restart
            Install VirtualBox extensions on ubuntu servers
              apt-get install build-essential linux-headers-`uname -r`
              mount /dev/cdrom /media/cdrom
              cd /media/cdrom
              ./VBoxLinuxAdditions-x86.run
              Perform Ubuntu system update:
                sudo apt-get update
                sudo apt-get install ruby
                sudo apt-get install rubygems
                Install Ruby requirements for RedMine
                  sudo gem install
                  gem install rails -v 2.3.5 -no-doc -no-ri
                  gem install rack -v 1.0.1 -no-doc -no-ri
                  Plug Ruby with MySQL, using an adapter:
                    cd /tmp
                    check latest version http://github.com/tmtm/ruby-mysql/downloads
                    wget http://github.com/downloads/tmtm/ruby-mysql/ruby-mysql-2.9.3-beta.tar.gz
                    tar -xzvf ruby-mysql-2.9.3-beta.tar.gz
                    cd ruby-mysql-2.9.3-beta/
                    ruby setup.rb
                    Eventually install PHPMyAdmin
                      sudo wget http://sourceforge.net/projects/phpmyadmin/files%2FphpMyAdmin%2F3.3.7%2FphpMyAdmin-3.3.7-all-languages.tar.gz
                      sudo tar -xzvf 
                      sudo mv /apps/phpMyAdmin
                      On Ubuntu Server: symbolic links in /etc/apache2/sites-enabled point to 'available' web sites. Use the a2ensite (Apache2 Enable Site) command to create such symbolic links, like this: sudo a2ensite mynewsite where your site configuration file is /etc/apache2/sites-available/mynewsite . Similarly, the a2dissite utility is used to disable sites.
                      Enabling your PhpMyAdmin directory as a site
                        cd /etc/apache2/sites-available
                        ln /phpmyadmin /apps/phpmyadmin-3.3.7
                        sudo a2ensite phpmyadmin
                        /etc/init.d/apache2 reload
                        browse to address/phpmyadmin
                        login/root from installation credentials
                        sometimes php fails when triggered (security problems), edit
                        sudo nano /etc/php5/apache2/php.ini
                        and edit open_basedir = to add your own '/apps/' (which allow php execution from that directory).
                        Install Mercurial
                          sudo apt-get install mercurial
                          Download and configure Redmine (http://www.redmine.org/wiki/redmine/RedmineInstall)
                            chown -R www-data:www-data /apps/
                            cd /volume1/apps
                            wget http://rubyforge.org/frs/download.php/72201/redmine-1.0.1.tar.gz
                            tar -xzvf redmine-1.0.1.tar.gz

                            mv redmine-1.0.1 redmine
                            cd redmine/config
                            cp database.yml.sample database.yml
                            nano /config/database.yml

                            production
                            adapter: mysql
                            username: redmine
                            password: xxxxxxxx

                            sudo apt-get install libopenssl-ruby1.8
                            sudo apt-get install rake

                            cd redmine

                            RAILS_ENV=production rake config/initializers/session_store.rb
                            RAILS_ENV=production rake db:migrate
                            RAILS_ENV=production rake redmine:load_default_data
                            ruby script/server -p production

                            in redmine login/password: admin admin

                            Install passenger (module enabling execution of ruby servicing in Apache)
                              sudo apt-get install libapache2-mod-passenger
                              load module in sites apache config scripts if not included by default
                              LoadModule passenger_module modules/mod_passenger.so

                              Install RedMine site under Apache (http://www.he1ix.org/?p=572)
                                cd /etc/apache2/sites-available
                                Alias /redmine /apps/redmine-1.0.1/public
                                sudo a2ensite redmine
                                sudo /etc/init.d/apache2 reload
                                sudo chown -R www-data.www-data files log tmp public/plugin_assets
                                sudo a2enmod rewrite
                                cd /apps/redmine-1.0.1/public
                                copy dispatch.cgi.example dispatch.cgi
                                If you have problem with /tmp/mysql.sock (Redmine having some problems to access mysql: can't find /tmp/mysql.sock):
                                you cant use sudo  ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock (file is not persistent), but you may specify the ubuntu mysql socket path in redmine config: edit /redmine/config/database.yml
                                production:
                                  adapter: mysql
                                  socket: /var/run/mysqld/mysqld.sock
                                
                                
                                Enabling NFS services on your synology: to allow your LAN machine to access a repository on the synology
                                  synoservice --list
                                  synoservice --enable nfs
                                  nano /etc/exports

                                  In 'exports' file, add the following line
                                  /directory/ ip.of.NFS.client(ro,root_squash,no_subtree_check)
                                  (* as 'ip.of.NFS.client', means 'for all computers on LAN')

                                  Save the 'exports' file

                                  Check if the file /var/lib/nfs/rmtab does exist, if not, run the following command
                                  touch /var/lib/nfs/rmtab

                                  Now perform
                                  cd / /usr/sbin/exportfs -a

                                  Testing: look at /var/log/messages to check whether the settings are ok with your Synology product

                                  On the Ubuntu Server side (read this):

                                  sudo apt-get install nfs-kernel-server
                                  sudo mkdir /apps/mnt
                                  sudo mount 192.168.0.77:/volume1/repos

                                  sudo vi /etc/fstab
                                  to add
                                  192.168.0.77:/volume1/repos /nfsmount nfs
                                  That's it for the virtual ubuntu server install !

                                    No comments: