月度归档: 2023 年 9 月
traefik配置多路由
我目前正在尝试让 traefik 在单个容器上使用多个路由器和服务,但它不起作用,我不知道这是否是有意为之。
为什么?
具体来说,我正在使用 gitlab 综合容器,并希望在综合容器内使用/访问多个服务,因为 gitlab 不仅提供“gitlab 网站”。
我尝试了什么?
我只是尝试通过标签将另一个路由器添加到我的 docker compose 文件中
这就是我所拥有的:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
- "traefik.http.services.gitlab.loadbalancer.server.port=80"
这就是我要的:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
- "traefik.http.services.gitlab.loadbalancer.server.port=80"
- "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
- "traefik.http.services.registry.loadbalancer.server.port=5000"
这是行不通的,因为 traefik 可能对路由到哪个服务的内容感到困惑,而且我找不到一种机制可以告诉 traefik 在这种情况下确切地告诉 traefik 哪个路由器转到哪个服务。
我找到了我的问题的解决方案。
确实有一点我错过了:
- traefik.http.routers.myRouter.service=myService
 
使用此标签,我可以将路由器指向特定服务,并且应该能够向一个容器添加多个服务:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
- "traefik.http.routers.gitlab.service=gitlab"
- "traefik.http.services.gitlab.loadbalancer.server.port=80"
- "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
- "traefik.http.routers.registry.service=registry"
- "traefik.http.services.registry.loadbalancer.server.port=5000"
这里每个路由器都显式地指向一个特定的服务,该服务通常是隐式发生的。
如果需要绑定容器的多个端口,则必须使用文档中此处所述的traefik .. *标签。例如,可以在docker-compose.yml中使用类似这样的内容
labels:
- traefik.ember.port=8080
- traefik.ember.frontend.rule=Host:mydomain.com
- traefik.reload.port=37531
- traefik.reload.frontend.rule=Host:mydomain.com;PathPrefixStrip:/reload
```<!--autointro-->			docker-compose部署seafile
docker-compose.yml文件如下
version: '2.0'
services:
  db:
    image: mariadb:10.5
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=rootpw  # Requested, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
    volumes:
      - /home/admin/volumes_seafile/mysql:/var/lib/mysql  # Requested, specifies the path to MySQL data persistent store.
    networks:
      - seafile-net
  memcached:
    image: memcached:1.6
    container_name: seafile-memcached
    entrypoint: memcached -m 256
    networks:
      - seafile-net
  seafile:
    image: seafileltd/seafile-mc:latest
    container_name: seafile
    ports:
      - "7000:80"
      - "7443:443"  # If https is enabled, cancel the comment.
      #- "80:80"
      #- "443:443"  # If https is enabled, cancel the comment.      
    volumes:
      - /home/admin/volumes_seafile/seafile:/shared   # Requested, specifies the path to Seafile data persistent store.
      - /home/admin/volumes_seafile/seafile/nginx/conf:/etc/nginx/conf.d
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=password  # Requested, the value shuold be root's password of MySQL service.
      - TIME_ZONE=Asia/Shanghai # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=xxxx@outlook.com # Specifies Seafile admin user, default is 'me@example.com'.
      - SEAFILE_ADMIN_PASSWORD=seafilepassword     # Specifies Seafile admin password, default is 'asecret'.
      - SEAFILE_SERVER_LETSENCRYPT=true   # Whether use letsencrypt to generate cert.
      - SEAFILE_SERVER_HOSTNAME=seafile.xxx.com # Specifies your host name.
    depends_on:
      - db
      - memcached
    networks:
      - seafile-net
networks:
  seafile-net:
切换到yml所在目录
cd /home/admin/compose_seafile
运行如下命令,build
docker-compose build
运行如下命令,启动
docker-compose up -d
nginx总是报找不到证书文件的错误可以这么解决 使用docker容器系统中的绝对路径,并将con.d文件夹映射到主机系统中就可以了。 220919 seafile一番折腾终于成功了 总结点经验就是,如果docker-compose buid出现错误报找不到文件错误,不是python的问题,检查docker是否安装,检查docker是否启动,这次就时因为重启服务器之后docker没有启动还以为时python的问题,花费了很长事件找原因。 修改docker-compose.yml文件之后要先停止已经启动的docker-compose,然后再build才能生效。
查看seafile数据库日志
docker-compose logs -f
查看seafile日志
docker logs -f seafile
进入seafile容器
docker container exec -it seafile bash
			nextcloud缺少插件和权限不足问题解决
221021
vscode的ssh插件连接主机后会占用很大内存,使内存占用从0.69G升到1.28G。
nextcloud问题
-   This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them.
`-   intl`
-   The PHP module "imagick" is not enabled although the theming app is. For favicon generation to work correctly, you need to install and enable this module.
上述两个问题安装intl和imagick并启用即可。
在php的dockerfile中安装
“`
libmagickwand-dev \
&& docker-php-ext-configure intl \
    && docker-php-ext-install intl 
   
&& pecl install imagick-beta \
&& echo “extension=imagick.so”
关于PHP执行用户和docker路径挂载的问题
关于PHP执行用户的问题
对于通过SFTP上传文件搭建的网站,有时会遇到权限问题。要么权限没给够,提示没有权限。一般遇到这种直接给全部权限,也就是‘777’权限可以解决。但对于安全设置严格的web程序这么操作会提示文件夹或文件可以被其他用户读取不安全,这就需要改文件夹或文件的所属用户了。 然而并不知道,用户是谁。下面是我在解决该问题时学习的一些方法。不过到目前位置还是没有理解透彻。 我在搭建nextcloud的时候就遇到了上面提到的问题,参考官方镜像搭建成功的web程序,发现很多文件夹所属用户是‘33’,但是主机系统中并没有这个用户。
php配置文件中的用户组如下,如果不存在,会使用默认用户执行。
user = www-data
group = www-data
www-data
获取nginx和php用户和组
[root@iZ8vbajg9wo8iwynfb1lgeZ data]# ps axu|grep nginx
root     1322844  0.0  0.3  37772  6232 ?        Ss   15:12   0:00 nginx: master process nginx -g daemon off;
101      1322890  0.0  0.3  38364  6740 ?        S    15:12   0:00 nginx: worker process
root     1331548  0.0  0.0  12108  1052 pts/0    S+   15:36   0:00 grep --color=auto nginx
[root@iZ8vbajg9wo8iwynfb1lgeZ data]# ps axu|grep php
root     1322682  0.0  1.4 216796 26416 ?        Ss   15:12   0:00 php-fpm: master process (/usr/local/etc/php-fpm.conf)
admin    1323298  0.1  2.3 223656 44364 ?        S    15:13   0:01 php-fpm: pool www
admin    1323731  0.1  2.3 223592 43104 ?        S    15:14   0:01 php-fpm: pool www
admin    1324200  0.1  2.2 223484 42808 ?        S    15:15   0:01 php-fpm: pool www
root     1331742  0.0  0.0  12108  1076 pts/0    S+   15:36   0:00 grep --color=auto php
**
docker路径挂载问题
build成功之后的部分日志
117668470    0 drwxr-xr-x 2 root root      24 Sep 21 14:37 /tmp/pear/temp/pear-build-defaultuser6thOCT/install-mongodb-1.11.1/usr/local/lib/php/extensions/no-debug-non-zts-20210902
117668471 8396 -rwxr-xr-x 1 root root 8595192 Sep 21 14:37 /tmp/pear/temp/pear-build-defaultuser6thOCT/install-mongodb-1.11.1/usr/local/lib/php/extensions/no-debug-non-zts-20210902/mongodb.so
Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20210902/mongodb.so'
install ok: channel://pecl.php.net/mongodb-1.11.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongodb.so" to php.ini
Removing intermediate container 237ce43c5051
---<!--autointro-->			dockercompose+traefik安装wordpress
yml文件`wordpress-docker-compose.yml
version: "3.7"
services:
  wordpress:
    image: wordpress
    restart: always
    # ports:
    #   - 8080:80
    environment:
      WORDPRESS_DB_HOST: mariadb #这里的数据库用的时lnmp中的,在同一个网络
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: SQLroot77
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wordpress:/var/www/html
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.wordpress.entrypoints=websecure"
      - "traefik.http.routers.wordpress.rule=Host(`wp.weiyoun.com`)"
      - "traefik.http.routers.wordpress.tls.certresolver=lets-encr"
volumes:
  wordpress:
networks:
  default:
    external:
      name: traefik
运行
docker-compose -f wordpress-docker-compose.yml up
用域名访问,提示数据库连接错误
这是因为数据库中没有创建
wordpress数据库
进入数据库容器
docker exec -it dc1_mariadb_1 bash 进入数据库mysql -u root -p
创建并查询数据库
MariaDB [(none)]<!--autointro-->