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

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

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

2. 设置开机启动Docker

  1. systemctl start docker #启动docker
  2. systemctl enable docker
  1. docker ps -a
  2. ps -ef|grep docker
  3. systemctl start docker(root)
  4. ps -ef|grep docker
  5. docker ps -a

3. 配置阿里云镜像

3.1 登录阿里云

image.png
image.png

3.2 进入控制台

image.png
image.png
image.png

3.3 修改配置文件daemon.json

  1. --Centos
  2. sudo mkdir -p /etc/docker
  3. sudo tee /etc/docker/daemon.json <<-'EOF'
  4. {
  5. "registry-mirrors": ["https://47salziq.mirror.aliyuncs.com"]
  6. }
  7. EOF
  8. sudo systemctl daemon-reload
  9. sudo systemctl restart docker

4. 启动

  1. sudo systemctl start docker

5. 测试

  1. sudo docker run hello-world
  1. [root@localhost ~]# sudo docker run hello-world
  2. Hello from Docker!
  3. This message shows that your installation appears to be working correctly.
  4. To generate this message, Docker took the following steps:
  5. The Docker client contacted the Docker daemon.
  6. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  7. (amd64)
  8. The Docker daemon created a new container from that image which runs the
  9. executable that produces the output you are currently reading.
  10. The Docker daemon streamed that output to the Docker client, which sent it
  11. to your terminal.
  12. To try something more ambitious, you can run an Ubuntu container with:
  13. $ docker run -it ubuntu bash
  14. Share images, automate workflows, and more with a free Docker ID:
  15. https://hub.docker.com/
  16. For more examples and ideas, visit:
  17. https://docs.docker.com/get-started/

Docker-compose

1. 安装

  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
  2. sudo chmod +x /usr/local/bin/docker-compose
  1. [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
  2. % Total % Received % Xferd Average Speed Time Time Time Current
  3. Dload Upload Total Spent Left Speed
  4. 100 423 100 423 0 0 86 0 0:00:04 0:00:04 --:--:-- 91
  5. 100 16.2M 100 16.2M 0 0 552k 0 0:00:30 0:00:30 --:--:-- 3565k

2. 测试

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

Mysql

1. 下载镜像

  1. docker pull mysql:5.7

2. 通过镜像启动

  1. 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
  2. -p 3306:3306:将容器的 3306 端口映射到主机的 3306 端口。
  3. -v -v $PWD/conf:/etc/mysql/conf.d:将主机当前目录下的 conf/my.cnf 挂载到容器的 /etc/mysql/my.cnf
  4. -v $PWD/logs:/logs:将主机当前目录下的 logs 目录挂载到容器的 /logs
  5. -v $PWD/data:/var/lib/mysql :将主机当前目录下的data目录挂载到容器的 /var/lib/mysql
  6. -e MYSQL_ROOT_PASSWORD=123456:初始化 root 用户的密码。

3. 进入容器配置

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

3.1 进入容器

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

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

3.2 进入mysql

  1. mysql -uroot -p123456

3.3 建立用户并授权

  1. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
  2. GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'root' WITH GRANT OPTION;
  3. GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION;
  4. FLUSH PRIVILEGES;

Navicat

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

Python

  1. --Linux Windows Pycharm已装好
  2. 提前安装好系统依赖包:
  3. centos:
  4. 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
  5. ubuntu:
  6. 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
  7. 1. 获取
  8. wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
  9. tar -xzvf Python-3.8.6.tgz -C /tmp
  10. cd /tmp/Python-3.8.6/
  11. 2. Python3.8安装到 /usr/local 目录
  12. ./configure --prefix=/usr/local
  13. make
  14. make altinstall
  15. 3. 更改/usr/bin/python链接
  16. ln -s /usr/local/bin/python3.8 /usr/bin/python3
  17. ln -s /usr/local/bin/pip3.8 /usr/bin/pip3
  18. 版本--3.8.6

虚拟环境

虚拟环境的安装和配置

Windows

  1. pip install virtualenvwrapper-win
  2. mkvirtualenv python_start
  3. rmvirtualenv python_start
  4. mkvirtualenv C:\Users\Wozen\AppData\Local\Programs\Python\Python38\python.exe python_start
  1. C:\WINDOWS\system32>pip install virtualenvwrapper-win
  2. Requirement already satisfied: virtualenvwrapper-win in c:\users\wozen\appdata\local\programs\python\python38\lib\site-packages (1.2.7)
  3. Requirement already satisfied: virtualenv in c:\users\wozen\appdata\local\programs\python\python38\lib\site-packages (from virtualenvwrapper-win) (20.15.1)
  4. 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)
  5. 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)
  6. 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)
  7. 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

安装
  1. yum install python-setuptools python-devel
  2. pip3 install virtualenvwrapper
  3. pip3 install virtualenvwrapper -i https://pypi.douban.com/simple
  1. [root@localhost ~]# yum install python-setuptools python-devel
  2. 已加载插件:fastestmirror, langpacks
  3. Loading mirror speeds from cached hostfile
  4. * base: mirror.lzu.edu.cn
  5. * extras: mirrors.aliyun.com
  6. * updates: mirrors.aliyun.com
  7. 软件包 python-setuptools-0.9.8-7.el7.noarch 已安装并且是最新版本
  8. 软件包 python-devel-2.7.5-92.el7_9.x86_64 已安装并且是最新版本
  9. 无须任何处理
  1. [root@localhost ~]# pip3 install virtualenvwrapper
  2. Requirement already satisfied: virtualenvwrapper in /usr/local/lib/python3.8/site-packages (4.8.4)
  3. Requirement already satisfied: virtualenv in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (20.15.1)
  4. Requirement already satisfied: virtualenv-clone in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (0.5.7)
  5. Requirement already satisfied: stevedore in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (3.5.0)
  6. Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /usr/local/lib/python3.8/site-packages (from stevedore->virtualenvwrapper) (5.9.0)
  7. Requirement already satisfied: platformdirs<3,>=2 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (2.5.2)
  8. Requirement already satisfied: six<2,>=1.9.0 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (1.16.0)
  9. Requirement already satisfied: distlib<1,>=0.3.1 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (0.3.4)
  10. Requirement already satisfied: filelock<4,>=3.2 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (3.7.1)
  11. 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
  1. [root@localhost ~]# pip3 install virtualenvwrapper -i https://pypi.douban.com/simple
  2. Looking in indexes: https://pypi.douban.com/simple
  3. Requirement already satisfied: virtualenvwrapper in /usr/local/lib/python3.8/site-packages (4.8.4)
  4. Requirement already satisfied: virtualenv in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (20.15.1)
  5. Requirement already satisfied: virtualenv-clone in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (0.5.7)
  6. Requirement already satisfied: stevedore in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (3.5.0)
  7. Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /usr/local/lib/python3.8/site-packages (from stevedore->virtualenvwrapper) (5.9.0)
  8. Requirement already satisfied: filelock<4,>=3.2 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (3.7.1)
  9. Requirement already satisfied: six<2,>=1.9.0 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (1.16.0)
  10. Requirement already satisfied: distlib<1,>=0.3.1 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (0.3.4)
  11. Requirement already satisfied: platformdirs<3,>=2 in /usr/local/lib/python3.8/site-packages (from virtualenv->virtualenvwrapper) (2.5.2)
  12. 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

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

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

  1. source ~/.bashrc

虚拟环境使用

1. 新建虚拟环境

  1. mkvirtualenv python_start

2. 查看所有虚拟环境

  1. workon

3. 进入指定虚拟环境

  1. workon python_start

Go

go的安装和配置

Windows

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

Linux

  1. 1. 下载
  2. 2. 解压
  3. tar -xvf go1.15.3.linux-amd64.tar.gz
  4. 3. 配置环境变量
  5. vim ~/.bashrc
  6. export GOROOT=/root/go
  7. export GOPATH=/root/projects/go
  8. export PATH=$PATH:$GOROOT/bin:$GPPATH/bin
  9. 4. 编辑保存并退出vim后,记得把这些环境载入:source ~/.bashrc

设置代理加速

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

GoLand的安装

  1. https://www.jetbrains.com/go/download/#section=windows
  2. 直接下载安装即可

go imports和go fmt

image.png

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

nodejs的安装和配置

Windows

下载

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

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

image.png

Linux

Date: 2022-07-12

1. 下载

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

2. 解压和建立软连接

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

3. 建立软连接

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

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

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

5. 测试

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

6. 安装cnpm

  1. npm install -g cnpm --registry=http://registry.npmmirror.com
  2. [root@localhost bin]# npm install -g cnpm --registry=http://registry.npmmirror.com
  3. npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
  4. added 346 packages in 45s
  5. 11 packages are looking for funding
  6. run `npm fund` for details
  7. npm notice
  8. npm notice New minor version of npm available! 8.11.0 -> 8.13.2
  9. npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.13.2
  10. npm notice Run npm install -g npm@8.13.2 to update!
  11. npm notice