云服务器使用指北
Tags: 技术 Last edited: May 31, 2022 4:39 PM
绪论
采购了一台腾讯云服务器,想着将其利用起来。试着搭了一个图床以及一个WordPress网站。通过docker可以将各个部分分离开,整体体验还不错。后续我还在云服务器上搭了饥荒服务器,极大加强了饥荒联机体验 ,这个是最令我惊喜的部分😆。
个人图床
使用 docker + Chevereto 搭建 个人图床
参考https://blog.folklib.com/2021/09/04/图床-docker安装chevereto/
首先下载安装docker 和 Chevereto
## 下载docker和docker compose
yum install docker-latest
curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
##拉取镜像
systemctl start docker-latest.service
docker pull mariadb:latest
docker pull nmtan/chevereto:latest
配置参数设置文件
##参数配置文件
mkdir cheverto/
cd cheverto
mkdir images conf database
cd conf
vi php.ini
在php.ini中增加一下内容,Chevereto默认设定上传最大文件大小为2M,这里修改大一些:
memory_limit = 256M;
upload_max_filesize = 100M;
post_max_size = 100M;
#返回cheverto目录,新建yaml文件
cd ..
vi docker-compose.yaml
在yaml文件中增加类似内容,里面相关密码需要使用者自己修改
version: '3'
services:
db:
image: mariadb
volumes:
- ./database:/var/lib/mysql:rw
restart: always
networks:
- private
environment:
MYSQL_ROOT_PASSWORD: xxxxx
MYSQL_DATABASE: xxxxx
MYSQL_USER: xxxxx
MYSQL_PASSWORD: xxxxx
chevereto:
depends_on:
- db
image: nmtan/chevereto
restart: always
networks:
- private
environment:
CHEVERETO_DB_HOST: db
CHEVERETO_DB_USERNAME: xxxxxx
CHEVERETO_DB_PASSWORD: xxxxx
CHEVERETO_DB_NAME: xxxxx
CHEVERETO_DB_PREFIX: chv_
volumes:
- ./images:/var/www/html/images:rw
- ./conf/php.ini:/usr/local/etc/php/php.ini:ro
ports:
- 8082:80
networks:
private:
启动
#docker容器启动后,chevereto文件夹内会自动生成挂载的两个目录.分别为数据库的database和图片文件夹images.
#为使图床程序能够正常上传和删除图片,还需要配置images文件夹权限.
chmod -R 777 images
# 启动命令
docker-compose up -d
# 容器正常运行中如需修改配置docker-compose.yml,执行以下停止命令,修改完毕后再次执行以上启动命令.
docker-compose down
开始使用chevereto
网址栏输入 云服务器IP地址:端口号 (类似168.192.1.1:8800) 网页页面如下图:
完成设置后点击 Install Chevereto 开始使用吧
后续还可以搭配 Picgo
自建个人网站
wordpress+docker compose
使用docker很方便的基于wordpress建立站点
首先拉取wordpress与mysql镜像
docker pull wordpress
docker pull mysql
新建文件夹wordpress 并在其中增加文件夹 ./wordpress ./db_data
编写docker-compose.yml文件
version: "3.3"
services:
db:
image: mysql:5.6
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
volumes:
- ./db_data:/var/lib/mysql
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
- ./wordpress:/var/www/html
启动
docker-compose up -d
进入站点设置wordpress即可,站点网址为: IP地址:端口号 (如 198.164.2.2:8000)
修改端口号:
docker-compose down
修改docker-compose.yml文件
docker-compose up -d
进入mysql容器 Linux容器/Docker
修改wordpress数据库, wp_options表, option_name字段 等于siteurl和home的2条记录
use wordpress
# wp_options表 查询记录
select * from wp_options where option_name in ('siteurl','home');
# wp_options表 更新option_value的值
update wp_options set option_value='http://www.example.com:80' where option_name in ('siteurl','home');
配置nginx反向代理
docker pull nginx
编写 docker-compose.yml
version: '3'
services:
nginx:
image: nginx:latest
container_name: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./certs:/etc/nginx/certs
ports:
- 80:80
- 443:443
加入ssl证书到certs文件夹下
配置nginx.conf
worker_processes 2;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;
# [ debug | info | notice | warn | error | crit ]
error_log /var/log/nginx.error_log info;
events {
worker_connections 2000;
# use [ kqueue | epoll | /dev/poll | select | poll ];
# use kqueue;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
log_format download '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$http_range" "$sent_http_content_range"';
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
send_lowat 12000;
keepalive_timeout 75 20;
#lingering_time 30;
#lingering_timeout 10;
#reset_timedout_connection on;
server {
listen 443 ssl;
ssl_certificate /etc/nginx/certs/your_domain.com/your_domain.com.cer;
ssl_certificate_key /etc/nginx/certs/your_domain.com/your_domain.com.key;
server_name your_domain.com;
client_max_body_size 500M ;
location / {
proxy_pass http://172.17.0.1:9009;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto https;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
#proxy_read_timeout 86400;
}
}
server {
listen 80;
server_name your_domain.com;
location / {
return 301 https://$host$request_uri;
}
}
}
在启动nginx镜像前, 请先确保80和443端口没有被占用, 再确保WordPress在http协议下的ip:port的访问是否正常, 再再确保你的WordPress是全新的或做好了资料备份的. 一切OK的话, 前往WordPress的设置->常规中把站点地址和WordPress地址都改成https://your_domain.com。
运行nginx docker-compose up -d
大功告成
饥荒服务器
参考教程: