-
-
Save sagunms/6070955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gitlab 5.1: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md | |
# Set up an AWS EC2 Ubuntu 12.04 LTS Server. | |
# Use ap-southeast-1b: spot pricing is smoother | |
# Log in as ubuntu@ | |
sudo apt-get -y update | |
sudo apt-get -y upgrade | |
# Install the required packages. | |
# For Postfix, select options: Internet > gitlab. Ensure that /etc/postfix/main.cf does not have gramener.com | |
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl git-core openssh-server redis-server postfix checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev | |
# Install Ruby | |
# ------------ | |
mkdir /tmp/ruby && cd /tmp/ruby | |
curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz | tar xz | |
cd ruby-1.9.3-p327 | |
./configure | |
make | |
sudo make install | |
# Install the bundler gem | |
sudo gem install bundler | |
# Gitlab Shell | |
# ------------ | |
# Create a git user for gitlab | |
sudo adduser --disabled-login --gecos 'GitLab' git | |
# Clone gitlab shell and set up the config file | |
sudo su -l git -c "cd /home/git && git clone https://github.com/gitlabhq/gitlab-shell.git" | |
sudo su -l git -c "cd /home/git/gitlab-shell && git checkout v1.3.0 && cp config.yml.example config.yml" | |
# Edit config and replace gitlab_url | |
# with something like 'http://domain.com/' | |
sudo su -l git -c 'cd /home/git/gitlab-shell && sed -i "s/localhost/git.gramener.com/" config.yml' | |
sudo su -l git -c "cd /home/git/gitlab-shell && ./bin/install" | |
# MySQL | |
# ----- | |
password=somerandompassword | |
echo mysql-server mysql-server/root_password password $password | sudo debconf-set-selections | |
echo mysql-server mysql-server/root_password_again password $password | sudo debconf-set-selections | |
# To reset password | |
# sudo dpkg-reconfigure mysql-server-5.5 | |
# Install the database packages | |
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev | |
# Login to MySQL | |
mysql -u root -p | |
# Create a user for GitLab. (change $password to a real password) | |
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password'; | |
# Create the GitLab production database | |
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; | |
# Grant the GitLab user necessary permissions on the table. | |
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON `gitlabhq_production`.* TO 'gitlab'@'localhost'; | |
# Quit the database session | |
mysql> \q | |
# Try connecting to the new database with the new user | |
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production | |
# We'll install GitLab into home directory of the user "git" | |
cd /home/git | |
# Clone GitLab repository | |
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab | |
# Go to gitlab dir | |
cd /home/git/gitlab | |
# Checkout to stable release | |
sudo -u git -H git checkout 5-1-stable | |
# Copy the example GitLab config | |
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml | |
# Make sure to change "localhost" to the fully-qualified domain name of your | |
# host serving GitLab where necessary | |
sudo -u git -H sed -i "s/localhost/git.gramener.com/" config/gitlab.yml | |
sudo -u git -H sed -i "s/@git.gramener.com/@gramener.com/" config/gitlab.yml | |
# Make sure GitLab can write to the log/ and tmp/ directories | |
sudo chown -R git log/ | |
sudo chown -R git tmp/ | |
sudo chmod -R u+rwX log/ | |
sudo chmod -R u+rwX tmp/ | |
# Create directory for satellites | |
sudo -u git -H mkdir /home/git/gitlab-satellites | |
# Create directories for sockets/pids and make sure GitLab can write to them | |
sudo -u git -H mkdir tmp/pids/ | |
sudo -u git -H mkdir tmp/sockets/ | |
sudo chmod -R u+rwX tmp/pids/ | |
sudo chmod -R u+rwX tmp/sockets/ | |
# Create public/uploads directory otherwise backup will fail | |
sudo -u git -H mkdir public/uploads | |
sudo chmod -R u+rwX public/uploads | |
# Copy the example Puma config | |
sudo -u git -H cp config/puma.rb.example config/puma.rb | |
# Mysql | |
sudo -u git cp config/database.yml.mysql config/database.yml | |
sudo -u git sed -i "s/username:.*/username: gitlab/" config/database.yml | |
sudo -u git sed -i "s/password:.*/password: $password/" config/database.yml | |
sudo gem install charlock_holmes --version '0.6.9' | |
# For MySQL (note, the option says "without") | |
sudo -u git -H bundle install --deployment --without development test postgres | |
# Initialise Database and Activate Advanced Features | |
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production | |
# Download the init script (will be /etc/init.d/gitlab): | |
sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlabhq/master/lib/support/init.d/gitlab | |
sudo chmod +x /etc/init.d/gitlab | |
# Make GitLab start on boot: | |
sudo update-rc.d gitlab defaults 21 | |
# Git configured for git user? ... no | |
# Try fixing it: | |
sudo -u git -H git config --global user.name "GitLab" | |
sudo -u git -H git config --global user.email "[email protected]" | |
# Run Sidekiq | |
sudo -u git -H bundle exec rake sidekiq:start RAILS_ENV=production | |
# Check if GitLab and its environment are configured correctly: | |
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production | |
# To make sure you didn't miss anything run a more thorough check with: | |
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production | |
# Start the service | |
sudo service gitlab start | |
# # or | |
# sudo /etc/init.d/gitlab restart | |
# Set up nginx | |
# ------------ | |
sudo apt-get -y install nginx | |
sudo curl --output /etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlabhq/master/lib/support/nginx/gitlab | |
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab | |
sudo sed -i 's/YOUR_SERVER_IP/'`wget -qO- http://instance-data/latest/meta-data/local-ipv4`'/' /etc/nginx/sites-available/gitlab | |
sudo sed -i 's/YOUR_SERVER_FQDN/ec2-175-41-180-155.ap-southeast-1.compute.amazonaws.com/' /etc/nginx/sites-available/gitlab | |
sudo service nginx restart | |
# Prevent fingerprint prompt for localhost. | |
echo "Host localhost | |
StrictHostKeyChecking no | |
UserKnownHostsFile=/dev/null" | sudo tee -a /etc/ssh/ssh_config | |
# Backup | |
cd ~git/gitlab | |
# If you get this: mysqldump: Got error: 1044: Access denied for user 'gitlab'@'localhost' to database 'gitlabhq_production' when using LOCK TABLES | |
# Then use: mysql> GRANT LOCK TABLES ON `gitlabhq_production`.* TO 'gitlab'@'localhost'; | |
sudo -u git -H rake RAILS_ENV=production gitlab:backup:create | |
# Restore. Make sure the filename only contains the timestamp, not the _gitlab_backup.tar | |
sudo -u git -H rake RAILS_ENV=production gitlab:backup:restore BACKUP=/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment