docker-compose安装gogs,实现GitHub代码版本管理服务

gogs简介

由于GitHub私服需要钱,所以自己搭建了类似GitHub的代码版本管理系统。

 

docker-compose方式来安装gogs   

通过docker-compose方式来安装gogs,好处是方便管理。以下是从刚装好Centos Linux系统的环境,开始操作:

1、docker环境安装、启动该docker

#docker安装
yum -y install docker-io
#docker启动
service docker start

tip1:如果docker没启动,执行docker ps命令,出现以下问题

“Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?”

执行 service docker start 命令,启动docker服务,即可,可执行docker ps检查

tip2:如果服务器会断电,建议设置docker随Linux启动后自动启动服务,避免服务不可用

systemctl enable docker.service

 

2、docker-compose安装

安装 Docker Compose
#使用命令从Github下载docker-compose可执行程序并到/usr/local/bin目录中,并赋予可执行权限
#下载		
curl -L "https://github.com/docker/compose/releases/download/1.8.1/docker-compose-$(uname -s)-$(uname -m)" > /usr/local/bin/docker-compose
#赋权
chmod +x /usr/local/bin/docker-compose
#执行了上面两个命令,再测试Docker Compose是否工作
docker-compose -v
输出的结果:docker-compose version 1.8.1, build 878cff1

 

3、建gogs目录,配置编排文件

 

[root@localhost docker]# mkdir gogs
[root@localhost docker]# cd gogs/
[root@localhost gogs]# touch docker-compose.yml
[root@localhost gogs]# pwd
/data/docker/gogs
[root@localhost gogs]# cat docker-compose.yml 
gogs:
  image: docker.io/gogs/gogs:latest
  links:
    - mysql-gogs:mysql
  ports:
    - "10022:22"
    - "10080:3000"
  volumes:
    - /opt/docker/gogs/:/data/docker/gogs
  restart: always

mysql-gogs:
  image: docker.io/mysql:5.7.7
  ports:
    - "3306:3306"
  volumes:
    - ./mysql-gogs/mysql:/var/lib/mysql
    - ./mysql-gogs/conf.d:/etc/mysql/conf.d:rw
  environment:
    - MYSQL_DATABASE=gogs
    - MYSQL_USER=gogs
    - MYSQL_PASSWORD=gogs
    - MYSQL_ROOT_PASSWORD=*****
  command: mysqld --lower_case_table_names=1 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
  restart: always

tip1:如果vi编辑文件的时候出现

E325:ATTENTION

这是由于在编辑该文件的时候异常退出了,因为vim在编辑文件时会创建一个交换文件swap file以保证文件的安全性。

解决办法:为了去掉这个警告,我们需要删除这个swp文件:

rm -f .config.swp

 

tip2:如果有服务层级权限问题,需要调整SELinux状态

[root@localhost mysql]# docker-compose up -d db
Recreating mysql_db_1
WARNING: Service "db" is using volume "/var/lib/mysql" from the previous container. Host mapping "/data/docker/mysql/online_backup/mysql" has no effect. Remove the existing containers (with `docker-compose rm db`) to use the host volume mapping.
[root@localhost mysql]# docker-compose logs -f db
Attaching to mysql_db_1
db_1  | my_print_defaults: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)
db_1  | my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
db_1  | my_print_defaults: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)
db_1  | my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
db_1  | mkdir: cannot create directory `': No such file or directory
mysql_db_1 exited with code 1
[root@localhost mysql]# getenforce 
Enforcing
[root@localhost mysql]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 


[root@localhost mysql]# setenforce 0
[root@localhost mysql]# getenforce 
Permissive

解决后,再reboot服务器,然后重启就OK了

[root@localhost mysql]# reboot
Connection closing...Socket close.
[root@localhost mysql]# docker-compose up -d db
Starting mysql_db_1
[root@localhost mysql]# docker-compose logs -f db
Attaching to mysql_db_1
db_1  | my_print_defaults: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)
db_1  | my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
db_1  | my_print_defaults: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)
db_1  | my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
db_1  | mkdir: cannot create directory `': No such file or directory
db_1  | 2019-03-06T10:05:45.482470Z 0 [Note] mysqld (mysqld 5.7.7-rc) starting as process 1 ...
db_1  | 2019-03-06T10:05:45.486804Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1  | 2019-03-06T10:05:45.486831Z 0 [Note] InnoDB: Uses event mutexes
db_1  | 2019-03-06T10:05:45.486838Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1  | 2019-03-06T10:05:45.486844Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.7
db_1  | 2019-03-06T10:05:45.486849Z 0 [Note] InnoDB: Using Linux native AIO
db_1  | 2019-03-06T10:05:45.487165Z 0 [Note] InnoDB: Number of pools: 1
db_1  | 2019-03-06T10:05:45.487296Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1  | 2019-03-06T10:05:45.488593Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1  | 2019-03-06T10:05:45.506265Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1  | 2019-03-06T10:05:45.508645Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1  | 2019-03-06T10:05:45.509929Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1  | 2019-03-06T10:05:45.528752Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1  | 2019-03-06T10:05:45.528883Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1  | 2019-03-06T10:05:45.571396Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1  | 2019-03-06T10:05:45.577365Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1  | 2019-03-06T10:05:45.577395Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1  | 2019-03-06T10:05:45.577943Z 0 [Note] InnoDB: Waiting for purge to start
db_1  | 2019-03-06T10:05:45.632498Z 0 [Note] InnoDB: 5.7.7 started; log sequence number 11842136
db_1  | 2019-03-06T10:05:45.632794Z 0 [Note] InnoDB: Loading buffer pool(s) from .//ib_buffer_pool
db_1  | 2019-03-06T10:05:45.634280Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1  | 2019-03-06T10:05:45.639235Z 0 [Warning] Failed to setup SSL
db_1  | 2019-03-06T10:05:45.639271Z 0 [Warning] SSL error: SSL context is not usable without certificate and private key
db_1  | 2019-03-06T10:05:45.639297Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1  | 2019-03-06T10:05:45.640759Z 0 [Note] IPv6 is available.
db_1  | 2019-03-06T10:05:45.640798Z 0 [Note]   - '::' resolves to '::';
db_1  | 2019-03-06T10:05:45.640830Z 0 [Note] Server socket created on IP: '::'.
db_1  | 2019-03-06T10:05:45.641430Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190306 10:05:45
db_1  | 2019-03-06T10:05:45.669083Z 0 [Note] Event Scheduler: Loaded 0 events
db_1  | 2019-03-06T10:05:45.669228Z 0 [Note] mysqld: ready for connections.
db_1  | Version: '5.7.7-rc'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

 

4、启动gogs服务,此处需要注意gogs依赖的数据库必须是utf8编码

[root@localhost gogs]# docker-compose up -d gogs
Creating gogs_mysql-gogs_1
Recreating gogs_gogs_1

47a9c5709a59a9eab4fff0e5a2caf91ea8c.jpg

启动成功!

 

5、配置gogs

1ff993703551dc19054169f2ac43eff42de.jpg

上图圈住的需要注意

 

6、来到这个界面,表示已经搭建好了

89c22c8891d5a519ff9211bc0285cae7a0e.jpg

7、接下来是gogs基本使用

注册用户  ==》  新建仓库 

 

仓库设置

b9af3231c2d19f68b47a6b5342ed51b6723.jpg

 

需要把团队成员账号加入“管理协作者”,否则,他们不能push代码

 e6f2650af9725a236ad589c804b1b081141.jpg

如果不在协作者范围内,会报如下错:

04943f0224d787954f82bba7e62f7be1525.jpg

 

以下协助开发项目提交记录

2ee6a745e0b64248c9f00558e592a2a7847.jpg

至此,整个gogs搭建完成了

 

接下来继续介绍idea使用git进行项目管理的过程

1、安装git客户端,一直默认安装即可

cbe583b69a6cad1479108b214702d3f3bef.jpg

 

2、安装成功后,随便找个目录能看到

56f741effbdc682bd2b5d9762310531b3f6.jpg

 

3、右键Git Bash Here,设置用户名、密码、密钥

一 设置Git的user name和email
git config --global user.name "xxx"
git config --global user.email "xxx@xxx.com"


二  生成SSH密钥过程
1、查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除。
2、生存密钥
 ssh-keygen -t rsa -C "xxx@xxx.com"

命令执行完后,在~/.ssh目录下会看到id_rsa、id_rsa.pub文件。

956b4e7fb157856e4fcce2289a8a60a4f0e.jpg

4、在gogs页面,用户设置-SSH密钥,然后配置密钥,即可

e97f0a14cb6f69450d6632ed415f1bc3a19.jpg

5、git客户端拉代码

6d76b2670948a38ebc57a2e659f582c5450.jpg

拷贝git地址,然后在git客户端执行clone命令

8ea7337419d4eac44d960fb001c8e034816.jpg

6、在idea上push代码,如遇以下问题,则按下面方法处理

git报ssh variant 'simple' does not support setting port

解决办法

在git bash中输入命令

git config --global ssh.variant ssh

 

大功告成~

转载于:https://my.oschina.net/xsh1208/blog/3019458

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值