Gogs的网页界面和GitHub十分相近,并提供MySQL,PostgreSQL和SQLite数据库支持。gogs具有轻量级、易安装、跨平台的优点。
https://gogs.io # go语言开发的git服务器;
https://www.percona.com/downloads/ #mysql咨询和软件包装,比mysql性能强
http://vault.centos.org/ # centos 文件下载
所需环境
•系统:Linux \ Centos 7.4-1708
•数据库:MySQL Percona-Server-5.5.45-37.4-r042e02b-el6-x86_64-bundle.tar
•反向代理:nginx
•git
•gogs gogs_0.11.66_linux_amd64.tar.gz
git
yum install git -y
1. MySQL安装
Percona-Server-5.5.45-37.4-r042e02b-el6-x86_64-bundle.tar
# tar xf 解压
tar xf Percona-Server-5.5.45-37.4-r042e02b-el6-x86_64-bundle.tar
# 按照顺序安装包 share-server-client;
yum install Percona-Server-shared-55-5.5.45-rel37.4.el6.x86_64.rpm Percona-Server-server-55-5.5.45-rel37.4.el6.x86_64.rpm Percona-Server-client-55-5.5.45-rel37.4.el6.x86_64.rpm
# 查看etc/init.d/目录下安装好的mysql
[root@centos7 Desktop]# cd /etc/init.d/
[root@centos7 init.d]# ll
total 52
-rw-r--r--. 1 root root 18281 Aug 24 2018 functions
-rwxr-xr-x. 1 root root 11056 Aug 31 2015 mysql # 数据库安装好了;
-rwxr-xr-x. 1 root root 4569 Aug 24 2018 netconsole
-rwxr-xr-x. 1 root root 7923 Aug 24 2018 network
-rw-r--r--. 1 root root 1160 Oct 31 2018 README
# 启动数据库
[root@centos7 init.d]# service mysql start
Starting MySQL (Percona Server).. SUCCESS!
# 查看端口:3306所有的地址都可以用
[root@centos7 init.d]# ss -tanl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:6000 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::6000 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
# mysql安全安装
[root@centos7 init.d]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
# 设置密码
Set root password? [Y/n] y
New password:
Re-enter new password:
Sorry, you can't use an empty password here.
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
# 移除其他用户
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
# 是否禁止远程登陆/否
Disallow root login remotely? [Y/n] n
... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
# 要不要一处test库文件
Remove test database and access to it? [Y/n]
# 要不要刷新权限;要,要是万一不能用了不就麻烦了吗
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
2. MySQL配置
# 现在直接敲 mysql就不能这样用了;
[root@centos7 init.d]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# root账户登录;
[root@centos7 init.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.5.45-37.4 Percona Server (GPL), Release 37.4, Revision 042e02b
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases; # 查看数据据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql | # 系统库,由管理员权限从才可以看到;
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
3. win本地查看登录虚拟机IP
常见的私网IP有 192.168.0.X ,192.168.1.1,172.16.X.X,10.X.X.X 这样的IP地址当初就规定好了,在公网上是看不到的,是不会分配给用户的。
NAT(Network Address Translation)是网络地址转换,它实现内 拓扑结构 网的IP地址与公网的地址之间的相互转换,将大量的内网IP地址转换为一个或少量的公网IP地址,减少对公网IP地址的占用。NAT的最典型应用是:在一个局域网内,只需要一台计算机连接上Internet,就可以利用NAT共享Internet连接,使局域网内其他计算机也可以上网。使用NAT协议,局域网内的计算机可以访问Internet上的计算机,但Internet上的计算机无法访问局域网内的计算机。
简单粗暴式:在Bash中直接输入ifconfig
//查看本地IP地址
[root@centos7 init.d]# ifconfig | grep -w inet | awk '{ print $2}'
192.168.116.130 # 虚拟机中IP地址;
127.0.0.1
192.168.122.1
[root@centos7 init.d]# ip a s | grep -w inet | awk '{ print $2}'
127.0.0.1/8
192.168.116.130/24
192.168.122.1/24
[root@centos7 init.d]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.116.130 netmask 255.255.255.0 broadcast 192.168.116.255
inet6 fe80::31da:42e9:edf2:898a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:78:f3:fe txqueuelen 1000 (Ethernet)
RX packets 23503 bytes 34721214 (33.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3381 bytes 224379 (219.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 324 bytes 37236 (36.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 324 bytes 37236 (36.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:46:d2:ed txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
4. 账户配置
[root@centos7 /]# useradd git # 添加一个git账户;
[root@centos7 /]# id git # 查看账户属主、属组
uid=1001(git) gid=1001(git) groups=1001(git)
#安装gogs(gogs是对外的,安装过gogs权限太大不好); 转换用户git;
[root@centos7 /]# su git # 到git用户下;
[git@centos7 home]$ cd git/
[git@centos7 ~]$ ll
total 19932
-rwxrw-rw-. 1 dell root 20407040 Jan 14 2019 gogs_0.11.66_linux_amd64.tar.gz
[git@centos7 ~]$ tar xf gogs_0.11.66_linux_amd64.tar.gz
[git@centos7 ~]$ ll
total 19932
drwxr-xr-x. 5 git git 116 Sep 17 2018 gogs
-rwxrw-rw-. 1 dell root 20407040 Jan 14 2019 gogs_0.11.66_linux_amd64.tar.gz
[git@centos7 ~]$ cd gogs/ # 直接运行是没有问题的;
[git@centos7 gogs]$ ll
total 36352
-rwxr-xr-x. 1 git git 37201803 Sep 17 2018 gogs
-rw-r--r--. 1 git git 1054 Jun 5 2018 LICENSE
drwxr-xr-x. 8 git git 101 Sep 17 2018 public
-rw-r--r--. 1 git git 7978 Sep 17 2018 README.md
-rw-r--r--. 1 git git 5278 Sep 17 2018 README_ZH.md
drwxr-xr-x. 7 git git 195 Sep 17 2018 scripts
drwxr-xr-x. 11 git git 174 Sep 17 2018 templates
配置文件
自定义配置,否则运行缺省配置;
在gogs目录下建立custom/conf/app.ini配置文件
$ mkdir -p custom/conf
$ cd custom/conf
$ touch app.ini
$ vi app.ini
custom/conf/app.ini内容如下
APP_NAME = magedu
RUN_USER = git
RUN_MODE = dev
[server]
HTTP_ADDR = 0.0.0.0
HTTP_PORT = 3000
[database]
DB_TYPE = mysql
HOST = 127.0.0.1:3306
NAME = gogs
USER = gogs
PASSWD = gogs
[security]
INSTALL_LOCK = false
SECRET_KEY = www.magedu.com.(python).GIT:gogs
# 数据库root账户登录,不是系统root;
[git@centos7 conf]$ mysql -u root -p
# /gogs/scripts目录下mysql.sql叫脚本输出重定向 mysql
[root@centos7 scripts]# mysql -uroot -p < mysql.sql
[root@centos7 scripts]# cat mysql.sql
SET GLOBAL innodb_file_per_table = ON,
innodb_file_format = Barracuda,
innodb_large_prefix = ON;
DROP DATABASE IF EXISTS gogs;
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
# 创建一个gogs的库;
[git@Centos7 gogs]$ mysql -uroot -p < scripts/mysql.sql
# 查看数据库,多了一个gogs;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| gogs |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
mysql> use gogs
Database changed
mysql> show tables;
Empty set (0.00 sec)
# 设置数据据库账户密码: % 所有IP地址;
mysql> grant all on gogs.* to 'gogs'@'%' identified by 'gogs';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[git@centos7 conf]$ mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# gogs账户查看数据库;只有gogs,root账户才可以看到mysql系统库;
[git@centos7 conf]$ mysql -u gogs -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.5.45-37.4 Percona Server (GPL), Release 37.4, Revision 042e02b
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 只有gogs,root账户才可以看到mysql系统库;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| gogs |
+--------------------+
2 rows in set (0.00 sec)
5. 启动gogs
gogs呈现绿色(启动中),使用gogs命令启动
$ ./gogs web
但是这样用不方便,使用scripts目录下的服务脚本
[git@centos7 gogs]$ ls
custom gogs LICENSE public README.md README_ZH.md scripts templates
[git@centos7 gogs]$ ./gogs web
2020/01/08 21:06:19 [TRACE] Custom path: /home/git/gogs/custom
2020/01/08 21:06:19 [TRACE] Log path: /home/git/gogs/log
2020/01/08 21:06:19 [TRACE] Log Mode: Console (Trace)
2020/01/08 21:06:19 [ INFO] Gogs 0.11.66.0916
2020/01/08 21:06:19 [ INFO] Cache Service Enabled
2020/01/08 21:06:19 [ INFO] Session Service Enabled
2020/01/08 21:06:19 [ INFO] SQLite3 Supported
2020/01/08 21:06:19 [ INFO] Run Mode: Development
2020/01/08 21:06:19 [ INFO] Listen: http://0.0.0.0:3000
6. 访问Gogs(默认端口3000)
root权限下防火墙放行 3000端口访问;
[root@centos7 dell]# firewall-cmd --permanent --add-port=3000/tcp
success
[root@centos7 dell]# firewall-cmd --reload
success
打开浏览器访问本机IP+端口,如下图所示6.
注册一个新账号(第一个用户是管理员);
管理员 用户的面板;
普通用户的管理页面;接下来我们就可以用git来进行项目的版本控制了;
可以看到配置文件中 变成了生产模式prod;
到这里,git私服就搭建成功了!
参考:
Linux 系统问题集锦
1. centos7.2重新安装yum
yum install git -y # 安装软件报错如下;
[root@zf-test-web01-4 ~]# yum install rng-tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
There are no enabled repos.
Run "yum repolist all" to see the repos you have.
You can enable repos with yum-config-manager --enable <repo>
红色部分Loading mirror speeds from cached hostfile问题解决如下:
进入修改 fastestmirror.conf ,把enabled=1改为enabled=0
-bash-4.2# vi /etc/yum/pluginconf.d/fastestmirror.conf
[main]
enabled=0
verbose=0
always_print_best_host = true
socket_timeout=3
# Relative paths are relative to the cachedir (and so works for users as well
# as root).
hostfilepath=timedhosts.txt
maxhostfileage=10
maxthreads=15
#exclude=.gov, facebook
把enabled=1改为enabled=0
蓝色部分There are no enabled repos.,解决办法:
1. 查看centos7.2系统本身所安装的那些yum 软件包
[root@zf-test-web01-4 ~]# rpm -qa|grep yum
yum-plugin-fastestmirror-1.1.31-34.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-3.4.3-132.el7.centos.0.1.noarch
[root@zf-test-web01-4 ~]#
2. 卸载这些软件包
[root@zf-test-web01-4 ~]# rpm -e yum-plugin-fastestmirror-1.1.31-34.el7.noarch --nodeps
warning: /etc/yum/pluginconf.d/fastestmirror.conf saved as /etc/yum/pluginconf.d/fastestmirror.conf.rpmsave
[root@zf-test-web01-4 ~]# rpm -e yum-metadata-parser-1.1.4-10.el7.x86_64 --nodeps
[root@zf-test-web01-4 ~]# rpm -e yum-3.4.3-132.el7.centos.0.1.noarch --nodeps
[root@zf-test-web01-4 ~]#
3. 进入centos镜像网站找到自己对应系统需要的yum包
查看系统的命令:
[root@zf-test-web01-4 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
查看系统的位数:
[root@zf-test-web01-4 ~]# file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=aa7ff68f13de25936a098016243ce57c3c982e06, stripped
http://vault.centos.org/
4. 下载这些yum包
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
5. 安装下载的这些yum包
[root@zf-test-web01-4 ~]# rpm -ivh yum-*
Preparing... ################################# [100%]
Updating / installing...
1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 33%]
2:yum-plugin-fastestmirror-1.1.31-3################################# [ 67%]
3:yum-3.4.3-132.el7.centos.0.1 ################################# [100%]
[root@zf-test-web01-4 ~]#
6. 更新centos系统的repo文件
http://mirrors.163.com/.help/centos.html
1)首先备份/etc/yum.repos.d/CentOS-Base.repo
[root@zf-test-web01-4 yum.repos.d]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2)下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份)
3)运行以下命令生成缓存
[root@zf-test-web01-4 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@zf-test-web01-4 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/12): base/7/x86_64/group_gz | 156 kB 00:00:00
(2/12): base/7/x86_64/filelists_db | 6.7 MB 00:00:01
(3/12): extras/7/x86_64/prestodelta | 71 kB 00:00:00
(4/12): extras/7/x86_64/primary_db | 145 kB 00:00:00
(5/12): extras/7/x86_64/filelists_db | 528 kB 00:00:00
(6/12): extras/7/x86_64/other_db | 97 kB 00:00:00
(7/12): updates/7/x86_64/prestodelta | 589 kB 00:00:00
(8/12): base/7/x86_64/primary_db | 5.7 MB 00:00:01
(9/12): base/7/x86_64/other_db | 2.5 MB 00:00:00
(10/12): updates/7/x86_64/primary_db | 4.5 MB 00:00:00
(11/12): updates/7/x86_64/other_db | 490 kB 00:00:00
(12/12): updates/7/x86_64/filelists_db | 2.7 MB 00:00:01
Determining fastest mirrors
Metadata Cache Created
7. 重新运用yum安装软件,成功;
2.1 系统已经安装其他版本的mysql
file /usr/lib64/mysql/plugin/dialog.so from install of Percona-Server-server-56-5.6.24-rel72.2.el6.x86_64 conflicts with file from package mariadb-libs-1:5.5.60-1.el7_5.x86_64
原因:系统已经安装了其他版本的mysql-libs包和mysql数据库文件导致不兼容。
解决:删除这个数据库
root@centos7 Desktop]# yum remove mysql-libs
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-7.el7 will be erased
--> Finished Dependency Resolution
3. web服务网页访问失败
[root@centos7 dell]# firewall-cmd --permanent --add-port=3000/tcp
success
[root@centos7 dell]# firewall-cmd --reload
success