Gogs 是一款类似GitHub的开源文件/代码管理系统(基于Git),Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自助 Git 服务。使用 Go 语言开发使得 Gogs 能够通过独立的二进制分发,并且支持 Go 语言支持的 所有平台,包括 Linux、Mac OS X、Windows 以及 ARM 平台。 官方网站是:https://gogs.io/,代码管理前台和git后台服务一体化安装部署,使用起来非常方便,下面我将在CentOS 7.5的平台上搭建一个Gogs服务。
-
保证CentOS 7.5最新
sudo yum update -y -
添加git用户( gogs期望用git用户操作 )
创建git账户
sudo useradd git为git账户设置密码
sudo passwd git -
安装MySQL 5.7
-
进入到要存放安装包的位置:
cd /home/lnmp -
查看系统中是否已安装 MySQL 服务,以下提供两种方式:
rpm -qa | grep mysqlyum list installed | grep mysql -
如果已安装则删除 MySQL 及其依赖的包:
yum -y remove mysql-libs.x86_64 -
下载 mysql57-community-release-el7-8.noarch.rpm 的 yum 源:
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm -
安装 mysql57-community-release-el7-8.noarch.rpm:
sudo yum -y install mysql57-community-release-el7-10.noarch.rpm -
安装 MySQL,出现提示的话,一路 Y 到底
sudo yum -y install mysql-community-server安装完毕后,启动mysql
systemctl start mysqld然后在 /var/log/mysqld.log 文件中会自动生成一个随机的密码,我们需要先取得这个随机密码,以用于登录 MySQL 服务端:
sudo cat /var/log/mysqld.log | grep password将会返回如下内容,末尾字符串就是密码,把它复制下来:
A temporary password is generated for root@localhost: aq2yb.KgNdhl -
登录到 MySQL 服务端并更新用户 root 的密码:
注意:由于 MySQL5.7 采用了密码强度验证插件 validate_password,故此我们需要设置一个有一定强度的密码;
mysql -u root -p hilX0U!9i3_6然后更改密码
mysql> alter user 'root'@'localhost' identified by 'new password'; Query OK, 0 rows affected (0.00 sec) mysql> alter user 'root'@'localhost' password expire never; Query OK, 0 rows affected (0.00 sec)设置用户 root 可以在任意 IP 下被访问:
mysql> grant all privileges on *.* to root@'%' identified by 'new password' with grant option;设置用户 root 可以在本地被访问:
mysql> grant all privileges on *.* to root@'localhost' identified by 'new password' with grant option;刷新权限使之生效:
mysql> flush privileges;OK,输入 exit 后用新密码再次登录看看吧!
注意:如果用远程工具还是连接不上,试试用
iptables -F命令来清除防火墙中链中的规则。
-
MySQL控制命令:启动、停止、重启、查看状态
service mysqld start service mysqld stop service mysqld restart service mysqld status systemctl start mysqld service mysqld stop service mysqld restart systemctl status mysqld -
设置 MySQL 的字符集为 UTF-8:
打开 /etc 目录下的my.cnf 文件(此文件是 MySQL 的主配置文件):
sudo vim /etc/my.cnf在 [mysqld] 前添加如下代码:
[client] default-character-set=utf8在 [mysqld] 后添加如下代码:
character_set_server=utf8重启mysql后,再登录,看看字符集,6个utf8就算OK
mysql> show variables like '%character%';+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
-
-
安装Git
sudo yum install git -
安装Gogs
环境都用了就可以下载gogs了。先确定自己的系统是x64还是x86的,或者arm
uname -a下载对应的二进制包(我选的二进制包),下载链接,版本具体都看自己的,如下:
wget https://dl.gogs.io/0.11.34/linux_amd64.tar.gz将安装包解压至git用户目录下(/home/git)并修改其权限和所有者。这一步很重要。路径不能放错,以及修改权限,否则配置gogs也不能用 :
sudo tar -xf linux_amd64.tar.gz -C /home/git sudo chmod -R 700 /home/git/gogs sudo chown -R git:git /home/git/gogs使用git用户运行gogs:
su -git -c "cd /home/git/gogs && ./gogs web &" -
配置Gogs服务
使用vim打开文件/usr/local/src/gogs/scripts/systemd/gogs.service,配置正确的启动参数,包括工作目录和启动用户
User=git Group=git WorkingDirectory=/your/gogs/install/root/path ExecStart=/your/gogs/install/root/path/gogs web Restart=always修改完毕后保存,将服务拷贝至系统服务启动目录
cp /usr/local/src/gogs/scripts/systemd/gogs.service /etc/systemd/system/gogs.service设置开机自启
systemctl enable gogs启动服务试试
systemctl start gogs
Q.E.D.

Comments | 0 条评论