Podman容器使用
系统版本 24.04.3 LTS

安装命令
sudo apt update
sudo dpkg --configure -a
sudo apt install podman
podman version
podman pull nginx :latest
podman pull nginx
# 1. 停止当前容器
podman stop nginx
# 2. 删除容器
podman rm nginx
# 3. 检查80端口是否被占用
sudo netstat -tulpn | grep :80
# 4. 重新创建容器,使用80端口映射
podman run -d -p 80:80 -p 8080:8080 --name nginx --restart=always -v /opt/nginx/conf.d:/etc/nginx/conf.d:Z -v /opt/nginx/html:/usr/share/nginx:Z nginx
podman run -d -p 80:80 -p 8001:81 -p 8002:82 --name nginx --restart=always -v /opt/nginx/conf.d:/etc/nginx/conf.d:Z -v /opt/nginx/html:/usr/share/nginx:Z nginx 映射多个端口
# 5. 验证新端口映射
podman port nginx
进入容器60999ffacd42
podman exec -it 60999ffacd42 /bin/bash
查看运行的容器
podman ps -a
查看nginx日志
podman logs nginx
启动nginx
podman start nginx
停止nginx
podman stop nginx
nginx配置
nginx.conf
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /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; }
conf.d文件default.conf
server { listen 80; listen [::]:80; server_name localhost; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/web/dist; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /index.html { root /usr/share/nginx/fxweb/dist; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
反向代理配置
server {
listen 8088;
listen [::]:8088;
server_name 127.0.0.1; #IP/域名
location / { ## 前端项目
root /usr/share/nginx/web/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
server {
listen 80;
listen [::]:80;
server_name www.xx.com;#外网访问的域名
location / {
proxy_pass http://127.0.0.1:8088;
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-Proto $scheme;
}
}
Redis安装
redis.conf
bind 0.0.0.0 port 6379 # 认证密码 requirepass lxyx@0371 # 持久化设置 save 900 1 save 300 10 save 60 10000 # AOF 持久化 appendonly yes appendfilename "appendonly.aof" # 内存管理 maxmemory 512mb maxmemory-policy allkeys-lru # 日志设置 loglevel notice logfile "" # 其他设置 databases 16 timeout 0 tcp-keepalive 300
下载Reid:podman pull redis:latest
创建目录:sudo mkdir -p /opt/redis/redis-data
创建容器:
podman run -d --name redis -p 6379:6379
-v /opt/redis/redis.conf:/usr/local/etc/redis/redis.conf:Z
-v /opt/redis/redis-data:/data:Z
--restart unless-stopped redis:latest redis-server /usr/local/etc/redis/redis.conf --appendonly yes
其他配置
|
作者:chenze 出处:https://www.cnblogs.com/chenze-Index/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |

浙公网安备 33010602011771号