我們在學習接口自動化的時候,最理想的狀態是在公司有項目可以操作。大部分時候我們並沒有可以練習的項目,因此練習接口無從談起,只能找一些開放的api來練一練,但是這樣並不能提高我們的技術。因此我們需要搭建一套自己的接口環境
需要的資源:
vm虛擬機:https://pan.baidu.com/s/1Gz77XAk7ME3JnV1fRVDnSQ 密碼:j1p8
ubuntu系統:https://pan.baidu.com/s/1jMAwFQGgq2tTw_vef3KAow 密碼:quze
centos系統:https://pan.baidu.com/s/1U_ulnyFhzsSs9mqtLsITEQ 密碼:e4g2
xshell:https://pan.baidu.com/s/1pX7LnmzFMFsb2lN-WmfSSA 密碼:16ks
1:安裝虛擬機
2:安裝系統(自選)
3:安裝ssh
ubuntu:apt-get install openssh-server
centos:yum -y install openssh-server
4:安裝net-tools
ubuntu:apt-get install net-tools
centos:yum -y install net-tools
5:xshell遠程連接虛擬機
6:安裝docker
ubuntu apt-get install docker.io
centos yum -y install docekr.io
7:安裝鏡像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://1vtrf9ho.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
---------------------------------------
---------------------------------------
docker 安裝成功---
鏡像加速器安裝成功---
---------------------------------------
---------------------------------------
8:拉取鏡像(需要聯系博主開啟鏡像)
sudo docker pull registry.cn-hangzhou.aliyuncs.com/zhufc/xiaoyaoji:web
sudo docker pull registry.cn-hangzhou.aliyuncs.com/zhufc/mysql:v1
鏡像下載成功之后,xhell開啟兩個會話
第一個會話執行 小幺雞 服務操作;
第二個會話執行 mysql 配置文件操作;
mysql數據庫:
docker images 查看mysql鏡像id
docker run -d -p 4406:3306 registry.cn-hangzhou.aliyuncs.com/zhufc/mysql:v1
docker ps -a 查看生成的容器
docker exec -it {mysql id} bash 進入容器
apt-get update
apt-get install vim
apt-get install lrzsz
cd /usr
rz xiaoyaoji.sql(上傳本地sql文件)
/usr/local/mysql/bin/mysql mysql -u root -p
密碼:000000
use mysql;(初始化mysql庫)
show databases;
create database api;
use mysql;
grant all on *.* to 'root'@'本機ip' identified by '000000';(本機ip添加到user表)
grant all on *.* to 'root'@'172.17.0.2' identified by '000000';(容器ip添加到user表)
grant all privileges on *.* to root@'%' identified by "000000";
FLUSH PRIVILEGES;(刷新數據庫)
use api;(初始化api庫)
source /usr/xiaoyaoji.sql(執行sql)
FLUSH PRIVILEGES;
小幺雞:
docker images 查看鏡像id
docker run -d -p 80:8080 registry.cn-hangzhou.aliyuncs.com/zhufc/xiaoyaoji:web
docker ps -a 查看生成的容器
docker exec -it {小幺雞id} bash 進入容器
cd /usr/local/tomcat/apache-tomcat-7.0.78/webapps/api/WEB-INF/classes
vi config.properties
修改數據庫地址 用戶名 密碼(host為虛擬機ip)
重啟tomcat
本地navicate遠程連接mysql
進入mysql庫下面的user表,刪除所有password為空的數據
進入mysql容器,執行刷新:FLUSH PRIVILEGES;
本地瀏覽器啟動小幺雞服務:虛擬機host/api
你還在為找不到可練習的接口而煩惱嗎?現在加入龍淵閣,手把手教你搭建屬於自己的接口測試環境!
