{"id":5387,"date":"2014-11-21T14:51:45","date_gmt":"2014-11-21T20:51:45","guid":{"rendered":"https:\/\/secure.rosehosting.com\/blog\/?p=5387"},"modified":"2022-06-03T03:46:33","modified_gmt":"2022-06-03T08:46:33","slug":"install-gitlab-on-a-centos-linux-vps-with-nginx-and-mysql","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/install-gitlab-on-a-centos-linux-vps-with-nginx-and-mysql\/","title":{"rendered":"How to Install GitLab on CentOS 7"},"content":{"rendered":"
<\/p>\n
We’ll show you how to install GitLab on CentOS 7. GitLab is a self-hosted git repository management system. It is used by more than 100,000 organizations worldwide. Today we will show you how to install GitLab on your CentOS VPS<\/a>. For instructions about how to install GitLab on an Ubuntu\u00a0VPS<\/a>, you can check our Install GitLab on Debian<\/a>\u00a0tutorial. Installing GitLab on CentOS 7 is fairly easy task and it should take 10 minutes for the installation.<\/p>\n <\/p>\n To run GitLab on your server you will need to have Ruby 2.0 or 2.1 installed on your server. GitLab requires 2 CPU cores and 2GB of RAM so it can support up to 500 users. This makes our SSD 2 VPS hosting plan<\/a> suitable for your needs. You will need to have MySQL or PostgreSL and Redis. Additional packages will be installed. When it comes to\u00a0this tutorial, we are using our CentOS 6 64bit full template.<\/p>\n The first step is to add the required repositories to your system. You can do this\u00a0using the following commands:<\/p>\n Next thing you need to do is update all your system software, remove the unnecessary packages and install the required packages.<\/p>\n Create a system user for GitLab:<\/p>\n Now edit the ‘\/etc\/sudoers’ file and add ‘\/usr\/local\/bin’ at the end of:<\/p>\n It should look like this:<\/p>\n Download Git source and extract it in your ‘\/tmp’ directory. At the moment of writing, the latest version available is 2.1.3.<\/p>\n After doing this, you will need to download and install Ruby on your CentOS VPS<\/a>. At the moment of writing, the latest version available is 2.1.5.<\/p>\n Once\u00a0the installation of\u00a0Ruby is completed, it is time to create a database. You can do this\u00a0using the following commands:<\/p>\n Do not forget to change ‘PaSsWoRd’ with a password of your choice.<\/p>\n Now, let’s configure Redis. Open the ‘\/etc\/redis.conf’ file with an editor of your choice and set ‘port 0’.<\/p>\n Then, add the following lines at the end of the file:<\/p>\n Restart the service and add git to the redis group:<\/p>\n Now, let’s install GitLab. We assume that you have a full root access to your Linux VPS<\/a> so you should execute all these commands as root. Also, you can change the ‘7-4-stable’ to the latest stable version available.<\/p>\n Edit ‘config\/gitlab.yml’ and follow the instructions at the top of the file.<\/p>\n Execute the commands:<\/p>\n Then, copy the ‘config\/unicorn.rb.example’ file to ‘config\/unicorn.rb’. Edit the ‘config\/unicorn.rb’ file and set the number of workers to match the number of cores on your CentOS VPS.<\/p>\n Please note, ‘unicorn.rb’ and ‘gitlab.yml’ should contain\u00a0the same information.<\/p>\n Now, copy ‘config\/database.yml.mysql’ to ‘config\/database.yml’ and edit the file. Please note that you will need to change the secure password with your ‘PaSsWoRd’ value.<\/p>\n Install Bundler, gems, GitLab shell and initialize the database.<\/p>\n Please change ‘YourPassword’ with your password. Also, you can review and modify the ‘config.yml’ file.<\/p>\n We are approaching the\u00a0end of this tutorial. It is now time to install the init script. You can use the following commands:<\/p>\n Set the logrotate, check the status, compile the assets and then start the GitLab:<\/p>\n OK, it is time to configure Nginx on your server and generate an SSL.<\/p>\n Edit the ‘\/etc\/nginx\/conf.d\/gitlab.conf’ file to match your FQDN and your SSL path. Also, you will need to comment the following lines:<\/p>\n Finally, run the following commands:<\/p>\n That’s it. If you followed closely every single step of this tutorial, you should be able to access your newly installed GitLab using your domain name or your CentOS VPS<\/a> IP address. For example, if your IP address is 12.34.56.78 you need to enter https:\/\/12.34.56.78 .<\/p>\n Of course, you don\u2019t have to Install GitLab on CentOS 7, if you use one of our Linux VPS hosting<\/a> services, in which case you can simply ask our expert Linux admins to install GitLab for you. They are available 24\u00d77 and will take care of your request immediately. You can also check our guide on How to Install GitLab on Ubuntu 18.04<\/a>.<\/p>\n PS. If you liked this post, on how to install GitLab on CentOS 7, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":" We’ll show you how to install GitLab on CentOS 7. GitLab is a self-hosted git repository management system. It is … <\/p>\nStep 1: Add the\u00a0required repositories to your system<\/h3>\n
wget -O \/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-EPEL-6 https:\/\/www.fedoraproject.org\/static\/0608B895.txt\nrpm --import \/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-EPEL-6\nrpm -Uvh http:\/\/dl.fedoraproject.org\/pub\/epel\/6\/x86_64\/epel-release-6-8.noarch.rpm\nwget -O \/etc\/yum.repos.d\/PUIAS_6_computational.repo https:\/\/gitlab.com\/gitlab-org\/gitlab-recipes\/raw\/master\/install\/centos\/PUIAS_6_computational.repo\nwget -O \/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-puias http:\/\/springdale.math.ias.edu\/data\/puias\/6\/x86_64\/os\/RPM-GPG-KEY-puias\nrpm --import \/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-puias<\/pre>\n
Step 2: Installing the required packages<\/h3>\n
yum update -y\nyum remove git httpd sendmail -y\nyum -y install nginx zlib-devel openssl-devel git redis perl-CPAN ncurses-devel gdbm-devel glibc-devel tcl-devel curl-devel byacc db4-devel sqlite-devel libxml2 libxml2-devel libffi libffi-devel libxslt libxslt-devel libyaml libyaml-devel libicu libicu-devel system-config-firewall-tui sudo wget crontabs gettext perl-Time-HiRes cmake gettext-devel readline readline-devel libcom_err-devel.i686 libcom_err-devel.x86_64 expat-devel logwatch logrotate patch\n<\/pre>\n
Step 3: Create user<\/h3>\n
adduser --shell \/bin\/bash --home-dir \/home\/git\/ git<\/pre>\n
Defaults secure_path = \/sbin:\/bin:\/usr\/sbin:\/usr\/bin<\/pre>\n
Defaults secure_path = \/sbin:\/bin:\/usr\/sbin:\/usr\/bin:\/usr\/local\/bin<\/pre>\n
Step 4:\u00a0Download Git source<\/h3>\n
mkdir \/tmp\/git\ncd \/tmp\/git\nwget https:\/\/www.kernel.org\/pub\/software\/scm\/git\/git-2.1.3.tar.gz \ntar -xzvf git-2.1.3.tar.gz\ncd git-2.1.3\/\n.\/configure\nmake\nmake prefix=\/usr\/local install\n\n<\/pre>\n
Step 5: Download and install Ruby<\/h3>\n
mkdir \/tmp\/ruby\ncd \/tmp\/ruby\nwget ftp:\/\/ftp.ruby-lang.org\/pub\/ruby\/2.1\/ruby-2.1.5.tar.gz \ntar -xzvf ruby-2.1.5.tar.gz\ncd ruby-2.1.5\n.\/configure --disable-install-rdoc\nmake\nmake prefix=\/usr\/local install<\/pre>\n
Step 6: Create new database<\/h3>\n
mysql -u root -p \nCREATE USER 'git'@'localhost' IDENTIFIED BY 'PaSsWoRd';\nCREATE DATABASE `gitlabdb` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;\nGRANT ALL ON `gitlabdb`.* TO 'git'@'localhost';<\/pre>\n
Step 7: Configure Redis<\/h3>\n
port 0<\/pre>\n
unixsocket \/var\/run\/redis\/redis.sock\nunixsocketperm 0775<\/pre>\n
service redis restart\nusermod -aG redis git<\/pre>\n
Step 7: Install GitLab on CentOS 7<\/h3>\n
cd \/home\/git\nsudo -u git -H git clone https:\/\/gitlab.com\/gitlab-org\/gitlab-ce.git -b 7-4-stable gitlab\ncd \/home\/git\/gitlab\nsudo -u git -H cp config\/gitlab.yml.example config\/gitlab.yml<\/pre>\n
sudo -u git -H nano config\/gitlab.yml<\/pre>\n
chown -R git log\/\nchmod -R u+rwX log\/\nchown -R git tmp\/\nchmod -R u+rwX tmp\/\nchmod -R u+rwX tmp\/sockets\/\nchmod -R u+rwX tmp\/pids\/\nchmod -R u+rwX public\/uploads\nsudo -u git -H mkdir \/home\/git\/gitlab-satellites\nchmod u+rwx,g=rx,o-rwx \/home\/git\/gitlab-satellites<\/pre>\n
sudo -u git -H cp config\/unicorn.rb.example config\/unicorn.rb\nsudo -u git -H nano config\/unicorn.rb<\/pre>\n
sudo -u git -H cp config\/initializers\/rack_attack.rb.example config\/initializers\/rack_attack.rb\nsudo -u git -H cp config\/resque.yml.example config\/resque.yml<\/pre>\n
sudo -u git cp config\/database.yml.mysql config\/database.yml\nsudo -u git -H nano config\/database.yml\nsudo -u git -H chmod o-rwx config\/database.yml<\/pre>\n
gem install bundler\ncd \/home\/git\/gitlab\nsudo -u git -H bundle install --deployment --without development test postgres aws\nsudo -u git -H bundle exec rake gitlab:shell:install[v2.1.0] REDIS_URL=unix:\/var\/run\/redis\/redis.sock RAILS_ENV=production\nrestorecon -Rv \/home\/git\/.ssh\nsudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=YourPassword<\/pre>\n
sudo -u git -H nano \/home\/git\/gitlab-shell\/config.yml<\/pre>\n
Step 8: Install init script<\/h3>\n
wget -O \/etc\/init.d\/gitlab https:\/\/gitlab.com\/gitlab-org\/gitlab-recipes\/raw\/master\/init\/sysvinit\/centos\/gitlab-unicorn\nchmod +x \/etc\/init.d\/gitlab\nchkconfig --add gitlab<\/pre>\n
cp lib\/support\/logrotate\/gitlab \/etc\/logrotate.d\/gitlab\nsudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\nsudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production\nservice gitlab start<\/pre>\n
Step 9: Configure Nginx<\/h3>\n
get -O \/etc\/nginx\/conf.d\/gitlab.conf https:\/\/gitlab.com\/gitlab-org\/gitlab-ce\/raw\/master\/lib\/support\/nginx\/gitlab-ssl\n<\/pre>\n
mkdir \/etc\/nginx\/ssl\ncd \/etc\/nginx\/ssl\/\nopenssl genrsa -des3 -out gitlab.key 1024\nopenssl req -new -key gitlab.key -out gitlab.csr\ncp gitlab.key gitlab.key.org\nopenssl rsa -in gitlab.key.org -out gitlab.key\nopenssl x509 -req -days 365 -in gitlab.csr -signkey gitlab.key -out gitlab.crt<\/pre>\n
# listen [::]:80 default_server;\n# listen [::]:443 ssl default_server;<\/pre>\n
usermod -a -G git nginx\nchmod g+rx \/home\/git\/\nservice nginx start\nchkconfig gitlab on\nchkconfig nginx on\nchkconfig redis on<\/pre>\n
\n