转载

CentOS 7 安装 Gitlab

安装基本系统与依赖包

安装 Gitlab 依赖的工具

bashyum -y update yum -y groupinstall 'Development Tools' yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui git redis ruby sudo wget crontabs logwatch logrotate perl-Time-HiRes 

安装 Redis

访问 http://www.redis.io/download ,下载 Redis 源代码。

bashwget http://download.redis.io/releases/redis-3.0.0.tar.gz tar zxvf redis-3.0.0.tar.gz cd redis-3.0.0 make 

若在编译过程中出错,则可以执行下面的命令:

bashsudo make test 

安装:

bashsudo make install sudo ./utils/install_server.sh 

配置

创建 /etc/init.d/redis 并使用下面的代码作为启动脚本。

添加如下内容:

bash########################### PATH=/usr/local/bin:/sbin:/usr/bin:/bin REDISPORT=6379 EXEC=/usr/local/bin/redis-server REDIS_CLI=/usr/local/bin/redis-cli PIDFILE=/var/run/redis.pid CONF="/etc/redis/6379.conf" case "$1" in     start)  if [ -f $PIDFILE ]  then   echo "$PIDFILE exists, process is already running or crashed"  else   echo "Starting Redis server..."   $EXEC $CONF  fi  if [ "$?"="0" ]  then        echo "Redis is running..."  fi  ;;     stop)  if [ ! -f $PIDFILE ]  then   echo "$PIDFILE does not exist, process is not running"  else   PID=$(cat $PIDFILE)   echo "Stopping ..."   $REDIS_CLI -p $REDISPORT SHUTDOWN   while [ -x ${PIDFILE} ]         do       echo "Waiting for Redis to shutdown ..."       sleep 1   done   echo "Redis stopped"  fi  ;;    restart|force-reload)  ${0} stop  ${0} start  ;;   *)     echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2  exit 1 esac ##############################  

保存后,添加可执行权限:

sudo chmod +x /etc/init.d/redis 

确保 redis 能随系统启动:

vi /etc/rc.d/rc.local 

在文件末尾添加下面这行:

service redis start 

然后使用上面同样的命令启动 redis 服务:

service redis start 

安装邮件服务器

yum -y install postfix 

安装Git

先删除系统中原有的老版本 git

bashyum -y remove git yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel 

从官方网站下载源代码进行:

bashcurl --progress https://www.kernel.org/pub/software/scm/git/git-2.4.0.tar.gz | tar xz cd git-2.4.0/ ./configure make make prefix=/usr/local install 

然后使用下面这个命令检测安装是否有效:

which git 

安装 ruby

如果 ruby 的版本低于 2.0 的话,则需要重新安装 ruby

bashcd ~ curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz | tar xz cd ruby-2.2.2 ./configure --disable-install-rdoc make make prefix=/usr/local install 

为 Gitlab 添加系统用户

adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git 

为了包含/usr/local/bin到git用户的$PATH,一个方法是编辑超级用户文件。以管理员身份运行:

visudo 

然后搜索:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin 

将其改成:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin 

安装数据库

MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB,先搜索 MariaDB 现有的包:

rpm -qa | grep mariadb 

然后全部删除:

rpm -e --nodeps mariadb-* 

然后创建 /etc/yum.repos.d/MariaDB.repo

vi /etc/yum.repos.d/MariaDB.repo 

将以下内容添加至该文件中:

# MariaDB 10.0 CentOS repository list - created 2015-05-04 19:16 UTC # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 

然后运行下面命令安装 MariaDB 10.0

sudo yum install MariaDB-server MariaDB-client 

然后启动 MariaDB 服务:

service mysql start 

接着运行 mysql_secure_installation

mysql_secure_installation 

登录 MariaDB 并创建相应的数据库用户与数据库:

mysql -uroot -p CREATE USER 'git'@'localhost' IDENTIFIED BY '$password'; SET storage_engine=INNODB; 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 'git'@'localhost'; /q 

尝试使用新用户连接数据库:

sudo -u git -H mysql -u git -p -D gitlabhq_production /q 

安装 Gitlab

克隆源

sudo -u -git cd /home/git sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-10-stable gitlab 

配置

cd /home/git/gitlab  # Copy the example GitLab config # 复制GitLab的示例配置文件 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 # 确保修改“localhost”为你的GitLab主机的FQDN # # If you want to use https make sure that you set `https` to `true`. See #using-https for all necessary details. # 如果你想要使用https确保你设置了`https`为`true`。具体必要的细节参见#using-https # # If you installed Git from source, change the git bin_path to /usr/local/bin/git # 如果你从源代码安装了Git,修改git的bin_path为/usr/local/bin/git sudo -u git -H editor config/gitlab.yml  # Make sure GitLab can write to the log/ and tmp/ directories # 确保GitLab可以写入log/和temp/目录 chown -R git {log,tmp} chmod -R u+rwX  {log,tmp}  # Create directory for satellites # 为卫星(?)创建目录 sudo -u git -H mkdir /home/git/gitlab-satellites chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites  # Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories # 确保GitLab可以写入tmp/pids/和temp/sockets/目录 chmod -R u+rwX  tmp/{pids,sockets}  # Make sure GitLab can write to the public/uploads/ directory # 确保GitLab可以写入public/uploads/目录 chmod -R u+rwX  public/uploads  # Copy the example Unicorn config # 复制Unicorn的示例配置文件 sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb  # Enable cluster mode if you expect to have a high load instance # Ex. change amount of workers to 3 for 2GB RAM server # 启用集群模式如果你期望拥有一个高负载实例 # 附:修改worker的数量到3用于2GB内存的服务器 sudo -u git -H editor config/unicorn.rb  # Copy the example Rack attack config # 复制Rack attack的示例配置文件 sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb  # Configure Git global settings for git user, useful when editing via web # Edit user.email according to what is set in config/gitlab.yml # 为git用户配置Git全局设定,当通过web修改时有用 # 修改user.email根据config/gitlab.yml中的设定 sudo -u git -H git config --global user.name "GitLab" sudo -u git -H git config --global user.email "gitlab@localhost" sudo -u git -H git config --global core.autocrlf input 

数据库配置

# MySQL only: # 仅限MySQL: sudo -u git cp config/database.yml.mysql config/database.yml  # MySQL and remote PostgreSQL only: # Update username/password in config/database.yml. # You only need to adapt the production settings (first part). # If you followed the database guide then please do as follows: # Change 'secure password' with the value you have given to $password # You can keep the double quotes around the password # 仅限MySQL和远程PostgreSQL: # 在config/database.yml中更新用户名/密码; # 你只需要适配生产设定(第一部分); # 如果你跟从数据库向导,请按以下操作: # 修改'secure password'使用你刚才设定的$password; # 你可以保留密码两端的双引号。 sudo -u git -H editor config/database.yml  # PostgreSQL and MySQL: # Make config/database.yml readable to git only # PostgreSQL和MySQL: # 设置config/database.yml仅对git可读。 sudo -u git -H chmod o-rwx config/database.yml 

安装 Gems

cd /home/git/gitlab  # For users from China mainland only # 仅限中国大陆用户 nano /home/git/gitlab/Gemfile source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"  # For MySQL (note, the option says "without ... postgres") sudo -u git -H bundle install --deployment --without development test postgres aws 

Install GitLab shell

安装GitLab Shell

GitLab Shell是一个专门为GitLab开发的SSH访问和源管理软件。

# Go to the Gitlab installation folder: # 转到GitLab安装目录: cd /home/git/gitlab  # For users from China mainland only # 仅限中国大陆用户 nano /home/git/gitlab/Gemfile source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"  # Run the installation task for gitlab-shell (replace `REDIS_URL` if needed): # 运行gitlab-shell的安装任务(替换`REDIS_URL`如果有需要的话): sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production  # By default, the gitlab-shell config is generated from your main gitlab config. # 默认的,gitlab-shell的配置文件是由你的gitlab主配置文件生成的。 # # Note: When using GitLab with HTTPS please change the following: # - Provide paths to the certificates under `ca_file` and `ca_path options. # - The `gitlab_url` option must point to the https endpoint of GitLab. # - In case you are using self signed certificate set `self_signed_cert` to `true`. # See #using-https for all necessary details. # 提示:当通过HTTPS使用GitLab时,请做出如下更改: # - 提供证书的路径在`ca_file`和`ca_path`选项; # - `gitlab_url`选项必须指向GitLab的https端点; # - 如果你使用自签名的证书,设置`self-signed_cert`为`true`。 # 所有必需的具体细节参见#using-https # # You can review (and modify) it as follows: # 你可以检查(并修改该)通过以下方法: sudo -u git -H editor /home/git/gitlab-shell/config.yml  # Ensure the correct SELinux contexts are set # Read http://wiki.centos.org/HowTos/Network/SecuringSSH # 确保正确的SELinux上下文被设置 # 阅读http://wiki.centos.org/HowTos/Network/SecuringSSH restorecon -Rv /home/git/.ssh 

初始化数据库和激活高级功能

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production # Type 'yes' to create the database tables. # When done you see 'Administrator account created:' 

提示:你可以设置管理员密码通过在环境变量GITLAB_ROOT_PASSWORD中提供,例如:

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword 

安装初始化脚本

下载初始化脚本(将放在/etc/init.d/gitlab):

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab chmod +x /etc/init.d/gitlab chkconfig --add gitlab 

设置GitLab开机启动:

chkconfig gitlab on 

设置日志翻转

cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab 

检查应用状态

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production 

编译静态文件

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production 

启动实例

/etc/init.d/gitlab start 
正文到此结束
Loading...