docker-compose安裝gogs,實現GitHub代碼版本管理服務

gogs簡介

因爲GitHub私服須要錢,因此本身搭建了相似GitHub的代碼版本管理系統。java

 

docker-compose方式來安裝gogs   

經過docker-compose方式來安裝gogs,好處是方便管理。如下是從剛裝好Centos Linux系統的環境,開始操做:mysql

一、docker環境安裝、啓動該docker

#docker安裝
yum -y install docker-io
#docker啓動
service docker start

tip1:若是docker沒啓動,執行docker ps命令,出現如下問題linux

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

執行 service docker start 命令,啓動docker服務,便可,可執行docker ps檢查git

tip2:若是服務器會斷電,建議設置docker隨Linux啓動後自動啓動服務,避免服務不可用github

systemctl enable docker.service

 

二、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

 

三、建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編輯文件的時候出現sql

E325:ATTENTION

這是因爲在編輯該文件的時候異常退出了,由於vim在編輯文件時會建立一個交換文件swap file以保證文件的安全性。docker

解決辦法:爲了去掉這個警告,咱們須要刪除這個swp文件:數據庫

rm -f .config.swp

 

tip2:若是有服務層級權限問題,須要調整SELinux狀態vim

[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)

 

四、啓動gogs服務,此處須要注意gogs依賴的數據庫必須是utf8編碼

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

啓動成功!

 

五、配置gogs

上圖圈住的須要注意

 

六、來到這個界面,表示已經搭建好了

七、接下來是gogs基本使用

註冊用戶  ==》  新建倉庫 

 

倉庫設置

 

須要把團隊成員帳號加入「管理協做者」,不然,他們不能push代碼

 

若是不在協做者範圍內,會報以下錯:

 

如下協助開發項目提交記錄

至此,整個gogs搭建完成了

 

接下來繼續介紹idea使用git進行項目管理的過程

一、安裝git客戶端,一直默認安裝便可

 

二、安裝成功後,隨便找個目錄能看到

 

三、右鍵Git Bash Here,設置用戶名、密碼、密鑰

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


二  生成SSH密鑰過程
一、查看是否已經有了ssh密鑰:cd ~/.ssh
若是沒有密鑰則不會有此文件夾,有則備份刪除。
二、生存密鑰
 ssh-keygen -t rsa -C "xxx@xxx.com"

命令執行完後,在~/.ssh目錄下會看到id_rsa、id_rsa.pub文件。

四、在gogs頁面,用戶設置-SSH密鑰,而後配置密鑰,便可

五、git客戶端拉代碼

拷貝git地址,而後在git客戶端執行clone命令

六、在idea上push代碼,如遇如下問題,則按下面方法處理

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

解決辦法

在git bash中輸入命令

git config --global ssh.variant ssh

 

大功告成~

相關文章
相關標籤/搜索