Last active
December 28, 2020 20:13
-
-
Save sanand0/5405468 to your computer and use it in GitHub Desktop.
Installing Gitlab
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/5-1-stable/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 <<EOF | |
CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password'; | |
CREATE DATABASE IF NOT EXISTS \`gitlabhq_production\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`; | |
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON \`gitlabhq_production\`.* TO 'gitlab'@'localhost'; | |
EOF | |
# 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/gitlab-recipes/5-1-stable/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/gitlab-recipes/5-1-stable/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-54-251-228-123.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 | |
# In case gitlab crashes, you may need to delete | |
# /home/git/gitlab/tmp/sockets/gitlab.socket before restarting it. | |
# After restarting, the first request takes a long time. Relax. |
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 7.0: | |
# Set up an AWS EC2 Ubuntu 14.04 LTS (HVM), SSD Volume Type (ami-d6e7c084) | |
# m3.medium with web-server security group (SSH, SMTP, HTTP/S) | |
# Storage: 60GB SSD that *does not delete on termination* | |
# Tag as Gitlab 7 | |
# Log in as ubuntu@ | |
sudo apt-get -y update | |
sudo apt-get -y upgrade | |
wget https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab_7.0.0-omnibus-1_amd64.deb | |
sudo apt-get install openssh-server | |
# 'Internet Site' | |
# System mail name: gitlab. Do not use gramener.com | |
# Ensure that /etc/postfix/main.cf does not have gramener.com | |
sudo apt-get install postfix | |
sudo dpkg -i gitlab_7.0.0-omnibus-1_amd64.deb | |
# Edit the configuration file to add your hostname: | |
# external_url 'http://code.gramener.com' | |
sudo nano /mnt/gitlab/etc/gitlab/gitlab.rb | |
# Install and start Gitlab | |
sudo gitlab-ctl reconfigure | |
# Browse to the hostname and login | |
# Username: root | |
# Password: 5iveL!fe | |
# See https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md | |
# To connect to the PostgreSQL database | |
sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -d gitlabhq_production | |
# To create a new instance, in case it crashes: | |
# --------------------------------------------- | |
# Mount old drive at /mnt/gitlab/ | |
sudo mkdir /mnt/gitlab | |
sudo mount /dev/xvdf /mnt/gitlab | |
# Re-install gitlab | |
sudo dpkg -i gitlab... | |
# Edit the configuration file to add your hostname: | |
# external_url 'http://code.gramener.com' | |
sudo nano /mnt/gitlab/etc/gitlab/gitlab.rb | |
# Copy the old secrets file directly | |
sudo cp -r -p /mnt/gitlab/etc/gitlab/gitlab-secrets.json /etc/gitlab/ | |
# Install and start Gitlab. Then stop it | |
sudo gitlab-ctl reconfigure | |
sudo gitlab-ctl stop | |
# Use old password scheme | |
sudo cp /mnt/gitlab/etc/passwd /etc/passwd | |
sudo cp /mnt/gitlab/etc/group /etc/group | |
# These can be done automatically | |
sudo rm -rf /var/log/gitlab && sudo cp -rp /mnt/gitlab/var/log/gitlab /var/log/ | |
sudo rm -rf /opt/gitlab && sudo cp -rp /mnt/gitlab/opt/gitlab /opt/ | |
sudo rm -rf /var/opt/gitlab && sudo cp -rp /mnt/gitlab/var/opt/gitlab /var/opt/ | |
sudo rm -rf /var/chef/backup/opt/gitlab && sudo cp -rp /mnt/gitlab/var/chef/backup/opt/gitlab /var/chef/backup/opt/ | |
sudo rm -rf /var/chef/backup/var/opt/gitlab && sudo cp -rp /mnt/gitlab/var/chef/backup/var/opt/gitlab /var/chef/backup/var/opt/ | |
sudo gitlab-ctl reconfigure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment