生产测试环境搭建
一 python
1. 安装python3.8
sudo apt update
sudo apt install -y software-properties-common
sudo apt install -y python3.8
sudo apt install python3-pip
sudo ln -s /usr/bin/python3.8 /usr/bin/python
2. 查看版本
python3 --version
python --version
二 安装docker
1.卸载旧版本Docker
#卸载旧版本docker
sudo apt-get remove docker docker-engine docker-ce docker.io
#清空旧版docker占用的内存
sudo apt-get remove --auto-remove docker
#更新系统源
sudo apt-get update
2.配置安装环境
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
3. 添加阿里云的docker GPG密钥
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
4. 添加阿里镜像源
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
#更新
sudo apt-get update
5. 查看有哪些版本
apt-cache madison docker-ce
6. 安装Docker
#安装最新版
sudo apt-get install -y docker-ce
7. 启动/重启Docker
sudo systemctl start docker
wsl使用 sudo service docker start
sudo systemctl restart docker
wsl使用 sudo service docker restart
8. 查看Docke版本
sudo docker version
9.以非 root 用户身份管理 Docker
要创建 docker 组并添加用户:
(1).创建 docker 组
sudo groupadd docker
(2).将自己的用户添加到 docker 组中:
sudo usermod -aG docker $USER
(3).注销并重新登陆以重新验证组成员关系。
sudo systemctl restart docker
三 安装docker-compose
1. 安装docker-compose
sudo apt install -y docker-compose
2. 查看docker-compose版本
docker-compose version
3. 常用命令
1 查看镜像
docker images
2 下拉镜像
docker pull mysql:5.7
3 删除镜像
docker rmi images-id
4 构建镜像
docker build -t coinflow/heco-converters-task:dev .
5 推送镜像到仓库
docker push coinflow/heco-converters-task:dev
6 查看容器
docker ps
docker ps -a
7 停止容器
docker stop contain-id或contain-name
8 删除容器
docker rm -f contain-id或contain-name
9 进入容器
docker exec -it contain-id或contain-name bash
10 查看容器信息
docker container inspect contain-id
11 使用docker-compose启动
docker-compose -f docker-compose.yml up -d
- d 表示后台运行
四 安装mysql
1 创建目录
mkdir /home/ubuntu/mysql
mkdir /home/ubuntu/mysql/config
mkdir /home/ubuntu/mysql/data
2 使用docker-compose方式创建mysql容器
2.1在docker-compose.yml文件中添加如下配置
version: '3'
services:
spapi:
environment:
- NODE_ENV=production
image: coinflow/bsc-sp-web-api:latest
container_name: spapi
restart: always
ports:
- "9701:9901"
privileged: true
volumes:
- "/home/ubuntu/logs/sp-web-api/logs:/usr/src/app/logs:rw"
networks:
- sp_default
spweb:
image: coinflow/bsc-sp-swap-web:latest
container_name: spweb
restart: always
ports:
- "8080:80"
privileged: true
sptask:
environment:
- NODE_ENV=production
image: coinflow/bsc-sp-web-task:latest
container_name: sptask
restart: always
ports:
- "9902:9902"
privileged: true
volumes:
- "/home/ubuntu/sh/sp-web-task/pro-mysql.json:/usr/src/app/sqlConfig/config/pro-mysql.json:rw"
- "/home/ubuntu/logs/sp-web-task:/usr/src/app/logs:rw"
networks:
- sp_default
spinfo:
image: coinflow/sp-info:latest
container_name: spinfo
restart: always
ports:
- "9020:80"
privileged: true
networks:
- sp_default
mysql:
restart: always
image: mysql:5.7
container_name: mysql
volumes:
- /home/ubuntu/mysql/config:/etc/mysql
- /home/ubuntu/mysql/logs:/var/log/mysql
- /home/ubuntu/mysql/data:/var/lib/mysql
environment:
- "MYSQL_ROOT_PASSWORD=Con_123456"
- "MYSQL_DATABASE=sheep"
ports:
- 3306:3306
networks:
- sp_default
networks:
sp_default:
driver: bridge
/home/ubuntu/mysql/config/my.cnf
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
[mysqld]
bind-address=0.0.0.0
port=3306
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
character-set-server=utf8
##############################################################################
#innodb
default_storage_engine=InnoDB
##############################################################################
# Binary log/replication
#log-bin
sync_binlog=1
sync_relay_log=1
relay-log-info-repository=TABLE
master-info-repository=TABLE
binlog_format=ROW
transaction-isolation=READ-COMMITTED
##############################################################################
#connect
max-connect-errors=100000
max-connections=2000
##############################################################################
explicit_defaults_for_timestamp=true
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
##############################################################################
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
2.2 启动
docker-compose -f docker-compose.yml up -d mysql
2.3 使用root用户登录
启动之后root用户的登录密码是MYSQL_ROOT_PASSWORD参数配置的密码,
mysql -h 18.163.195.73 -P 3306 -uroot -pCon_123456
2.3 添加新用户
create user 'converter'@'%' identified by 'Con_123456';
grant all privileges on . to 'converter'@'%';
flush privileges;
2.4 root用户只用来本地登录
use mysql;
delete user where Host = '%' and User = 'root';
保留这条数据的备份:
INSERT INTO `mysql`.`user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) VALUES ('%', 'root', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', '*464202B4B3F5C5D124E1CCA1A3FEE5D3C43AB624', 'N', '2021-07-01 03:30:58', NULL, 'N');
3 使用docker方式启动mysql
docker run -p 3306:3306 --name mysql \
-v /home/ubuntu/rpone/mysql/conf:/etc/mysql \
-v /home/ubuntu/rpone/mysql/logs:/var/log/mysql \
-v /home/ubuntu/rpone/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=Cf_u1949 \
-d mysql:5.7
五 安装mysql8
1 创建目录
mkdir /home/ubuntu/mysql
mkdir /home/ubuntu/mysql/config
mkdir /home/ubuntu/mysql/data
2 使用docker-compose方式创建mysql容器
2.1在docker-compose.yml文件中添加如下配置
version: '3'
services:
mysql:
restart: always
image: mysql:8.0.27
container_name: mysql8
volumes:
- /home/ubuntu/mysql/config:/etc/mysql
- /home/ubuntu/mysql/logs:/var/log/mysql
- /home/ubuntu/mysql/data:/var/lib/mysql
- /home/ubuntu/mysql-files:/var/lib/mysql-files
environment:
- MYSQL_USER=hfer
- MYSQL_PASSWORD=hfer123456
- MYSQL_ROOT_PASSWORD=root123456
- MYSQL_DATABASE=test
command:
--default-authentication-plugin=mysql_native_password
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
ports:
- 3306:3306
networks:
- sp_default
networks:
sp_default:
driver: bridge
2.2 启动
docker-compose -f docker-compose.yml up -d mysql
2.3 进入容器修改配置
docker exec -it **** /bin/bash
mysql -u root -p
use mysql
grant all privileges on *.* to 'hfer'@'%';
flush privileges;
其它操作
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
# 开启远程登录与权限
use mysql
update user set host='%' where user ='root';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
//如果加密方式不对可修改
update user set plugin='mysql_native_password' where user='root';
FLUSH PRIVILEGES;
//查看修改结果
select host,user,plugin from user;
# 创建备份用户
CREATE USER 'repl'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'repl'@'%' PASSWORD EXPIRE NEVER;
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
#查看master状态并记录下来
SHOW MASTER STATUS;