博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS 7 安装 Gitlab
阅读量:6083 次
发布时间:2019-06-20

本文共 9271 字,大约阅读时间需要 30 分钟。

安装基本系统与依赖包

安装 Gitlab 依赖的工具

yum -y updateyum -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

访问 ,下载 Redis 源代码。

wget http://download.redis.io/releases/redis-3.0.0.tar.gztar zxvf redis-3.0.0.tar.gzcd redis-3.0.0 make MALLOC=libc #如果不加参数,linux下会报错 make MALLOC=libc

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

sudo make test

安装:

sudo make installsudo ./utils/install_server.sh

配置

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

添加如下内容:

###########################PATH=/usr/local/bin:/sbin:/usr/bin:/binREDISPORT=6379EXEC=/usr/local/bin/redis-serverREDIS_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

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

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

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

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

which git

安装 ruby

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

cd ~curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz | tar xzcd 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 = MariaDBbaseurl = http://yum.mariadb.org/10.0/centos7-amd64gpgkey=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 -pCREATE 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/gitsudo -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/Gemfilesource "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/gitlabchmod +x /etc/init.d/gitlabchkconfig --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

http://segmentfault.com/a/1190000002729796

 

转载地址:http://cezwa.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
用yum安装mariadb
查看>>
一点IT"边缘化"的人的思考
查看>>
WPF 降低.net framework到4.0
查看>>
搭建一个通用的脚手架
查看>>
开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
查看>>
开源磁盘加密软件VeraCrypt教程
查看>>
本地vs云:大数据厮杀的最终幸存者会是谁?
查看>>
阿里云公共镜像、自定义镜像、共享镜像和镜像市场的区别 ...
查看>>
shadowtunnel v1.7 发布:新增上级负载均衡支持独立密码
查看>>
Java线程:什么是线程
查看>>
mysql5.7 创建一个超级管理员
查看>>
【框架整合】Maven-SpringMVC3.X+Spring3.X+MyBatis3-日志、JSON解析、表关联查询等均已配置好...
查看>>
要想成为高级Java程序员需要具备哪些知识呢?
查看>>
带着问题去学习--Nginx配置解析(一)
查看>>
onix-文件系统
查看>>
java.io.Serializable浅析
查看>>
我的友情链接
查看>>
多线程之线程池任务管理通用模板
查看>>
CSS3让长单词与URL地址自动换行——word-wrap属性
查看>>