如何使用Apache和MySQL在Centos 5.5上安装Gitlab 7.8
时间:2020-03-05 15:30:35 来源:igfitidea点击:
GitLab是一个基于web的Git存储库管理器,具有wiki和问题跟踪功能。
GitLab是用ruby-on-rails编写的。
按照这里给出的教程安装gitlab omnibus包并不是那么困难。
但是,在centos 5.5上安装gitlab并不是那么容易,因为对于版本低于6.5的centos系统,没有提供任何综合包。
因此,让我们看看在centos 5.5上成功安装gitlab需要遵循的步骤:
1. 安装从源代码编译应用程序所需的开发工具
yum -y groupinstall "Development Tools" yum install perl-ExtUtils-MakeMaker
2. 安装缺少的依赖项
yum install libxslt-devel libyaml-devel libxml2-devel gdbm-devel libffi-devel zlib zlib-devel openssl-devel libyaml-devel readline readline-devel curl-devel openssl-devel pcre-devel git memcached-devel valgrind-devel mysql-devel ImageMagick-devel ImageMagick libicu libicu-devel libffi-devel make bzip2 autoconf automake libtool bison iconv-devel redis
3. 从源代码安装Git
- 我们需要确保Git的版本是1.7.10或者更高版本。要检查Git版本,请使用以下命令:
git --version
- 当git版本为1.7.10或者更高版本时,可以跳到步骤4. 如果没有,请从源代码安装。首先删除已安装的Git版本:
yum -y remove git
- 安装Git编译的必备文件:
yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
- 然后从源代码安装Git:
mkdir /tmp/git cd /tmp/git curl --progress https://www.kernel.org/pub/software/scm/git/git-2.1.2.tar.gz | tar xz cd git-2.1.3/ ./configure make make install
4安装Ruby 2.1.2`
- 删除旧的Ruby 1.8包(如果有的话)。GitLab仅支持Ruby 2.0+发行版系列:
yum remove ruby
- 删除任何其他Ruby版本(如果它仍然存在):
cd <your-ruby-source-path> make uninstall
- 卸载完成后,安装ruby 2.1.2
mkdir /tmp/ruby cd /tmp/ruby wget https://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz tar zxvf ruby-2.1.2.tar.gz cd ruby-2.1.2 ./configure make make install
- 要检查ruby版本,请使用以下命令:
ruby --version
- 输出应如下所示:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
- 我们需要安装Bundler Gem,如下所示:
gem install bundler --no-ri --no-rdoc
5. 我们将使用以下命令为Gitlab创建一个新用户:
useradd --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/git
6. 安装MySQL并为Gitlab创建新数据库
- 安装mysql
yum install -y mysql-server mysql-devel
- 登录MySQL(键入数据库根密码):
mysql -u root -p
- 为GitLab创建用户(在下面的命令中键入要设置的密码):
CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';
- 创建GitLab生产数据库:
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
- 授予Gitlab必要的权限
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
7. 配置Redis服务器
- 确保redis在引导时启动:
chkconfig redis on
- 配置redis以使用套接字:
cp /etc/redis.conf /etc/redis.conf.orig
- 通过将"port"设置为0禁用Redis在TCP上侦听:
sed 's/^port .*/port 0/' /etc/redis.conf.orig | sudo tee /etc/redis.conf
- 为默认CentOS路径启用Redis套接字:
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.conf echo -e 'unixsocketperm 0770' | sudo tee -a /etc/redis.conf
- 创建包含套接字的目录
mkdir /var/run/redis chown redis:redis /var/run/redis chmod 755 /var/run/redis
- 保存包含套接字的目录(如果适用)
if [ -d /etc/tmpfiles.d ]; then echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf fi
- 激活对的更改redis.conf文件:
/etc/init.d/redis restart
- 将git添加到redis组:
usermod -aG redis git
8. 安装Gitlab并进行配置
- 我们将把GitLab安装到用户"git"的主目录中
cd /home/git
- 克隆GitLab存储库
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-8-stable gitlab
- 转到GitLab安装文件夹并复制示例GitLab配置文件。
cd /home/git/gitlab sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
- 根据服务器编辑GitLab配置文件,如果我们想使用自定义端口,则将其包含在url中,否则只需提供域
sudo -u git -H nano config/gitlab.yml ## GitLab settings gitlab: ## Web server settings (note: host is the FQDN, do not include https://) host: https://git.yourtheitroad.com port: 8081 # Set to 443 if using HTTPS, see installation.md#using-https for additional HTTPS configuration details https: false # Set to true if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
- GitLab应该有一些权限,因此请确保完成以下操作:
chown -R git log/ chown -R git tmp/ chmod -R u+rwX log/ chmod -R u+rwX tmp/ chmod -R u+rwX tmp/pids chmod -R u+rwX tmp/sockets chmod -R u+rwX public/uploads
- 为卫星创建目录并正确设置权限
sudo -u git -H mkdir /home/git/gitlab-satellites chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
- 复制Unicorn配置示例
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
- 编辑独角兽.rb文件中,将worker数至少设置为核心数
nproc sudo -u git -H nano config/unicorn.rb
- 复制机架攻击配置示例
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
- 为Git用户配置Git全局设置,在通过web和edit进行编辑时非常有用用户电子邮件根据设定的吉特实验室.yml
sudo -u git -H git config --global user.name "GitLab" sudo -u git -H git config --global user.email "[email protected]" sudo -u git -H git config --global core.autocrlf input
- 配置Redis连接设置
sudo -u git -H cp config/resque.yml.example config/resque.yml
- 如果不使用默认的CentOS配置,请更改Redis套接字路径
sudo -u git -H nano config/resque.yml
- 配置MySQL数据库配置
sudo -u git cp config/database.yml.mysql config/database.yml
- 在配置中更新用户名/密码/数据库.yml.
sudo -u git -H nano config/database.yml
- 进行配置/数据库.yml仅对git可读
sudo -u git -H chmod o-rwx config/database.yml
9. 安装宝石
- 要安装charlock_holmes gem,我们需要icu包4.2.1或者更高版本
cd /home/git/gitlab curl -O https://download.icu-project.org/files/icu4c/4.2.1/icu4c-4_2_1-src.zip tar -xvzf icu4c-4_2_1-src.zip cd icu/source ./configure make sudo make install gem install charlock_holmes --version '0.6.9.4'
- 要安装所有其他gems,请使用以下命令
sudo -u git -H bundle install --deployment --without development test postgres aws
10. 安装Gitlab shell
- GitLab Shell是专门为GitLab开发的SSH访问和存储库管理软件。
- 运行gitlab shell的安装任务(如果需要,请替换"REDIS_URL"):
sudo -u git -H bundle exec rake gitlab:shell:install[v2.1.0] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
- 默认情况下,gitlab shell配置是从主gitlab配置生成的。
sudo -u git -H nano /home/git/gitlab-shell/config.yml
- 初始化数据库并激活高级功能
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
- 键入yes以创建数据库。你什么时候看到管理员帐户创建:。
Administrator account created: login.........root password......5iveL!fe
- 安装初始化脚本
cd /home/git/gitlab sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab sudo chmod +x /etc/init.d/gitlab sudo update-rc.d gitlab defaults 2
- 设置日志旋转
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
- 检查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
- 启动Gitlab实例并使用以下命令检查状态:
/etc/init.d/gitlab start /etc/init.d/gitlab status Gitlab service/Unicorn with PID 19988 is running. Gitlab service/Sidekiq with PID 20031 is running.
11. 如果我们不想使用nginxserver(gitlab建议使用Nginx),而是使用Apache,那么请按照以下步骤操作。
- 如果我们想从特定的端口和子域访问gitlab,这些步骤将非常有用。
- 创建新的gitlab.conf文件在/etc/httpd/conf.d/目录中添加以下内容
<VirtualHost *:80> ServerName https://git.yourtheitroad.com DocumentRoot /home/git/gitlab/public ServerSignature Off ProxyRequests Off ProxyPreserveHost On ProxyPass /https://127.0.0.1:8081/ ProxyPassReverse /https://127.0.0.1:8081/ ErrorLog /var/log/httpd/error_log <Location Order allow,deny Allow from all </Location> </VirtualHost>
- 为了识别配置,我们需要重新启动Apache/httpd和gitlab
/etc/init.d/httpd restart /etc/init.d/gitlab restart