目录

remark42是一种小型评论系统,它可以嵌入静态网站中,而不用搭建论坛或wordpress等动态系统即可实现与用户的互动。

remark42的官方网站是: remark42.com。以下是我搭建的过程,由于该系统很小众,说明资料也很少,所以把安装过程记录下来,方便后继之人安装使用。

需要的基础知识

  1. 知道debian是什么
  2. 知道什么是putty类软件
  3. 会用nano或VI或VIM命令编辑配置文件
  4. 知道linux的非管理员账号是什么
  5. 非管理员账号会使用sudo命令
  6. 知道什么是IP地址
  7. 了解nginx(web服务程序)
  8. 了解SSL的大概情况
  9. 了解80,443代表什么意思
  10. 有自己的域名并具有管理权
  11. 会新建二级子域名并关联到你现在的服务器地址
  12. 看得懂简单的英语
  13. 了解HTML语言的基础知识
  14. 有计算机输入设备(键盘)

通过putty软件,登录你自己的服务器(vps)。

安装相对应的环境文件(复制$ 后面的内容)

安装 nginx

更新软件清单。

$ sudo apt-get update

​ 安装依赖:

$ sudo apt install curl gnupg2 ca-certificates lsb-release

以下4部为验证完整性步骤To set up the apt repository for stable nginx packages, run the following command:

$ echo "deb http://nginx.org/packages/debian `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

Next, import an official nginx signing key so apt could verify the packages authenticity:

$ curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Verify that you now have the proper key:

$ sudo apt-key fingerprint ABF5BD827BD9BF62

The output should contain the full fingerprint 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 as follows:

pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
      573B FD6B 3D8F BC64 1079  A6AB ABF5 BD82 7BD9 BF62
uid   [ unknown] nginx signing key <signing-key@nginx.com>

安装nginx网络服务器:

$ sudo apt update
$ sudo apt install nginx

安装docket

卸载或有的docket文件

$ sudo apt-get remove docker docker-engine docker.io containerd runc

更新软件清单。

$ sudo apt-get update

安装依赖

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

验证完整性

$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
会显示如下,则没有问题:
pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22

X86或X64的系统使用以下命令:

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"
  • 不知道自己的系统,使用 (#部分不要复制)

    $ cat /proc/cpuinfo      # 查看CPU信息
    $ uname -a    # 查看内核/操作系统/CPU信息
    

    其他系统请浏览以下链接查阅: 官方安装指引(英文)

安装DOCKER ENGINE

 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io

验证是否安装成功

$ sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.(如果验证成功,则会留下信息并退出)

Install Docker Compose

下载最新的版本

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

给执行权限

$ sudo chmod +x /usr/local/bin/docker-compose

链接指向路径

$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

测试是否安装成功:

$ docker-compose --version

docker-compose version 1.27.4, build 1110ad01

添加当前用户为docker的执行用户,将以下命令的your_username换成你当前的用户名

$ sudo usermod -aG docker your_username

其他资讯请浏览以下链接查阅:

remark42环境搭建

新建remark42的目录

$ cd
$ cd /srv/                            #进入/srv/目录
$ sudo mkdir -m 755 www              #新建www文件夹,并设置权限755
$ cd /srv/www/                       #进入/srv/www/目录
$ sudo mkdir -m 755 remark42        #新建remark42文件夹,并设置权限755

配置remark42的设置文件

$ cd /srv/www/remark42/
$ sudo nano docker-compose.yml      #编辑docker-compose.yml内容:

假设你的二级子域名是remark42.yourdomain.com,将下面的内容复制到docker-compose.yml,然后按CTRL+O进行保存,CTRL+X退出NANO编辑模式。

你需要调整**environment:**下的REMARK_URL=- SECRET=- SITE=,的值。其中REMARK_URL=需要是你的二级子域名的网址。而- SECRET=- SITE=你可以随意。其他数值都可以不改。

version: '2'

services:
    remark:
        build: .
        image: umputun/remark42:latest
        container_name: "remark42"
        hostname: "remark42"
        restart: always

        logging:
            driver: json-file
            options:
                max-size: "10m"
                max-file: "5"

        # uncomment to expose directly (no proxy)
        #ports:
        #  - "80:8080"

        environment:
            - REMARK_URL=https://remark42.yourdomain.com
            - SECRET=remark42
            - SITE=remark42
            - STORE_BOLT_PATH=/srv/var/db
            - BACKUP_PATH=/srv/var/backup
            - DEBUG=true
            - AUTH_GOOGLE_CID
            - AUTH_GOOGLE_CSEC
            - AUTH_GITHUB_CID=
            - AUTH_GITHUB_CSEC=
            - NOTIFY_TYPE=telegram
            - NOTIFY_TELEGRAM_CHAN=
            - NOTIFY_TELEGRAM_TOKEN=
            - AUTH_FACEBOOK_CID
            - AUTH_FACEBOOK_CSEC
            - AUTH_DISQUS_CID
            - AUTH_DISQUS_CSEC
            - AUTH_ANON=true
            - EMOJI=true

            # - ADMIN_PASSWD=password
        volumes:
            - ./var:/srv/var

拉取remark42程序

$ cd /srv/www/remark42/
$ docker pull umputun/remark42

Using default tag: latest
latest: Pulling from umputun/remark42
Digest: sha256:ce85044f6b8d53a9a21b9825929d65fea5867d1bd2d37026222831feaaf3d3a3
Status: Image is up to date for umputun/remark42:latest
docker.io/umputun/remark42:latest
$ docker-compose pull && docker-compose up -d

Pulling remark ... done
Creating remark42 ... done

删除、重装remark42程序(非必须步骤,如果配置有问题可进行该步骤)

有时候配置不成功,可以进行此处操作。

$ cd /srv/www/remark42/
$ docker container ls -a

CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS                  PORTS                    NAMES
55c87ca05274        umputun/remark42:latest   "/entrypoint.sh serv…"   26 hours ago        Up 10 hours (healthy)   0.0.0.0:8080->8080/tcp   remark42 

删除CONTAINER ID的数字,用于移除remark42

$ docker rm -f 55c87ca05274

测试是否已经移除

$ docker container ls -a

重装

$ docker pull umputun/remark42
$ docker-compose pull && docker-compose up -d

到这里,remark42就已经安装到你的服务器上了。并且根据你先前在remark42目录中的docker-compose.yml进行了启动。所以如果你调整配置,就需要到你的remark42的文件夹中调整docker-compose.yml

如果已经运行

$ docker-compose stop remark       // go to hibernate
$ docker-compose rm remark        // shutdown the PC 
$ docker-compose create remark     // create the container from image and put it in hibernate
$ docker-compose start remark     //bring container to life from hibernation

上述四步可以简化成:

$ docker-compose up -d 

设置remark42的网页访问功能

在nginx(网络服务程序)中进行配置

进入nginx的配置文件

编辑默认配置文件

$ cd /etc/nginx/
$ ls
$ cd /etc/nginx/conf.d
$ ls
$ sudo nano default.conf

修改default.conf,将server_name后面的内容改成yourdomain.com,注意将yourdomain.com换成你目前的域名的根域名或其他,不要是remark42.yourdomain.com即可

server {
 server_name  yourdomain.com;
}

然后按CTRL+O进行保存,CTRL+X退出NANO编辑模式。

新建remark42的二级域名设置文件

$ cd /etc/nginx/conf.d
$ sudo nano remark42.conf

编辑内容如下:

server {
	listen 80;
	listen [::]:80;

	server_name remark42.yourdomain.com;
	root /srv/www/remark42;

	index index.html;
	location / {
		try_files $uri $uri/ =404;
	}
}

然后按CTRL+O进行保存,CTRL+X退出NANO编辑模式。

测试nginx配置是否正确并刷新web服务:

$ sudo systemctl stop nginx
$ sudo systemctl start nginx
$ sudo service nginx reload

由于配置文件的调整是事后编辑的,所以如果有错误,导致无法加载nginx,请参考其他关于nginx的文章。**注意这里先不要添加443访问模式。**确保在进入下一步前,nginx的配置是可以正常启动nginx的。

添加SSL安全访问模式

以Let’s Encrypt证书为例,你并不需要知道什么是Let’s Encrypt。

使用Certbot自动配置SSL

  1. 安装snapd

    $ sudo apt update
    $ sudo apt install snapd
    $ sudo snap install core
       
    core 16-2.45.2 from Canonical✓ installed
       
    $ sudo snap install core; sudo snap refresh core
    
  2. 确保没有残留的cerbot

    $ sudo apt-get remove certbot
    
  3. 安装cerbot

    $ sudo snap install --classic certbot
    
  4. 指向路径可执行

    $ sudo ln -s /snap/bin/certbot /usr/bin/certbot
    
  5. 自动配置SSL

    $ sudo certbot --nginx
    
  6. 测试SSL是否自动续期:

    $ sudo certbot renew --dry-run
    

查看并编辑nginx的conf文件

查看remark42程序的内网IP:

$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' remark42

172.18.0.1

得到IP:172.18.0.1

打开配置文件

$ cd /etc/nginx/conf.d
$ ls
$ sudo nano remark42.conf

查看里面的文件,并将内容修改如下(注意保留certbot生成的内容),172.18.0.1改成你刚才得到的IP地址,yourdomain.com改成你自己的域名。

server {
 server_name remark42.yourdomain.com;

 listen [::]:443 ssl; # managed by Certbot
 listen 443 ssl; # managed by Certbot
 ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; # managed by Certbot
 ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # managed by Certbot
 include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
 ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

 gzip on;
 gzip_types text/plain application/json text/css application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;
 gzip_min_length 1000;
 gzip_proxied any;


 location ~ /\.git {
     deny all;
 }

 location /index.html {
      proxy_redirect          off;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        Host $http_host;
      proxy_pass              http://172.18.0.1:8080/web/index.html;
  }

 location / {
      proxy_redirect          off;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        Host $http_host;
      proxy_pass              http://172.18.0.1:8080/;
 }

 access_log   /var/log/nginx/remark42.log;

}

server {
listen 80;
server_name remark42.yourdomain.com;
return      301 https://remark42.yourdomain.com$request_uri;
}

测试nginx配置是否正确并刷新web服务:

$ sudo systemctl stop nginx
$ sudo systemctl start nginx
$ sudo service nginx reload

访问remark42.yourdomain.com/web/,如果一切正常,你的remark42就成功了。

接下来需要到你需要

提供服务的网站的静态网页插入js,并在需要显示的地方插入到HTML。

插入的JS如下:

<script>
  var remark_config = {
    host: "REMARK_URL", // hostname of remark server, same as REMARK_URL in backend config, e.g. "https://demo.remark42.com"
    site_id: 'YOUR_SITE_ID',
    components: ['embed'], // optional param; which components to load. default to ["embed"]
                           // to load all components define components as ['embed', 'last-comments', 'counter']
                           // available component are:
                           //     - 'embed': basic comments widget
                           //     - 'last-comments': last comments widget, see `Last Comments` section below
                           //     - 'counter': counter widget, see `Counter` section below
    url: 'PAGE_URL', // optional param; if it isn't defined
                     // `window.location.origin + window.location.pathname` will be used,
                     //
                     // Note that if you use query parameters as significant part of url
                     // (the one that actually changes content on page)
                     // you will have to configure url manually to keep query params, as
                     // `window.location.origin + window.location.pathname` doesn't contain query params and
                     // hash. For example default url for `https://example/com/example-post?id=1#hash`
                     // would be `https://example/com/example-post`.
                     //
                     // The problem with query params is that they often contain useless params added by
                     // various trackers (utm params) and doesn't have defined order, so Remark treats differently
                     // all this examples:
                     // https://example.com/?postid=1&date=2007-02-11
                     // https://example.com/?date=2007-02-11&postid=1
                     // https://example.com/?date=2007-02-11&postid=1&utm_source=google
                     //
                     // If you deal with query parameters make sure you pass only significant part of it
                     // in well defined order
    max_shown_comments: 10, // optional param; if it isn't defined default value (15) will be used
    theme: 'dark', // optional param; if it isn't defined default value ('light') will be used
    page_title: 'Moving to Remark42', // optional param; if it isn't defined `document.title` will be used
    locale: 'en', // set up locale and language, if it isn't defined default value ('en') will be used
    show_email_subscription: false // optional param; by default it is `true` and you can see email subscription feature
                                   // in interface when enable it from backend side
                                   // if you set this param in `false` you will get notifications email notifications as admin
                                   // but your users won't have interface for subscription
  };

  (function(c) {
    for(var i = 0; i < c.length; i++){
      var d = document, s = d.createElement('script');
      s.src = remark_config.host + '/web/' +c[i] +'.js';
      s.defer = true;
      (d.head || d.body).appendChild(s);
    }
  })(remark_config.components || ['embed']);
</script>

然后在需要显示评论的html文件中插入

<div id="remark42"></div>

感觉对于新手最难的地方过去了,其他关于配置可访问: github.com/umputun/remark42查阅设置。