栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

一键安装与配置gitlab(脚本)

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一键安装与配置gitlab(脚本)

一、解决问题概述

该脚本可以解决 gitlab安装、配置访问网址、配置初始登录密码、配置系统的邮箱。

二、脚本内容
#!/bin/bash

#下面是定义颜色变量,用来给输出变量定义
RED='e[1;31m' #输出为红色
GREEN='e[1;32m' #输出为绿色
YELLOW='33[1;33m'
BLUE='E[1;34m'
PINK='E[1;35m'
RES='33[0m'


#下面这个函数是gitlab的安装步骤
function install() {
  #安装依赖
  yum install curl wget policycoreutils policycoreutils-python openssh-server openssh-clients postfix -y >/dev/null
  systemctl enable sshd
  systemctl start sshd
  sed -i 's/inet_interfaces = localhost/inet_interfaces = all/g' /etc/postfix/main.cf
  
  #正式安装gitlab
  curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh  | sudo bash > /dev/null
  sed -i "s/baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/7/$basearch/baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever//g" /etc/yum.repos.d/gitlab_gitlab-ce.repo  
  yum makecache &>/dev/null
  yum install gitlab-ce -y 
  #已经安装完成
 

  #验证是否安装成功
  right=$(yum list installed | grep gitlab-ce)
  gitlab='gitlab-ce'
    if [[ ${right} =~ "${gitlab}" ]];then
      echo "gitlab-ce已经安装成功啦!"
    else
      echo "gitlab-ce没有安装成功,请重新检查!"
      exit
    fi
}



#此函数是修改gitlab的访问url
function url() {
until [[ $flag == "yes" || $flag == "YES" || $flag == "Y" || $flag == "y" || $flag == "NO" || $flag == "no" || $flag == "N" || $flag == "n" ]]
do
    read -p "请问您是否使用您的ip+端口实现访问:(yes|no)" flag
    case $flag in
       yes|YES|Y|y)
         until [[ $cloud == "云主机" || $cloud == "虚拟机" ]]
         do
         read -p "请输入您目前使用的机器:(云主机|虚拟机)" cloud
         if [[ $cloud == "云主机" ]];then
            line=$(wget -qO - ifconfig.co)
            sed -i "s?'http://gitlab.example.com'?'http://$line:9418'?g" /etc/gitlab/gitlab.rb
            gitlab-ctl reconfigure
            gitlab-ctl stop > /dev/null
            gitlab-ctl start > /dev/null
            echo -e "n"
            echo "此时访问http://$line:9418就可以显示gitlab的页面了"
            echo -e "n" 
            echo -e " ${red} 如果此时页面显示502,请检查您的机器性能是否大于2核4G,或者等待一分钟后重新刷新,祝你好运!${RES}"      
         elif [[ $cloud == "虚拟机" ]];then
            virtual=$(ifconfig | grep 'inet' | grep -v '127.0.0.1' | awk '{print $2}')
            sed -i "s?http://gitlab.example.com?http://$virtual:9418?g" /etc/gitlab/gitlab.rb
            restart > /dev/null
            echo "此时访问http://$line:9418就可以显示gitlab的页面了"
         else 
            echo "输入错误!"
         fi
         done
         ;;
       no|NO|N|n)
         echo "请确保您的域名申请成功!"
         ;;
       *)
         echo "您的输入不正确,请您重新输入"
         continue
         ;;
    esac
done
}




#此函数用来修改root的默认密码
function passwdction() {
while :
do
 read -p "请输入您要设置的密码,最少需要八位:" passwd
 if [[ ${#passwd} -ge 8 ]]; then
   cd /opt/gitlab/bin
   gitlab-rails console -e production <> /etc/gitlab/gitlab.rb

gitlab-ctl reconfigure

read -p "请输入一个用来接受测试邮件的地址:" accept
gitlab-rails console < 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/361883.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号