solo_Tomcat 转 docker 并升级 (问题好多!)

本贴最后更新于 1985 天前,其中的信息可能已经时移世改

      之前 solo 一直老老实实地运行 Tomcat 上,上个月有功夫升级,从 v3.6.1 升级到 v3.6.2 但失败了,因没有时间之前也没来得及查找原因,最近想进行升级,又突然想试试用 docker 来运行,故开始折腾了……

一、Docker 安装(CentOS7)

      安装一些必要的系统工具:

          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

      更新 yum 缓存:

          sudo yum makecache fast

      安装 Docker-ce:

          sudo yum -y install docker-ce

      启动 Docker 后台服务

          sudo systemctl start docker

      完成之后可以测试一下 docker 是否安装成功

二、停止运行 Tomcat

      Tomcat 路径下 /bin 目录下执行

          ./shutdown.sh

      目前 Tomcat 端口号为 8080

三、Docker 部署 solo

      按照官方文档来说,docker 部署安装 solo 很简单。

1)获取最新镜像

          docker pull b3log/solo

2)安装 Mysql?

               原先已在 docker 容器外部进行了 Mysql 部署安装,现在只需要用即可

3)启动容器

      下面具体参数含义,详见官方文档

          docker run  --name solo \
	  --network=host --env RUNTIME_DB="MYSQL"  \
	  --env JDBC_USERNAME="root" \
	  --env JDBC_PASSWORD="XXX"  \
	  --env JDBC_DRIVER="com.mysql.cj.jdbc.Driver" \
	  --env JDBC_URL="jdbc:mysql://localhost:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC" \
	  b3log/solo --listen_port=8080 --server_scheme=https --server_host=aeneag.xyz --server_port=80 

4)报错来了

[INFO ]-[2019-07-16 15:55:15]-[org.b3log.solo.util.Markdowns:135]: [markdown-http] is not available, uses built-in [flexmark] for markdown processing. Please read FAQ section in user guide ([https://hacpai.com/article/1492881378588](https://hacpai.com/article/1492881378588)) for more details.  
[INFO ]-[2019-07-16 15:55:15]-[org.b3log.solo.SoloServletListener:99]: Solo is booting [ver=3.6.3, servletContainer=jetty/9.4.12.v20180830, os=Linux, isDocker=true, markdownHttpAvailable=false, pid=1, runtimeDatabase=MYSQL, runtimeMode=PRODUCTION, jdbc.username=root, jdbc.URL=jdbc:mysql://localhost:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC]  
[INFO ]-[2019-07-16 15:55:15]-[com.zaxxer.hikari.HikariDataSource:110]: HikariPool-1 - Starting...  
[INFO ]-[2019-07-16 15:55:16]-[com.zaxxer.hikari.HikariDataSource:123]: HikariPool-1 - Start completed.  
[INFO ]-[2019-07-16 15:55:16]-[org.b3log.solo.upgrade.V361_362:59]: Upgrading from version [3.6.1] to version [3.6.2]....  
[ERROR]-[2019-07-16 15:55:16]-[org.b3log.latke.repository.jdbc.JdbcRepository:261]: Update failed  
java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x84 ' for column 'commentContent' at row 1  
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)  
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)  
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)  
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:955)  
at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:372)  
at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)  
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)  
at org.b3log.latke.repository.jdbc.util.JdbcUtil.executeSql(JdbcUtil.java:91)  
at org.b3log.latke.repository.jdbc.JdbcRepository.update(JdbcRepository.java:259)  
at org.b3log.latke.repository.AbstractRepository.update(AbstractRepository.java:111)  
at org.b3log.solo.repository.CommentRepository.update(CommentRepository.java:93)  
at org.b3log.solo.repository.CommentRepository_$$_jvst36c_1a.*d31update(CommentRepository*$$*jvst36c_1a.java)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:498)  
at org.b3log.latke.ioc.JavassistMethodHandler.invoke(JavassistMethodHandler.java:116)  
at org.b3log.solo.repository.CommentRepository*$$*jvst36c_1a.update(CommentRepository*$$*jvst36c_1a.java)  
at org.b3log.solo.upgrade.V361_362.perform(V361_362.java:83)  
at org.b3log.solo.service.UpgradeService.upgrade(UpgradeService.java:85)  
at org.b3log.solo.service.UpgradeService*$$_jvst36c_a.*d8upgrade(UpgradeService*$$*jvst36c_a.java)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:498)  
at org.b3log.latke.ioc.JavassistMethodHandler.invoke(JavassistMethodHandler.java:116)  
at org.b3log.solo.service.UpgradeService*$$*jvst36c_a.upgrade(UpgradeService*$$*jvst36c_a.java)  
at org.b3log.solo.SoloServletListener.contextInitialized(SoloServletListener.java:111)  
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:952)  
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:558)  
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:917)  
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:370)  
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)  
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)  
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:847)  
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)  
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)  
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)  
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)  
at org.eclipse.jetty.server.Server.start(Server.java:416)  
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)  
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)  
at org.eclipse.jetty.server.Server.doStart(Server.java:383)  
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)  
at org.b3log.solo.Starter.main(Starter.java:177)  
[ERROR]-[2019-07-16 15:55:16]-[org.b3log.solo.upgrade.V361_362:92]: Upgrade failed!  
org.b3log.latke.repository.RepositoryException: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x84 ' for column 'commentContent' at row 1  
at org.b3log.latke.repository.jdbc.JdbcRepository.update(JdbcRepository.java:263)  
at org.b3log.latke.repository.AbstractRepository.update(AbstractRepository.java:111)  
at org.b3log.solo.repository.CommentRepository.update(CommentRepository.java:93)  
at org.b3log.solo.repository.CommentRepository*$$_jvst36c_1a.*d31update(CommentRepository*$$*jvst36c_1a.java)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:498)  
at org.b3log.latke.ioc.JavassistMethodHandler.invoke(JavassistMethodHandler.java:116)  
at org.b3log.solo.repository.CommentRepository*$$*jvst36c_1a.update(CommentRepository*$$*jvst36c_1a.java)  
at org.b3log.solo.upgrade.V361_362.perform(V361_362.java:83)  
at org.b3log.solo.service.UpgradeService.upgrade(UpgradeService.java:85)  
at org.b3log.solo.service.UpgradeService*$$_jvst36c_a.*d8upgrade(UpgradeService*$$*jvst36c_a.java)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:498)  
at org.b3log.latke.ioc.JavassistMethodHandler.invoke(JavassistMethodHandler.java:116)  
at org.b3log.solo.service.UpgradeService*$$*jvst36c_a.upgrade(UpgradeService*$$*jvst36c_a.java)  
at org.b3log.solo.SoloServletListener.contextInitialized(SoloServletListener.java:111)  
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:952)  
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:558)  
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:917)  
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:370)  
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)  
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)  
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:847)  
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)  
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)  
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)  
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)  
at org.eclipse.jetty.server.Server.start(Server.java:416)  
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)  
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)  
at org.eclipse.jetty.server.Server.doStart(Server.java:383)  
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)  
at org.b3log.solo.Starter.main(Starter.java:177)  
Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x84 ' for column 'commentContent' at row 1  
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)  
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)  
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)  
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:955)  
at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:372)  
at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)  
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)  
at org.b3log.latke.repository.jdbc.util.JdbcUtil.executeSql(JdbcUtil.java:91)  
at org.b3log.latke.repository.jdbc.JdbcRepository.update(JdbcRepository.java:259)  
... 36 more  
[ERROR]-[2019-07-16 15:55:16]-[org.b3log.solo.service.UpgradeService:95]: Upgrade failed, please contact the Solo developers or reports this issue: [https://github.com/b3log/solo/issues/new](https://github.com/b3log/solo/issues/new)  
java.lang.Exception: Upgrade failed from version [3.6.1] to version [3.6.2]  
at org.b3log.solo.upgrade.V361_362.perform(V361_362.java:94)  
at org.b3log.solo.service.UpgradeService.upgrade(UpgradeService.java:85)  
at org.b3log.solo.service.UpgradeService*$$_jvst36c_a.*d8upgrade(UpgradeService*$$*jvst36c_a.java)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:498)  
at org.b3log.latke.ioc.JavassistMethodHandler.invoke(JavassistMethodHandler.java:116)  
at org.b3log.solo.service.UpgradeService*$$*jvst36c_a.upgrade(UpgradeService*$$_jvst36c_a.java)  
at org.b3log.solo.SoloServletListener.contextInitialized(SoloServletListener.java:111)  
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:952)  
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:558)  
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:917)  
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:370)  
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)  
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)  
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:847)  
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)  
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)  
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)  
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)  
at org.eclipse.jetty.server.Server.start(Server.java:416)  
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)  
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)  
at org.eclipse.jetty.server.Server.doStart(Server.java:383)  
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)  
at org.b3log.solo.Starter.main(Starter.java:177)

5)解决报错

      读报错内容,你会发现 commentContent 这个地方有错,在 github 上发现有一个同样的错误,并和 D 哥交流,得知是数据库中有些表的字段字符集和排序规则不对,可能是之前升级没进行修复。
      b3_solo_comment 表中的 commentContent 字段,b3_solo_article 表中的 articleAbstract、articleContent、articleAbstractText 这三个字段,字符集改为 utf8mb4,排序规则用 utf8mb4_general_ci。
      这样该错误就会解决,同时想到了之前 Tomcat 上 solo v3.6.1 升级 v3.6.2 失败的原因,应该也是这个问题,之前 Tomcat 上升级造成的后果便是 Tomcat 直接运行失败,报 jar 包的错,也懒的管,直接退回 v3.6.1

6)执行第 3 步,启动容器

      执行第三步之前,请把之前的 solo 删除,再执行第 3 步

          docker rm solo

      这样容器启动成功,输入网址即可(之前 Nginx 配置 8080,又 docker 设置 8080,故无需更改输入网址即可打开 solo)

7)皮肤配置

      下面这条命令可以在第 3 步的命令中加上,使用 docker 挂载目录命令,一定要弄明白前后的路径代表什么含义,前面代表寄宿机的路径,后面代表容器虚拟路径。因先入为主的原因一直认为后面代表寄宿机路径,搞了好久…… 这样就可以改皮肤了

          --volume /opt/solo/skins/:/opt/solo/skins/ 

四、启动 Tomcat

      因 Tomcat 上有另一个小项目,Tomcat 仍需运行

1)删除 solo 项目

      Tomcat webapps 目录下的 solo-v3.6.1 项目文件

2)修改配置

      修改 Tomcat 配置文件,修改 conf 目录下 server.xml 文件,更改 Tomcat 端口号,8080-->8888,删除配置 solo 的节点,修改完毕

3)启动 Tomcat

          ./startup.sh  //bin目录下

五、修改 Nginx 配置

      修改主要目的是 Tomcat 和 docker 同时都可以用域名访问
      Nginx 原先配置如下:

    upstream myblog{
        server localhost:8080;
    }    
    server {
        listen       80;
        server_name  aeneag.xyz www.aeneag.xyz;
        rewrite ^/(.*)$ https://aeneag.xyz/$1 permanent;
    }
    server {
        listen 443  ssl;
        server_name aeneag.xyz www.aeneag.xyz;
        root html;
        index index.html index.htm;
        ssl_certificate  ../cert/aeneag.xyz.pem;
        ssl_certificate_key ../cert/aeneag.xyz.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        location / {
              root html;
              index index.html index.htm;
              proxy_pass http://myblog$request_uri;
              proxy_set_header  Host $host:$server_port;
              proxy_set_header  X-Real-IP  $remote_addr;
              client_max_body_size  10m;
        }
    }

      现在修改为:

    upstream myblog{
        server localhost:8080;
    }    
    upstream myperson{
        server localhost:8888;
    }
    server {
        listen       80;
        server_name  aeneag.xyz;
        rewrite ^/(.*)$ https://aeneag.xyz/$1 permanent;
    }
    server {
        listen       80;
        server_name  www.aeneag.xyz;
        rewrite ^/(.*)$ https://www.aeneag.xyz/$1 permanent;
    }
    server {
        listen 443  ssl;
        server_name aeneag.xyz;
        root html;
        index index.html index.htm;
        ssl_certificate  ../cert/aeneag.xyz.pem;
        ssl_certificate_key ../cert/aeneag.xyz.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        location / {
              root html;
              index index.html index.htm;
              proxy_pass http://myblog$request_uri;
              proxy_set_header  Host $host:$server_port;
              proxy_set_header  X-Real-IP  $remote_addr;
              client_max_body_size  10m;
        }
    }
    server {
        listen 443  ssl;
        server_name www.aeneag.xyz;
        root html;
        index index.html index.htm;
        ssl_certificate  ../cert/aeneag.xyz.pem;
        ssl_certificate_key ../cert/aeneag.xyz.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        location / {
              root html;
              index index.html index.htm;
              proxy_pass http://myperson$request_uri;
              proxy_set_header  Host $host:$server_port;
              proxy_set_header  X-Real-IP  $remote_addr;
              client_max_body_size  10m;
        }
    }

六、尾

      至此,soloTomcat 转 Docker 并升级,还能同时运行已全部完成,花的不少时间,最耗时的就是解决错误,太费时间了 😰

  • Solo

    Solo 是一款小而美的开源博客系统,专为程序员设计。Solo 有着非常活跃的社区,可将文章作为帖子推送到社区,来自社区的回帖将作为博客评论进行联动(具体细节请浏览 B3log 构思 - 分布式社区网络)。

    这是一种全新的网络社区体验,让热爱记录和分享的你不再感到孤单!

    1435 引用 • 10056 回帖 • 489 关注
  • Docker

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的操作系统上。容器完全使用沙箱机制,几乎没有性能开销,可以很容易地在机器和数据中心中运行。

    492 引用 • 926 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • someone

    请问一下,你这个音乐播放器怎么弄的

    1 回复
  • 其他回帖
  • aeneag

    在签名档里,直接把 html 代码写上,网易云的百度一下你就知道