Skip to content

Gazelle Installation from scratch with Gentoo

Mel Pearlmutter edited this page Jan 12, 2018 · 3 revisions

If you don't want to use the available virtual machine, below is a guide to installing Gazelle, using the Gentoo operating system, to closely match the tools What.CD uses. We are using Gentoo in this guide, but you should be able to apply most of the gazelle configuration steps on any other operating system. Skip the installing gentoo and installing dependencies steps, and install those using your own favourite package manager or source tarballs.

Prequisites

  • A (virtual) machine to install Gentoo on
  • A Gentoo install CD. You don't need to burn the ISO to CD if you are going to use it on a virtual machine.
  • A couple of hours, depending on how fast your CPU is. Some music and a nice book might also be helpful. May I suggest the A Song of Ice and Fire series?

Setting up a VirtualBox virtual machine

If you're not using VirtualBox or if you're using a physical machine, you may skip this step. You may use it for inspiration though.

##Installing VirtualBox ## I'm using Gentoo Linux on my desktop as well. Anyone using a flavour of Linux should be able to find VirtualBox in their package manager.

Grab one of the packages available here if you're on Windows or OS X.

Configuring your virtual machine

###Step 1. Click "New"###

Step 2. Select a name and operating system

Step 3. Select the memory size

I'm choosing a little more than the recommended amount, since we'll be needing to allocate some RAM for Memcached. You can choose to allocate more RAM if you've got more in your PC: it'll make a lot of things a little faster, especially compiling stuff. We'll be doing a lot of that soon.

Step 4. Create a new virtual hard drive

You can use an existing one if you want, but this guide will assume you've got a blank slate. Most of the defaults are fine.

Step 4 a. Select disk size

I'm choosing a little more disk size than the bare minimum of 8 GB suggested by VirtualBox.

Step 5. All done configuring

It now should look somewhat similar to this image:

Step 6. Launch the virtual machine

It'll prompt you about mouse capturing, and then launch the inital setup wizard. Select the Gentoo ISO you downloaded.

Installing Gentoo Linux

After you've launched your (virtual) machine the Gentoo Linux LiveCD will be booting. It will ask for a keyboard layout: most users will want to keep the default settings.

Any special configurations not covered by this guide might be found in more detail in the official Gentoo Linux install documentation available here

After booting it will drop you into this shell:

Let's get started! We'll be doing a quick and dirty installation, skipping most of the configuration specifics.

Step 1. Networking

Should mostly be fine out of the box. Try ping -c 1 google.com. If it works, great! If not, see the Networking chapter of the install guide.

Step 2. Disk layout

I'm going to be lazy, and will be just using one swap partition plus one big partition the size of the complete disk:

Step 2 a. Creating partitions

Type the following commands:

fdisk /dev/sda

This will drop you into the fdisk shell.

Press n to create a new partition, then select p to make a primary partition. Select the default partition number, then select the default first sector. Use +1G to select a partition size of 1 GB.

Then select n to create another partition. Again, use p to make a primary partition. Also again select the default partition number, then select the default first sector.Then just press enter to use the rest of the disk.

Finally, commit the layout to disk using the w command.

TL;DR:

fdisk /dev/sda
n
p
<enter>
<enter>
+1GB
n
p
<enter>
<enter> 
<enter>
w

Step 2 b. Creating file systems

Type the following commands in the shell:

mkfs.ext4 /dev/sda2
mkswap /dev/sda1
swapon /dev/sda1

Step 2 c. Mounting file systems

Just type the following:

mount /dev/sda2 /mnt/gentoo/

Step 3 Installing the Gentoo installation files

Step 3 a. First things first

Check the date. Type the following in the console:

date

If it isn't correct, see the Gentoo Handbook.

Step 3 b. Getting a Stage3 tarball

Follow the instructions in the Gentoo Handbook, Using a Stage from the Internet. Come back here after you've unpacked it on /mnt/gentoo/.

Step 3 c. Setting compile options

Type the following in your shell:

`cp /mnt/gentoo/usr/share/portage/config/make.conf.example /mnt/gentoo/etc/portage/make.conf 
nano -w /mnt/gentoo/etc/portage/make.conf`

Navigate the file until you find the CFLAGS and CXXFLAGS settings. Read the documentation available there, but the following should be sane settings for most people:

CFLAGS="-march=native -O2 -pipe"
CXXFLAGS="${CFLAGS}"`

Then find MAKEOPTS. Setting it to MAKEOPTS="-j2" should do fine.

Uncomment (remove the #) from the line ACCEPT_KEYWORDS="~amd64".

Press Ctrl+X to save and exit nano.

Installing the base system

This is loosely based on this chapter of the Gentoo Handbook.

Getting into the chrooted environment

Execute the following commands, following the instructions mirrorselect provides:

mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
mirrorselect -r -i -o >> /mnt/gentoo/etc/portage/make.conf

Copy the /etc/resolv.conf file:

cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf

Remount necessary file systems:

mount -t proc none /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev

Enter the new environment:

chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"

Yay, we're now on our own! Time to make this system bootable.

Configuring portage

Just type the following and get installing portage over with:

mkdir /usr/portage
emerge-webrsync
emerge --sync

Setting the proper USE flags: We're now going to open /etc/portage/make.conf and set the USE flags we're going to build our system with. These settings help building packages with the proper options.

  1. nano -w /etc/portage/make.conf
  2. Browse to the line that says #USE="X gtk gnome -alsa"
  3. Add the following line below it: USE="-X -gtk -gnome -qt4 -kde bash-completion crypt bcmath php mysql mysqli"

Installing the kernel

Compiling kernels is a huge topic. Read this chapter of the Gentoo handbook for more information.

First download the kernel sources:

emerge gentoo-sources

I'm going to be lazy and just use the genkernel package. If you want to configure and optimise the kernel yourself, see here.

Using genkernel:

emerge genkernel
genkernel all

Configuring your system

Creating /etc/fstab

nano -w /etc/fstab

Then enter the following into that file. The amount of white space doesn't matter.

/dev/sda1   none         swap    sw                   0 0
/dev/sda2   /            ext4    noatime              0 1

Delete all othes lines that do not start with #

Setting the hostname

Edit /etc/conf.d/hostname:

nano -w /etc/conf.d/hostname

Set hostname="gazelletest".

If you need more specific networking configuration, see this chapter of the Gentoo Handbook.

Autostart networking on boot

  1. Figure out the name of your network device: ifconfig -s
  2. Jot down the names of the network interfaces.
  3. Then do for each network interface: ln -s /etc/init.d/net.lo /etc/init.d/net.eth0 && rc-update add /etc/init.d/net.eth0 default Replace eth0 with the actual interface name.

Change the root password

  1. Type passwd in the shell
  2. Follow the instructions

Configure locale

  1. Run nano -w /etc/locale.gen
  2. Uncomment en_US.UTF-8 UTF-8 and save.
  3. Run locale-gen
  4. Run nano -w /etc/env.d/02locale
  5. Set LANG="en_US.UTF-8" and save the file.
  6. Run env-update && source /etc/profile.

Installing system tools

Run the following command:

emerge syslog-ng logrotate vixie-cron dhcpcd  
rc-update add syslog-ng default
rc-update add vixie-cron default
rc-update add sshd default

If you're using VirtualBox:

emerge virtualbox-guest-additions

Installing a boot loader

Run the following commands:

emerge grub:2
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

Reboot

Congratulations! You're done. Reboot the system:

reboot

(Optional) System update

Because we're running ~amd64 this has the potential to fail. Don't run if you don't know what you're doing

You can run this command to update the whole system:

emerge -uDNav @world

These coding standards apply to legacy (PHP) Gazelle. For the new project, see https://github.com/meteor-gazelle/.

Installing Gazelle dependencies

We're going to first install a few things on our base system:

  • git
  • nginx
  • php
  • memcache

Configuring pre-install flags

Make sure you execute the following commands:

echo "dev-lang/php fpm" >> /etc/portage/package.use
echo "app-admin/eselect-php fpm" >> /etc/portage/package.use
echo ">=app-eselect/eselect-php-0.9.1 fpm" >> /etc/portage/package.use
echo 'PHP_TARGETS="php5-6"' >> /etc/portage/make.conf

Installing

Execute the following command:

emerge nginx php dev-vcs/git memcached pecl-memcache mysql
EXTRA_ECONF="--with-mysql" emerge app-misc/sphinx

Time to make some coffee.

Post-install configuration:

Make sure services start on boot:

rc-update add nginx default
rc-update add php-fpm default
rc-update add mysql default

Configure nginx

nano -w /etc/nginx/nginx.conf

Make sure the server section looks like this:

    server {
            server_name localhost;

            access_log /var/log/nginx/localhost.access_log main;
            error_log /var/log/nginx/localhost.error_log info;

            root /var/www/localhost/;

            index index.php index.html;

            location ~ .php$ {
                    fastcgi_pass 127.0.0.1:9000;
                    include fastcgi.conf;
            }
    }

So remove the listen 127.0.0.1; line and add the location section and index line.

Configure PHP

nano -w /etc/php/fpm-php*/php.ini

Change the following settings:

  1. short_open_tag = On

Change the same settings in /etc/php/cli-php*/php.ini

Configuring MySQL

Run

emerge --config mysql 

Don't forget the root password you set!

Setting up Gazelle

Cloning the Gazelle repository

We're going to need the files shipped in Gazelle to continue, so let's start by cloning the Gazelle repository into the web server's root.

rm -rf /var/www/localhost
git clone http://github.com/WhatCD/Gazelle.git /var/www/localhost

Initializing the database

If you haven't done so already, go ahead and start the mysql service. (You can also reboot.)

mysql -p < /var/www/localhost/gazelle.sql

Set up sphinx.conf

nano -w /var/www/localhost/sphinx.conf

Fill in the sql_user and sql_pass variables. The user can be root.

Verify that sql_sock is set to /var/run/mysqld/mysqld.sock.

On the second to last line of the file, comment out the line containing compat_sphinxql_magics = 0.

Execute

mkdir -p /var/data/sphinx
ln -s /var/www/localhost/sphinx.conf /etc/sphinx/sphinx.conf

Initialize sphinx

indexer -c /etc/sphinx/sphinx.conf --all

Configuring Gazelle

Copy the configuration template

Run

cp /var/www/localhost/classes/config.{template,php}

Edit the configuration file

Set the following variables according to the instructions:

  1. SITE_NAME to gazelle test
  2. SITE_IP to the IP address the machine is using. You can use the ip addr or ifconfig commands to find out which IP address you are using.
  3. SSL_SITE_URL to localhost
  4. NONSSL_SITE_URL to localhost
  5. SERVER_ROOT to /var/www/localhost
  6. ANNOUNCE_URL to 'http://'.NONSSL_SITE_URL.':34000'
  7. ENCKEY to a random keyboard smash or something more random
  8. SITE_SALT VERY IMPORTANT that you set this. Use a long, random string
  9. SCHEDULE_KEY Set this to a word or something. Randomness isn't that important.
  10. RSS_HASH Set this one to a random string as well
  11. SQLLOGIN Set this to the SQL username. root should work.
  12. SQLPASS Set this to the SQL password you set earlier.
  13. SQLSOCK Set this to /var/run/mysqld/mysqld.sock
  14. TRACKER_PORT Set this to 34000
  15. TRACKER_SECRET Set this to a 32 character string. An easy way to get a 32 character string is to take the MD5 hash of something complicated.

Start memcached

You need to do this again if you reboot the machine.

memcached -d -m 64 -s /var/run/memcached.sock -a 0777 -t16 -C -u root

Set up cron jobs

crontab -e

Set the following as contents for the file:

0,15,30,45  *  *   *    *       /usr/bin/php /var/www/localhost/schedule.php SCHEDULE_KEY >> /root/schedule.log
10,25,40,55 *  *   *    *       /usr/bin/php /var/www/localhost/peerupdate.php SCHEDULE_KEY >> /root/peerupdate.log
*           *  *   *    *       /usr/bin/indexer -c /etc/sphinx/sphinx.conf --rotate delta
5           *  *   *    *       /usr/bin/indexer -c /etc/sphinx/sphinx.conf --rotate --all

Remember to include the SCHEDULE_KEY that you set in the Gazelle configuration file.

Installing Ocelot

While not necessary for most development purposes, I'm going to install Ocelot now.

Install dependencies

emerge boost mysql++ libev

Unpack Ocelot

tar jxf ocelot* && cd ocelot*

Configuring Ocelot

Copy the configuration template

cp config.cpp{.template,}

Change Ocelot settings

nano -w config.cpp

Change the mysql_username, mysql_password, and site_password variables to the right values.

Compile

./configure
make 

Run

Switch to an alternative terminal (Alt + F2) (you may also use screen), log in, and run

/var/www/localhost/ocelot*/ocelot
Clone this wiki locally