title: Go 开发环境搭建
date: 2021-08-27 11:33:00
toc: true
category:
- Golang
tags: - Go
- Golang
- 开发
- 环境
- 搭建
本文基于 Centos7.8 介绍了常见的开发环境工具的搭建流程及命令。
git 安装#
-
安装:
yum install -y git配置:
git config --global user.name "biuaxia" git config --global user.email "[email protected]" git config --global --list -
查看有无 sshKey:
ls -al ~/.ssh -
生成 sshKey:
ssh-keygen -t ed25519 -C "[email protected]" -
拷贝 sshKey 到剪贴板 (粘贴到 Github 账户配置):
cat ~/.ssh/id_ed25519.pub -
验证 git 配置:
git clone [email protected]:biuaxia/Sardine.git test/1 -
删除 git clone 的文件夹:
rm -rf ~/test/
dockers 和 docker-compose 安装#
docker 安装#
- 安装:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun - 开启
docker: systemctl start docker - 设置开机启动:
docker: systemctl enable docker - 检查是否启动:
ps -ef|grep docker - 检查能否执行:
docker ps -a - 配置容器镜像加速 (访问 https://cr.console.aliyun.com/cn-hangzhou/instances, 左侧
镜像工具-镜像加速器) - 查看能否加速:
sudo docker run --name he hello-world - 删除容器:
docker rm he - 删除镜像:
docker rmi hello-world
docker-compose 安装#
- 安装:
curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-uname -s-uname -m> /usr/local/bin/docker-compose - 授权:
chmod +x /usr/local/bin/docker-compose
MySQL 安装#
-
安装:
docker pull mysql:5.7 -
检查:
docker images -
运行:
docker run -p 3306:3306 --name mysql57 -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7注意:所有可选参数前者是指容器,后者是指宿主机。例如:
-v $PWD/logs:/logs是指将容器当前目录下的 logs 目录挂载到宿主机的 /logs 目录。 -
检查:
docker ps -a -
日志:
docker logs mysql57 -
进入:
docker exec -it mysql57 /bin/bash -
登录:
mysql -uroot -p123456 -
创建新用户及远程登录授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'root' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES; -
查询:
select user,host from user; -
退出 MySQL:
exit -
退出容器:
exit -
放行防火墙或安全组规则
来源 协议端口 0.0.0.0/0 TCP:3306 ::/0 TCP:3306 -
通过数据库连接工具链接,如 Navicat for MySQL。