-
Notifications
You must be signed in to change notification settings - Fork 362
Gazelle Installation from scratch with Gentoo
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.
- 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?
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.
###Step 1. Click "New"###
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.
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.
I'm choosing a little more disk size than the bare minimum of 8 GB suggested by VirtualBox.
It now should look somewhat similar to this image:
It'll prompt you about mouse capturing, and then launch the inital setup wizard. Select the Gentoo ISO you downloaded.
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.
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.
I'm going to be lazy, and will be just using one swap partition plus one big partition the size of the complete disk:
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
Type the following commands in the shell:
mkfs.ext4 /dev/sda2
mkswap /dev/sda1
swapon /dev/sda1
Just type the following:
mount /dev/sda2 /mnt/gentoo/
Check the date. Type the following in the console:
date
If it isn't correct, see the Gentoo Handbook.
Follow the instructions in the Gentoo Handbook, Using a Stage from the Internet. Come back here after you've unpacked it on /mnt/gentoo/
.
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.
This is loosely based on this chapter of the Gentoo Handbook.
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.
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.
nano -w /etc/portage/make.conf
- Browse to the line that says
#USE="X gtk gnome -alsa"
- Add the following line below it:
USE="-X -gtk -gnome -qt4 -kde bash-completion crypt bcmath php mysql mysqli"
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
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 #
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.
- Figure out the name of your network device:
ifconfig -s
- Jot down the names of the network interfaces.
- 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
Replaceeth0
with the actual interface name.
- Type
passwd
in the shell - Follow the instructions
- Run
nano -w /etc/locale.gen
- Uncomment
en_US.UTF-8 UTF-8
and save. - Run
locale-gen
- Run
nano -w /etc/env.d/02locale
- Set
LANG="en_US.UTF-8"
and save the file. - Run
env-update && source /etc/profile
.
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
Run the following commands:
emerge grub:2
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
Congratulations! You're done. Reboot the system:
reboot
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/.
We're going to first install a few things on our base system:
- git
- nginx
- php
- memcache
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
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.
rc-update add nginx default
rc-update add php-fpm default
rc-update add mysql default
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.
nano -w /etc/php/fpm-php*/php.ini
Change the following settings:
short_open_tag = On
Change the same settings in /etc/php/cli-php*/php.ini
Run
emerge --config mysql
Don't forget the root password you set!
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
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
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
indexer -c /etc/sphinx/sphinx.conf --all
Run
cp /var/www/localhost/classes/config.{template,php}
Set the following variables according to the instructions:
-
SITE_NAME
togazelle test
-
SITE_IP
to the IP address the machine is using. You can use theip addr
orifconfig
commands to find out which IP address you are using. -
SSL_SITE_URL
tolocalhost
-
NONSSL_SITE_URL
tolocalhost
-
SERVER_ROOT
to/var/www/localhost
-
ANNOUNCE_URL
to'http://'.NONSSL_SITE_URL.':34000'
-
ENCKEY
to a random keyboard smash or something more random -
SITE_SALT
VERY IMPORTANT that you set this. Use a long, random string -
SCHEDULE_KEY
Set this to a word or something. Randomness isn't that important. -
RSS_HASH
Set this one to a random string as well -
SQLLOGIN
Set this to the SQL username.root
should work. -
SQLPASS
Set this to the SQL password you set earlier. -
SQLSOCK
Set this to/var/run/mysqld/mysqld.sock
-
TRACKER_PORT
Set this to34000
-
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.
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
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.
While not necessary for most development purposes, I'm going to install Ocelot now.
emerge boost mysql++ libev
tar jxf ocelot* && cd ocelot*
cp config.cpp{.template,}
nano -w config.cpp
Change the mysql_username
, mysql_password
, and site_password
variables to the right values.
./configure
make
Switch to an alternative terminal (Alt + F2) (you may also use screen), log in, and run
/var/www/localhost/ocelot*/ocelot