Alibaba Cloud Tech Share - How to deploy GitLab on Alibaba Cloud - Alibaba Cloud Developer Forums: Cloud Discussion Forums

Assistant Engineer
Assistant Engineer
  • UID622
  • Fans2
  • Follows0
  • Posts52

Alibaba Cloud Tech Share - How to deploy GitLab on Alibaba Cloud

More Posted time:Jan 12, 2017 16:10 PM
This is for $500 USD Coupon - Alibaba Cloud Tech Share

Recently, I tried to transform my static blog to an auto-deployed blog. After hearing about this, my colleague recommended I try GitLab.

Software environment

Switch the Yum source
You can set the yum source as the open-source image of Alibaba Cloud to accelerate software installation.
cd /etc/yum.repos.d
wget -O CentOS-Base.repo

Despite of this, installing certain packages is still slow.

Required software packages
yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

Install Git
//View the current Git version.
git --version
//Uninstall first if the version is earlier than 1.7.10.
yum remove git
//Download and install the latest Git version.
wget -O
cd git-src
make prefix=/usr/local all
make prefix=/usr/local install
ln -fs /usr/local/bin/git* /usr/bin/

Install a Ruby environment
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress | tar xz
//This step takes a long time to complete and the progress advances by about 0.1% per second.
cd ruby-2.1.5
./configure --disable-install-rdoc
make && make install

ln -s /usr/local/bin/bundle /usr/bin/bundle
ln -s /usr/local/bin/ruby /usr/bin/ruby
ln -s /usr/local/bin/gem /usr/bin/gem

//Set the ruby gem source as the Taobao source.
gem source -r
gem source -a  //Note to use "https" but not "http".
gem install bundler --no-ri --no-rdoc

Install MySQL and initialize a GitLab database
yum install mysql mysql-devel mysql-server -y
/etc/init.d/mysqld start
chkconfig mysqld on

//Log in to MySQL and create a GitLab account and database.
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

Install Redis
yum -y install redis
/etc/init.d/redis start
chkconfig redis on

Add a Git account and allow Sudo
useradd --comment 'gitlab' git
echo "git ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers

Test if you can log in to the database with the Git account
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production

Install GitLab
cd /home/git
sudo -u git -H git clone -b 7-8-stable gitlab
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
//Edit the path to Git and the host:port for GitLab.
vim config/gitlab.yml
// bin_path: /usr/local/bin/git
// host: localhost
// port: 80
//Add required permissions for the folder.
chown -R git log/
chown -R git tmp/
chmod -R u+rwX  log/
chmod -R u+rwX  tmp/
//Create required folders and copy the configuration file.
sudo -u git -H mkdir /home/git/gitlab-satellites
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/
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX  public/uploads
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H cp config/initializers/rack_attack.rb.example
//Directly skip the folders that may exist already.
//Configure database connection information.
sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git -H vim  config/database.yml
vim config/database.yml
// production:
// username: gitlab
// password: "gitlab

Install GitLab-Shell
cd /home/git
sudo -u git -H git clone -b v2.6.0
cd gitlab-shell/
sudo -u git -H cp config.yml.example config.yml

//Edit the configuration file and set gitlab_url, redis-cli, log-level...
vim config.yml
// gitlab_url: "http://localhost/"
// /usr/bin/redis-cli

//Install git-shell.
sudo -u git -H ./bin/install

Install required Ruby gems
Before running the following command, change the default source of gem back to that of Taobao. Actually, we have done this change earlier but you still need to change it manually here. To do this, you need to run vim Gemfile to change source "" to Note: use https, not http.
cd /home/git/gitlab
sudo -u git -H bundle install --deployment --without development test postgres aw

During the process, you may encounter the following error:
An error occurred while installing rugged (0.21.2), and Bundler cannot continue.
Make sure that `gem install rugged -v '0.21.2'` succeeds before bundling.

If this is the case, you need to install:
sudo yum -y install cmake
Then, repeat the process to try again.

Initialize the database (create GitLab-related tables)
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
After performing this step, you can see the username and password.
Administrator account created:

Install the startup file and the log cutter file.
cp lib/support/init.d/gitlab /etc/init.d/gitlab
cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

Set Git account information
$ sudo -u git -H git config --global "Reeoo Shen"
$ sudo -u git -H git config --global ""
$ sudo -u git -H git config --global core.autocrlf input

Even you have set this information here, you will still find that the later check will prompt the information is not set.

Install nginx
This step will not be detailed as I have already installed nginx on my server.
Next, modify required permissions and start nginx.
nginx -t
chown -R git:git /var/lib/nginx/
/etc/init.d/nginx start

Detect the current environment
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
[root@iZ234fbksx3Z gitlab]# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

System information
System:        CentOS 6.7
Current User:    git
Using RVM:    no
Ruby Version:    2.1.5p273
Gem Version:    2.2.2
Bundler Version:1.11.2
Rake Version:    10.3.2
Sidekiq Version:3.3.0

GitLab information
Version:    7.8.4
Revision:    019ffd9
Directory:    /home/git/gitlab
DB Adapter:    mysql2
SSH Clone URL:
Using LDAP:    no
Using Omniauth:    no

GitLab Shell
Version:    2.6.0
Repositories:    /home/git/repositories/
Hooks:        /home/git/gitlab-shell/hooks/
Git:        /usr/local/bin/git

Pull GitLab static resource files
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

Start GitLab
/etc/init.d/gitlab start

Verify if all components are working normally
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
After nearly a day of modification, there is only one problem left:
Checking Environment ...

Git configured for git user? ... yes

Checking Environment ... Finished

Checking GitLab Shell ...

GitLab Shell version >= 2.5.4 ? ... OK (2.6.0)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
Satellites access is drwxr-x---? ... yes
hooks directories in repos are links: ...
reeoo / mytest ... ok
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Check directories and files:
    /home/git/repositories: OK
    /home/git/.ssh/authorized_keys: OK
Test redis-cli executable: redis-cli 2.4.10
Send ping to redis server: PONG
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... no
  Try fixing it:
  Redownload the init script
  For more information see:
  doc/install/ in section "Install Init Script"
  Please fix the error above and rerun the checks.
projects have namespace: ...
reeoo / mytest ... yes
Projects have satellites? ...
reeoo / mytest ... yes
Redis version >= 2.0.0? ... yes
Ruby version >= 2.0.0 ? ... yes (2.1.5)
Your git bin path is "/usr/local/bin/git"
Git version >= 1.7.10 ? ... yes (2.7.0)

Checking GitLab ... Finished

See the output below:
Init script up-to-date? ... no
  Try fixing it:
  Redownload the init script
  For more information see:
  doc/install/ in section "Install Init Script"
  Please fix the error above and rerun the checks.

It's said that these "no" prompts can be ignored, and I have not found a solution yet. This problem may also relate to another problem that the password is always required by the code in the local clone repository.
Then, by accessing, the error message 502 Bad GateWay appears.
By querying the nginx log,
tail /var/log/nginx/gitlab_error.log
the error message "/home/git/gitlab/public/favicon.ico.html" failed (13: Permission denied) appears.
After you run chmod 775 /home/git to obtain required permissions, becomes accessible (though was also accessible when multiple "no" prompt appear). However, after a new project is created, commit is unavailable:
Your changes could not be committed, because the file has been changed(Run commit on the GitLab server.)
When commit is performed, the following error always appears.
Check gitlab-shell/config.yml, and you will find gitlab_url: is displayed as "".
Modify gitlab_url: to "" and restart, and the problem is resolved with the following message: Your changes have been successfully committed.

Outstanding problem
1. As mentioned above, even you have set Git information, you will still find that the Git information is unavailable during later checks.
Refer to Error in Gitlab:, git configured for git user … no try fixing it
to resolve this problem.
2. For Redis misconfiguration:
sudo -u git ./check
    Check GitLab API access: OK
    Check directories and files:
            /home/git/repositories: OK
            /home/git/.ssh/authorized_keys: OK
    Test redis-cli executable: redis-cli 2.4.10
    Send ping to redis server: Could not connect to Redis at /var/run/redis/redis.sock: No such file or directory

Locate /home/git/gitlab-shell/config.yml, uncomment socket and rerun the check:
      bin: /usr/bin/redis-cli
      # host:
      # port: 6379
      # pass: redispass # Allows you to specify the password for Redis
      database: 0
      #socket: /var/run/redis/redis.sock # Comment out this line if you want to use TCP // Comment out this line
      namespace: resque:gitlab

3. During the check, another problem (insufficient available memory) occurs as my Alibaba Cloud server has a single processor core and 1GB of memory. Checking the problem online, I found that the solution is complicated. In my case, I upgraded the memory to 2GB directly as the solution.
4. Last, there's one more outstanding problem I've encountered up to this point:
After the ssh key is uploaded to GitLab, the password is always required by the clone repository. However, any password that I can remember cannot resolve this problem. Currently, GitLab has been deployed but clone, pull, commit and push operations are all unavailable.

Latest likes:

fridayyofriday... ownonesownone...