gitlab安装脚本

  • 安装脚本
#!/bin/bash
## 系统为CENTOS7
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
systemctl start postfix && systemctl enable postfix
yum install gitlab-ce -y
## 生成ssl证书,这儿使用的是自生成证书,也可以在阿里上面使用免费的ssl证书
mkdir -p /etc/gitlab/ssl
cd /etc/gitlab/ssl
openssl req -new -nodes -sha256 -newkey rsa:2048 -keyout your_domai_name.key -out your_domai_name.csr -subj "/C=CN/ST=CHONGQING/0=CHONGQING/OU=CHONGQING/CN=your_domai_name/emailAddress=111111@qq.com"
openssl x509 -req -days 3650 -in your_domai_name.csr -signkey your_domai_name.key -out your_domai_name.crt
openssl dhparam -out dhparams.pem 2048
chmod 600 *
  • 需要修改的配置,编辑”/etc/gitlab/gitlab.rb”。以下几项需要打开,并且证书需要改成你自己设置的位置
##域名与ssl相关的配置
external_url 'https://your_domai_name'
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/#{node['fqdn']}.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/#{node['fqdn']}.key"
nginx['ssl_dhparam'] = /etc/gitlab/ssl/dhparams.pem
##备份相关得设置
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/opt/backup/gitlab"    ##gitlab备份目录
gitlab_rails['backup_archive_permissions'] = 0644       ##生成的备份文件权限
gitlab_rails['backup_keep_time'] = 7776000
  • 根据配置文件启动gitlab
gitlab-ctl reconfigure

jenkins安装脚本

  • jenkins安装脚本
#!/bin/bash
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
yum install wget git curl -y
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install java jenkins -y
systemctl start jenkins
## 查看jenkins默认生成的密码
cat /var/lib/jenkins/secrets/initialAdminPassword

SHELL脚本之case

  • 一般形式
case variable in
    pattern1 | pattern2)
        command;;
    pattern3)
        command;;
    *)
        default command;;
esac
  • 例子
#!/bin/bash
case $USER in
    root | user)
        echo "Welcome.$USER"
        echo "Please enjoy your visit";;
    testing)
        echo "Special testing acount";;
    *)
    echo "Sorry,you are not allowed here";;
esac

SHELL脚本之if

if语句的几种常用方法

  • if then fi
if command
then
    commands
fi
  • if then else fi
if command
then
    commands
else
    commands
fi
  • if then elif then fi
if command1
then
    commands
elif command2
then
    more commands
fi

PS:
1.if-then语句允许你使用布尔逻辑来组合测试,有两种布尔运算符可用:
[ condition ] && [ condition2 ]
[ condition ] || [ condition2 ]
2.双圆括号命令允许你将高级数学表达式放入比较中:
(( expression ))
3.双方括号里的expression使用了test命令中采用的标准字符串进行比较。但他提供了test命令未提供的另一种特性—-模式匹配
[[ expression ]]

go环境搭建

本方法在centos系列系统中实用,其余系统暂没有测试过!

  • 下载go的tar文件并解压
cd /opt && wget https://go.dev/dl/go1.17.5.linux-amd64.tar.gz
tar zxvf go1.17.5.linux-amd64.tar.gz
[ -f go1.17.5.linux-amd64.tar.gz ] && rm go1.17.5.linux-amd64.tar.gz -rf
  • 设置环境变量
echo "" >> /etc/profile
echo "##go 环境变量设置" >> /etc/profile
echo "export GOPATH=/opt/go" >> /etc/profile
echo "export PATH=\$PATH:\$GOPATH/bin" >> /etc/profile
echo 'export GOPROXY="https://goproxy.cn"' >> /etc/profile
echo "export GO111MODULE=on" >> /etc/profile
source /etc/profile