之前都是将域名绑定到G Suite或者Office 365来搭建域名邮箱,最近服务器闲置地有点多,为了不吃灰,拿来搭建一个零时邮箱!
项目地址 https://github.com/denghongcai/forsaken-mail 项目作者写的步骤有点不怎么清楚,这里将自己的摸索过程记录如下
1. 安装
安装Docker
<span class="pln">curl </span><span class="pun">-</span><span class="pln">fsSL https</span><span class="pun">:</span><span class="com">//get.docker.com -o get-docker.sh</span><span class="pln"> bash </span><span class="kwd">get</span><span class="pun">-</span><span class="pln">docker</span><span class="pun">.</span><span class="pln">sh</span>
拉取镜像
<span class="pln">docker run </span><span class="pun">--</span><span class="pln">name forsaken</span><span class="pun">-</span><span class="pln">mail </span><span class="pun">-</span><span class="pln">d </span><span class="pun">-</span><span class="pln">p </span><span class="lit">25</span><span class="pun">:</span><span class="lit">25</span> <span class="pun">-</span><span class="pln">p </span><span class="lit">3000</span><span class="pun">:</span><span class="lit">3000</span><span class="pln"> denghongcai</span><span class="pun">/</span><span class="pln">forsaken</span><span class="pun">-</span><span class="pln">mail</span>
疑难杂症
1. 如果提示Error starting userland proxy: listen tcp4 0.0.0.0:25: bind: address already in use.
,一般是由于sendmail占用了25端口。查找是25端口被谁占用:
<span class="pln">sudo netstat </span><span class="pun">-</span><span class="pln">pna </span><span class="pun">|</span><span class="pln"> grep </span><span class="lit">25</span><span class="pln"> tcp </span><span class="lit">0</span> <span class="lit">0</span> <span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pun">:</span><span class="lit">25</span> <span class="lit">0.0</span><span class="pun">.</span><span class="lit">0.0</span><span class="pun">:*</span><span class="pln"> LISTEN </span><span class="lit">28656</span><span class="pun">/</span><span class="pln">sendmail</span><span class="pun">:</span><span class="pln"> MTA </span>
这里可以看到的确是sendmail占用了25端口,由于这里用不到sendmail,立即停止sendmail
<span class="str">/etc/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">sendmail stop docker container rm forsaken</span><span class="pun">-</span><span class="pln">mail</span>
并重新拉取镜像
<span class="pln">docker run </span><span class="pun">--</span><span class="pln">name forsaken</span><span class="pun">-</span><span class="pln">mail </span><span class="pun">-</span><span class="pln">d </span><span class="pun">-</span><span class="pln">p </span><span class="lit">25</span><span class="pun">:</span><span class="lit">25</span> <span class="pun">-</span><span class="pln">p </span><span class="lit">3000</span><span class="pun">:</span><span class="lit">3000</span><span class="pln"> denghongcai</span><span class="pun">/</span><span class="pln">forsaken</span><span class="pun">-</span><span class="pln">mail</span>
安装成功,应该就可访问网站了: http://IP:3000/
2. 设置DNS记录
只需要添加 MX 、A 两个记录即可
类型:MX
名称:patriotic.ml
邮件服务器:mx.patriotic.ml
TTL:自动
优先级:10
类型:A
名称:mx.patriotic.ml
IPv4 地址:184.33.16.112(自己的服务器地址)
TTL:自动
3. 使用域名访问
设置DNS记录,添加A记录
类型:A
名称:paelic.org
IPv4 地址:184.33.16.112(自己的服务器地址)
TTL:自动
名称:paelic.org
IPv4 地址:184.33.16.112(自己的服务器地址)
TTL:自动
宝塔新建网站:宝塔新建网站,域名填paelic.org,其他默认
宝塔设置Nginx反代
至此,便可以用域名访问,而不用IP加端口访问了!
3. 修改网站内容
<span class="pln">root@google</span><span class="pun">:~</span><span class="com"># docker ps</span><span class="pln"> CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c7a10eb9f879 denghongcai</span><span class="pun">/</span><span class="pln">forsaken</span><span class="pun">-</span><span class="pln">mail </span><span class="str">"/bin/sh -c 'npm sta…"</span> <span class="lit">5</span><span class="pln"> minutes ago </span><span class="typ">Up</span> <span class="lit">5</span><span class="pln"> minutes </span><span class="lit">0.0</span><span class="pun">.</span><span class="lit">0.0</span><span class="pun">:</span><span class="lit">25</span><span class="pun">-></span><span class="lit">25</span><span class="pun">/</span><span class="pln">tcp</span><span class="pun">,</span> <span class="pun">:::</span><span class="lit">25</span><span class="pun">-></span><span class="lit">25</span><span class="pun">/</span><span class="pln">tcp</span><span class="pun">,</span> <span class="lit">0.0</span><span class="pun">.</span><span class="lit">0.0</span><span class="pun">:</span><span class="lit">3000</span><span class="pun">-></span><span class="lit">3000</span><span class="pun">/</span><span class="pln">tcp</span><span class="pun">,</span> <span class="pun">:::</span><span class="lit">3000</span><span class="pun">-></span><span class="lit">3000</span><span class="pun">/</span><span class="pln">tcp forsaken</span><span class="pun">-</span><span class="pln">mail root@google</span><span class="pun">:~</span><span class="com"># docker exec -it c7a10eb9f879 bash</span>
<span class="pln">apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> install vim </span><span class="pun">&&</span><span class="pln"> vim </span><span class="kwd">public</span><span class="pun">/</span><span class="pln">index</span><span class="pun">.</span><span class="pln">html</span>
如果vim打开后中文乱码,那么在vim normal模式输入冒号后进入命令模式,再输入
<span class="kwd">set</span><span class="pln"> encoding</span><span class="pun">=</span><span class="pln">utf</span><span class="pun">-</span><span class="lit">8</span>
回车。乱码应该立马变正常。
4. 一些docker命令
由于程序是docker封装的,以下对日后维护很有帮助的docker命令简记如下
1. 查看所有容器
<span class="pln">docker ps </span><span class="pun">-</span><span class="pln">a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES </span><span class="lit">13f0c6688370</span><span class="pln"> denghongcai</span><span class="pun">/</span><span class="pln">forsaken</span><span class="pun">-</span><span class="pln">mail </span><span class="str">"/bin/sh -c 'npm sta…"</span> <span class="lit">44</span><span class="pln"> minutes ago </span><span class="typ">Exited</span> <span class="pun">(</span><span class="lit">137</span><span class="pun">)</span> <span class="lit">32</span><span class="pln"> minutes ago forsaken</span><span class="pun">-</span><span class="pln">mail</span>
可以看到容器forsaken-mail的容器ID(CONTAINER ID)是13f0c6688370
2. 启动已停止的容器
<span class="pln">docker start </span><span class="pun">容器</span><span class="pln">ID</span>
3. 关闭正在运行的容器
<span class="pln">docker start </span><span class="pun">容器</span><span class="pln">ID</span>
4. 重启容器
<span class="pln">docker start </span><span class="pun">容器</span><span class="pln">ID</span>
5. 进入容器
<span class="pln">docker </span><span class="kwd">exec</span> <span class="pun">-</span><span class="pln">it </span><span class="pun">容器</span><span class="pln">ID </span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash</span>
搭建挺简单的,只是碰到的小问题挺多。
搭建成功,就可以愉快玩耍了!