课程需要用到的开发环境介绍

2. 开发环境 - 图2

Git-Linux

  1. yum install git
  2. y
  3. y
  4. git config --global user.name "Jeff"
  5. git config --global user.email "wjajeff@qq.com"
  6. git config --global --list

Docker-Linux

1. 安装Docker

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

2. 设置开机启动Docker

systemctl start docker #启动docker
systemctl enable docker
docker ps -a
ps -ef|grep docker
systemctl start docker(root)
ps -ef|grep docker
docker ps -a

3. 配置阿里云镜像

3.1 登录阿里云

image.png
image.png

3.2 进入控制台

image.png
image.png
image.png

3.3 修改配置文件daemon.json

--Centos
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://47salziq.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

4. 启动

sudo systemctl start docker

5. 测试

sudo docker run hello-world
[root@localhost ~]# sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

The Docker client contacted the Docker daemon.
The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

Docker-compose

1. 安装

curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose
[root@localhost ~]# curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   423  100   423    0     0     86      0  0:00:04  0:00:04 --:--:--    91
100 16.2M  100 16.2M    0     0   552k      0  0:00:30  0:00:30 --:--:-- 3565k

2. 测试

docker-compose -v
[root@localhost ~]# docker-compose -v
docker-compose version 1.25.0, build 0a186604

Mysql

1. 下载镜像

docker pull mysql:5.7

2. 通过镜像启动

docker run -p 3306:3306 --name mymysql -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
-p 3306:3306:将容器的 3306 端口映射到主机的 3306 端口。

-v -v $PWD/conf:/etc/mysql/conf.d:将主机当前目录下的 conf/my.cnf 挂载到容器的 /etc/mysql/my.cnf。

-v $PWD/logs:/logs:将主机当前目录下的 logs 目录挂载到容器的 /logs。

-v $PWD/data:/var/lib/mysql :将主机当前目录下的data目录挂载到容器的 /var/lib/mysql 。

-e MYSQL_ROOT_PASSWORD=123456:初始化 root 用户的密码。

3. 进入容器配置

由于mysql的安全策略,现在还不能使用root/123456来访问数据库

3.1 进入容器

通过docker ps -a来查看mysql的容器id然后使用:

[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS                     PORTS     NAMES
3a9f972fd40b   hello-world   "/hello"                 6 minutes ago   Exited (0) 6 minutes ago             ecstatic_darwin
1f21d46cc8f6   mysql:5.7     "docker-entrypoint.s…"   8 days ago      Exited (0) 7 days ago                mymysql
221a1edc6490   hello-world   "/hello"                 8 days ago      Exited (0) 8 days ago                exciting_jones
docker exec -it 3a9f972fd40b /bin/bash

3.2 进入mysql

mysql -uroot -p123456

3.3 建立用户并授权

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;

Navicat

https://www.navicat.com.cn/download/navicat-premium
# 自行破解

Python

--Linux Windows Pycharm已装好
提前安装好系统依赖包:
centos: 
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++  openssl-devel libffi-devel python-devel mariadb-devel
ubuntu:
sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev default-libmysqlclient-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev liblzma-dev libffi-dev libc6-dev

1. 获取
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
tar -xzvf Python-3.8.6.tgz -C  /tmp
cd  /tmp/Python-3.8.6/
2. 把Python3.8安装到 /usr/local 目录
./configure --prefix=/usr/local
make
make altinstall
3. 更改/usr/bin/python链接
ln -s /usr/local/bin/python3.8 /usr/bin/python3
ln -s /usr/local/bin/pip3.8 /usr/bin/pip3


版本--3.8.6

虚拟环境

虚拟环境的安装和配置

Windows

pip install virtualenvwrapper-win

mkvirtualenv python_start
rmvirtualenv python_start

mkvirtualenv C:\Users\Wozen\AppData\Local\Programs\Python\Python38\python.exe python_start
C:\WINDOWS\system32>pip install virtualenvwrapper-win
Requirement already satisfied: virtualenvwrapper-win in c:\users\wozen\appdata\local\programs\python\python38\lib\site-packages (1.2.7)
Requirement already satisfied: virtualenv in c:\users\wozen\appdata\local\programs\python\python38\lib\site-packages (from virtualenvwrapper-win) (20.15.1)
Requirement already satisfied: platformdirs<3,>=2 in c:\users\wozen\appdata\local\programs\python\python38\lib\site-packages (from virtualenv->virtualenvwrapper-win) (2.5.2)
Requirement already satisfied: distlib<1,>=0.3.1 in c:\users\wozen\appdata\local\programs\python\python38\lib\site-packages (from virtualenv->virtualenvwrapper-win) (0.3.4)
Requirement already satisfied: six<2,>=1.9.0 in c:\users\wozen\appdata\local\programs\python\python38\lib\site-packages (from virtualenv->virtualenvwrapper-win) (1.16.0)
Requirement already satisfied: filelock<4,>=3.2 in c:\users\wozen\appdata\local\programs\python\python38\lib\site-packages (from virtualenv->virtualenvwrapper-win) (3.7.1)

Linux

安装
yum install python-setuptools python-devel 
pip3 install virtualenvwrapper
pip3 install virtualenvwrapper -i https://pypi.douban.com/simple
[root@localhost ~]# yum install python-setuptools python-devel 

已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.lzu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
软件包 python-setuptools-0.9.8-7.el7.noarch 已安装并且是最新版本
软件包 python-devel-2.7.5-92.el7_9.x86_64 已安装并且是最新版本
无须任何处理
[root@localhost ~]# pip3 install virtualenvwrapper

Requirement already satisfied: virtualenvwrapper in /usr/local/lib/python3.8/site-packages (4.8.4)
Requirement already satisfied: virtualenv in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (20.15.1)
Requirement already satisfied: virtualenv-clone in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (0.5.7)
Requirement already satisfied: stevedore in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (3.5.0)
Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /usr/local/lib/python3.8/site-packages (from stevedore->virtualenvwrapper) (5.9.0)
Requirement already satisfied: platformdirs<3,>=2 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (2.5.2)
Requirement already satisfied: six<2,>=1.9.0 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (1.16.0)
Requirement already satisfied: distlib<1,>=0.3.1 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (0.3.4)
Requirement already satisfied: filelock<4,>=3.2 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (3.7.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[root@localhost ~]# pip3 install virtualenvwrapper -i https://pypi.douban.com/simple

Looking in indexes: https://pypi.douban.com/simple
Requirement already satisfied: virtualenvwrapper in /usr/local/lib/python3.8/site-packages (4.8.4)
Requirement already satisfied: virtualenv in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (20.15.1)
Requirement already satisfied: virtualenv-clone in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (0.5.7)
Requirement already satisfied: stevedore in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (3.5.0)
Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /usr/local/lib/python3.8/site-packages (from stevedore->virtualenvwrapper) (5.9.0)
Requirement already satisfied: filelock<4,>=3.2 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (3.7.1)
Requirement already satisfied: six<2,>=1.9.0 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (1.16.0)
Requirement already satisfied: distlib<1,>=0.3.1 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (0.3.4)
Requirement already satisfied: platformdirs<3,>=2 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (2.5.2)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

配置

编辑.bashrc文件 vim ~/.bashrc

export WORKON_HOME=$HOME/.virtualenvs   
source /usr/local/bin/virtualenvwrapper.sh #这里不同的linux系统
virtualenvwrapper.sh路径可能不一致,最好通过find命令查询一下

退出vim后运行下面命令重新加载

source  ~/.bashrc

虚拟环境使用

1. 新建虚拟环境

mkvirtualenv python_start

2. 查看所有虚拟环境

workon

3. 进入指定虚拟环境

workon python_start

Go

go的安装和配置

Windows

https://proxy.golang.com.cn,direct
下载直接安装     
官方地址下载安装即可 
go fmt 和goimports保存后自动格式化
settings -> tools -> file watchers

Linux

1. 下载
2. 解压
  tar -xvf go1.15.3.linux-amd64.tar.gz
3. 配置环境变量
  vim ~/.bashrc

    export GOROOT=/root/go
    export GOPATH=/root/projects/go
    export PATH=$PATH:$GOROOT/bin:$GPPATH/bin
4. 编辑保存并退出vim后,记得把这些环境载入:source ~/.bashrc

设置代理加速

go env -w GOPROXY=https://goproxy.io,direct
go env -w GO111MODULE=on

GoLand的安装

https://www.jetbrains.com/go/download/#section=windows

直接下载安装即可

go imports和go fmt

image.png

文件->设置->工具->保存时的操作 or 文件->设置->File Watcher 
看个人喜好自行选择
go fmt 和goimports保存后自动格式化

nodejs的安装和配置

Windows

下载

从官网下下载最新的nodejs,https://nodejs.org/en/download/,根据自身的操作系统选择下载对应版本

:::tips 正常下一步安装即可,记得选择安装路径 :::

image.png

Linux

Date: 2022-07-12

1. 下载

wget https://nodejs.org/dist/v16.15.1/node-v16.15.1-linux-x64.tar.xz

2. 解压和建立软连接

tar -xvf node-v16.15.1-linux-x64.tar.xz

3. 建立软连接

一定要先找到node可执行文件的完整路径比如我这里

[root@localhost bin]# pwd
/root/node-v16.15.1-linux-x64/bin
ln -s /root/node-v16.15.1-linux-x64/bin/node /usr/bin/node
ln -s /root/node-v16.15.1-linux-x64/bin/npm /usr/bin/npm

注意ln指令用于创建关联(类似与Windows的快捷方式)必须给全路径,否则可能关联错误。

5. 测试

node -v

[root@localhost bin]# node -v
v16.15.1

6. 安装cnpm

npm install -g cnpm --registry=http://registry.npmmirror.com

[root@localhost bin]# npm install -g cnpm --registry=http://registry.npmmirror.com
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

added 346 packages in 45s

11 packages are looking for funding
run `npm fund` for details
npm notice 
npm notice New minor version of npm available! 8.11.0 -> 8.13.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.13.2
npm notice Run npm install -g npm@8.13.2 to update!
npm notice