1. 安装MySQL数据库
-
查看是否已经安装,显示为空进入下一步
dpkg -l | grep mysql
-
开始安装,Y/n时选择Y
apt install mysql-server
-
查看是否安装成功,出现mysqld说明安装成功已开始运行
netstat -tap | grep mysql
-
数据库安全配置
root@gitserver:~# mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? ##启用密码验证插件 Press y|Y for Yes, any other key for No: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 Please set the password for root here. ## 设置新密码 New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y ## 删除匿名用户 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? (Press y|Y for Yes, any other key for No) : yes 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? (Press y|Y for Yes, any other key for No) : 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. ## 删除测试数据库机器访问权限 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. ## 刷新权限表使配置立即生效 Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
2. 下载GOGS
-
切换到自己要安装GOGS的目录,下载GOGS并解压
我这里使用的是目前最新的版本,查找最新版本可以到dl.gogs.iowget https://dl.gogs.io/0.12.1/gogs_0.12.1_linux_amd64.tar.gz
-
解压gogs
tar -xvf gogs_0.12.1_linux_amd64.tar.gz
-
赋予gogs目录权限
sudo chown -R git:git gogs
-
数据库的配置,使用gogs自带的script里面的mysql完成数据库的配置
## 在数据库中创建一个gogs用户,赋予权限并刷新,注意密码需要符合自己设置的密码规则 create user 'gogs'@'localhost' identified by 'gogspassword'; grant all privileges on gogs.* to 'gogs'@'localhost';
切换到gogs/script下运行
mysql -u root -p < mysql.sql
-
进入gogs目录,运行gogs
./gogs web
-
访问ip:3000/install,完成初次安装,第一个注册的用户默认为系统管理员
-
出现无法写log权限不够的情况,请sudo chown -R git:git gogs
-
配置gogs为系统服务,设置自启动
## 使用root复制文件 cp /gogs/script/init/centos/gogs /etc/init.d ## 需要修改一下gogs文件的配置,设置工作路径 ## cd到init.d目录 赋予权限并添加到自启动服务中 chmod 755 gogs ## 99代表启动顺序,可以改变 update-rc.d gogs defaults 99 ## 如果需要取消自启动 sudo update-rc.d -f gogs remove
-
gogs的管理
service gogs { start|stop|status|restart|force-reload}