标签:多个 utils body pwd basename files proxy 开机 stream
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum -y install docker-ce
sudo service docker start
sudo systemctl enable docker.service
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-‘EOF‘
{
"registry-mirrors": ["https://9tkx16bl.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo usermod -aG docker $USER
# 需要重启服务器
docker pull mysql
cp /etc/my.cnf .
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/lib/mysql/log/mysql.log
pid-file=/var/lib/mysql/pid/mysql.pid
mkdir conf
mkdir data
docker run --restart=always -d --name mysql -v /opt/software/mysql/data:/var/lib/mysql -v /opt/software/mysql/conf:/etc/mysql/ -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:5.7.29
4.1 命令解析
# 自动重启
--restart=always
# 使用本地的my.cnf配置文件替换默认的文件
-v /mysql/my.cnf:/etc/mysql/my.cnf
# mysql 的数据文件映射到本地的/mysql/data下 前面的那个是本地的
-v /mysql/data:/mysql/data
#
-v /mysql/mysql-files:/var/lib/mysql-files
# 指定mysql启动的名称
--name mysql
# 指定机器的3306端口对应容器的3306端口(后面的)
-p 3306:3306
# 指定mysql的root的密码为root
-e MYSQL\_ROOT\_PASSWORD=root
# 静默-后台启动
-d
docker exec -ti mysql bash
5.1 连接方式
mysql -uroot --protocol=tcp -p
5.2 指定用户可远程登陆
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ WITH GRANT OPTION;
FLUSH PRIVILEGES;
# mysql 8
CREATE USER ‘root‘@‘%‘ IDENTIFIED BY ‘root‘;
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ WITH GRANT OPTION;
5.3 mysql的一些管理操作
# 创建数据库
CREATE DATABASE `mydb` CHARACTER SET utf8 COLLATE utf8_general_ci;
# 创建本地登陆的 username 用户 密码为 username
CREATE USER username@‘localhost‘ IDENTIFIED BY ‘password‘;
# 授权数据库 databasename 中的 tablename 表 给 host 登陆的 username 用户
# 可以使用 *.* 授权所有数据库的所有表
# privileges - 用户的操作权限,如SELECT , INSERT , UPDATE 等。如果要授予所的权限则使用 ALL;
GRANT privileges ON databasename.tablename TO ‘username‘@‘host‘
# 指定操作权限
# GRANT INSERT,DELETE,UPDATE,SELECT ON test.user TO ‘foo‘@‘localhost‘;
# 刷新配置
flush privileges;
# 更改密码
update mysql.user set password=password(‘新密码‘) where User="username" and Host="host";
# 指定mongodb 的管理员名称
-e MONGO_INITDB_ROOT_USERNAME=mongoadmin
# 指定mongodb 的密码
-e MONGO_INITDB_ROOT_PASSWORD=secret
docker run -d -v /mongo/data:/data/db -p 27017:27017 --restart=always --privileged=true --name mongo -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=secret mongo
docker run -p 6379:6379 -v $PWD:/data:rw -v $PWD/redis.conf:/etc/redis/redis.conf:rw --privileged=true --name redis --restart=always -d redis redis-server /etc/redis/redis.conf
docker pull nginx
docker run --name nginx -p 80:80 -d nginx
docker stop nginx
docker container cp nginx:/etc/nginx .
user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name gogs.ifan.com; #监听基于域名的虚拟主机。可有多个,可以使用正则表达式和通配符
charset utf-8; #编码格式
#set $static_root_dir "/Users/doing/static";
location / { #反向代理的路径(和upstream绑定),location后面设置映射的路径
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://192.168.200.11:11530;
}
}
}
docker run --name nginx -v /opt/software/nginx:/etc/nginx -p 80:80 -d --privileged=true --restart=always nginx
docker run --name=gogs -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs
# 指定端口 本地:docker
-p 5672:5672
-p 15672:15672
# 指定本地数据存储目录
-v /rabbitmq/data:/var/lib/rabbitmq
# 指定 hostname
--hostname rabbitmq
# 指定vhost
-e RABBITMQ_DEFAULT_VHOST=rabbitmq
# 指定管理员
-e RABBITMQ_DEFAULT_USER=admin
# 指定管理员密码
-e RABBITMQ_DEFAULT_PASS=admin
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 -v /rabbitmq/data:/var/lib/rabbitmq --hostname rabbitmq1 -e RABBITMQ_DEFAULT_VHOST=rabbitmq1 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin rabbitmq:management
标签:多个 utils body pwd basename files proxy 开机 stream
原文地址:https://www.cnblogs.com/iFanLiwei/p/12824800.html