最近公司将服务器上云,将服务器操作系统采用了CentOS系统,顺便搭建了公司自己的源代码管理服务器GitLab,本文记录一下搭建过程,以便后续查阅。
1、安装依赖包
yum install -y curl policycoreutils-python openssh-server
2、设置 SSH 开机自启动并启动 SSH 服务
systemctl enable sshd systemctl start sshd
3、安装 Postfix
1.安装 yum install -y postfix 如出现下面提示,则代表该服务已经安装了。
2.执行以下命令,设置 Postfix 服务开机自启动 systemctl enable postfix 查看postfix服务状态 systemctl status postfix
这步如果报错:
Sep 27 13:47:15 test.novalocal aliasesdb[1912]: /usr/sbin/postconf: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file... directory Sep 27 13:47:15 test.novalocal aliasesdb[1912]: /usr/bin/newaliases: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object fil... directory Sep 27 13:47:15 test.novalocal postfix[1919]: /usr/sbin/postfix: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: N... directory Sep 27 13:47:15 test.novalocal systemd[1]: postfix.service: control process exited, code=exited status=127 Sep 27 13:47:15 test.novalocal systemd[1]: Failed to start Postfix Mail Transport Agent.
可能是因为卸载了mariadb造成的,可以再安装一下
yum install -y dovecot mariadb-server dovecot-mysql
3.打开 Postfix 的配置文件 main.cf vi /etc/postfix/main.cf 按 i 进入编辑模式,删除 inet_interfaces = all 前的 #,在 inet_interfaces = localhost 前加上 #。
4.重启postfix systemctl start postfix systemctl restart postfix
4、执行以下命令,添加 GitLab 软件包仓库
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
5、安装 GitLab
sudo EXTERNAL_URL=“实例公网 IP 地址” yum install -y gitlab-ce
安装的版本:gitlab-ce.x86_64 0:15.3.1-ce.0.el7 安装成功,注意整个安装后,gitLab占了大概有接近3G空间。 完成安装后,你需要设置external_url(如上图说明); vi /etc/gitlab/gitlab.rb; 修改文件中的 external_url=http://192.168.XX.XX”,#你安装软件的服务器 IP ADDR; 然后执行命令: gitlab-ctl reconfigure
5.1修改默认端口号
第一步:修改/etc/gitlab/gitlab.rb文件,如果有如下参数直接修改,如果没有就新增
nginx['listen_port'] = 8088
第二步:修改默认的gitlab nginx的web服务80端 /var/opt/gitlab/nginx/conf/gitlab-http.conf
server { ## HTTPS server listen *:8088;
第三步:初始化并重启组件:
gitlab-ctl reconfigure gitlab-ctl restart
6、设置管理员账号密码
1.获取管理员帐户默认密码 cat /etc/gitlab/initial_root_password
你可以看到 Password:后面的内容就是管理员用户 root 的密码; 访问gitlab 的服务页面,注意:最新版访问地址,直接就是80端口就可以访问了。 http://192.168.2.248; 会出现如下登录页面: ,用户名用 root,密码用上面命令显示的密码登录; 进入后最好更新密码。
用户名用 root,密码用上面命令显示的密码登录;进入后最好更新密码。
7、更改默认的仓库存储目录
默认安装时,默认的仓库存储路径在 /var/opt/gitlab/git-data目录下,仓库存储在子目录repositories里面,可以通过修改/etc/gitlab/gitlab.rb文件中git_data_dirs参数来自定义父目录。 vi /etc/gitlab/gitlab.rb
把该注释打开,使用自己的数据盘路径即可。
没有数据下,我们可以这样操作 先关闭应用,然后再重载一下配置,最后启动。 启动:gitlab-ctl start 关闭:gitlab-ctl stop 重启:gitlab-ctl restart 重载配置:gitlab-ctl reconfigure 查看状态:gitlab-ctl status
8、创建Project
1、安装Git工具 centos:安装Git,使用自带的源安装。 yum install -y git
2、生成密钥文件 使用ssh-keygen生成密钥文件**.ssh/id_rsa.pub**。
[root@test local]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:66kFPQg5L+O5EUBC5dyIUlZzyxD/tn+T5zGwNWCF9fs root@test.novalocal The key's randomart image is: +---[RSA 2048]----+ |o.=o=.. oo | | =+ oB . .. . | |...++.+ o .| |. . + + . . .| | + + S . o. | | . = o + + ..| | + + ..o E| | o o o + .o | | . ..o .. +. | +----[SHA256]-----+
获取SSHKEY 公钥 cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnxr79U+gHxvM9Byg/VdZCi7oSk8zEWtJJ8glj+276fj0R4GuMertetQFaqDeuAeSlGi9sUtYCrLLxixJVlc4yAH3yyqCLv+8H3ORP9vaO/cq05NOMOBxwmkMqvuODh0CHdYo18ECcLm8fIP3T8R0daaSISqg3RyPQLbLppfw3F9/JezsjEBa5myRCe/7e8w/0I+LuLJAd1zwRHYe1svpVW5fkuvWB6SkqIB3d90gCVSYx2GXwkQw8Bxuy4Z4zbohmcQVyTv2jPouBJ/VBMGSy3/ryS9DnUhXwzccroOfDAc9ymTS+rLW6ClxW74IGdq3X7Y6o56o6ufo0jbKyYF5J root@test.novalocal
3、在GitLab的主页中新建一个Project 在页面上选择 new project 按钮,进入如下页面,可以根据需要创建项目; 我选择了 Create from template 创建项目,这样,创建的项目会默认有项目基础代码。
选择了用Spring template 创建项目,输入项目名称后点击 Create Project;
4、添加ssh key 选择新建的项目,导入步骤2中生成的密钥文件内容:
选择 Add SSH key,在如下画面中输入步骤的密钥内容,完成 Add SSH Key;
ssh key添加完成:
5、点击项目,查看ssh地址和http地址
项目地址,该地址在进行clone操作时需要用到:
9、简单配置
1、配置使用Git仓库的人员姓名 git config --global user.name “root” 2、配置使用Git仓库的人员email 填写自己的邮箱 git config --global user.email “support@test.com” 3、克隆项目 在本地生成同名目录,并且目录中会有所有的项目文件 mkdir /root/wkspace & cd /root/wkspace 执行如下命令,获取项目auto001 的代码; git clone http://192.168.19.50/gitlab-instance-51b259bf/auto001.git 执行后会有 /root/wkspace/auto001 目录,目录下放了项目的资源及代码;
10、上传文件
1、创建目录,并进入到项目目录 cd /root/wkspace/auto001/src/test 2、创建需要上传到GitLab中的目标文件 echo “test” > test.sh 3、查看文件是否产生在当前目录下:
4、将test.sh文件加入到索引中 git add test.sh 5、将test.sh提交到本地仓库 git commit -m “test.sh”
6、将文件同步到GitLab服务器上 git push -u origin master
7、查看代码 在网页中查看上传的test.sh文件已经同步到GitLab中
至此,完成了Gitlab 部分的安装与配置,当然,后续多用户使用,需要为每个用户建议自己的用户 ID、密码、凭证等,参考上面的做法。