Skip to content

Commit 761dd46

Browse files
committed
new file: _posts/2017-08-22-nas-with-plex-syncthing.md
1 parent 8994992 commit 761dd46

13 files changed

+305
-126
lines changed

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ kramdown:
2727
hard_wrap: false
2828

2929
ga: 'UA-65795020-1'
30-
adsense: 'ca-pub-4389178015607333'
30+
adsense:
3131
disqus: 'harttleland'
3232
twitter:
3333
username: harttleharttle

_posts/2016-10-25-install-oh-my-zsh-locally.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ export PATH="$HOME/usr/bin/zsh"
119119

120120
> 注意`PATH`两边不能有空格,且必须使用双引号来让Bash解析`$HOME`的值。
121121
122+
# 多余字符问题
123+
124+
语言和地区配置不正确可能会导致 Z Shell 中敲 Tab 时出现多余的字符。尝试修复 `locale` 设置即可解决。
125+
126+
1. 首先检查 `LC_ALL``echo $LC_ALL`。如果它不没有指定 UTF-8 的话,可以在 `~/.zshrc` 中添加 `LC_ALL=en_US.UTF-8 UTF-8`
127+
2. 如果还不生效可能是没有生成对应 locale。检查 `/etc/locale.gen` 并执行 `locale-gen` 可能解决问题(ArchLinux)。
128+
122129
[omz]: https://github.com/robbyrussell/oh-my-zsh
123130
[zsh-cli]: /assets/img/blog/shell/zsh-cli.png
124131
[zsh]: http://www.zsh.org/

_posts/2017-02-08-web-components-survey.md

Lines changed: 180 additions & 124 deletions
Large diffs are not rendered by default.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
title: 利用 Plex 和 Syncthing 搭建媒体中心
3+
tags: Plex Syncthing Archlinux SSH systemd
4+
---
5+
6+
因为软件都是[朋友][oott]介绍的,这篇文章本来是不打算写的。
7+
但由于在坑上浪费不少时间还是写出来或许对新接触 NAS 的人有所帮助。
8+
本文记录如何利用 [Plex][plex][Syncthing][syncthing] 搭建家用 NAS,具体地实现了这些功能:
9+
10+
* P2P 的文件备份。
11+
* DLNA 媒体服务。
12+
* 随时上传媒体文件。
13+
14+
笔者的设备:Acer 笔记本([Archlinux][arch]),小米 TV(Android)。
15+
可能和您的设备有所区别,但原理类似。我了解到即使对 Windows 版本,用户和权限等策略都是一样的。
16+
或者你可以 [安装一个 Arch][arch-install]
17+
18+
<!--more-->
19+
20+
# 软件介绍
21+
22+
* [Plex][plex] 是一套软件,包括媒体服务器、Android 等终端设备 App。支持转码和基于元数据的分类,以及播放时选择不同的码率。
23+
24+
* [Syncthing][syncthing] 开放的,去中心化的文件同步软件。P2P 的机制很厉害,居然在公司可以与家里的内网服务同步。
25+
26+
* [systemd][systemd] 是 Linux 下很先进的守护进程管理工具,使用方式很简单。一个简单的使用例子可以参考这篇文章:[使用systemd管理Node.js应用](/2016/08/04/systemd-nodejs-app.html)
27+
28+
# 搭建 Syncthing 服务
29+
30+
Syncthing 有很多 binary 可以下载,可以挑一个合适的下载安装即可。Archlinux 可以从 AUR 安装:
31+
32+
```bash
33+
yaourt -S syncthing
34+
```
35+
36+
`systemd` 启动服务:
37+
38+
```bash
39+
systemctl start syncthing@harttle.service
40+
systemctl enable syncthing@harttle.service
41+
```
42+
43+
`@harttle` 后缀让它工作在 harttle 用户下,需要改成你的系统用户名。
44+
这样 Syncthing 创建的文件拥有 harttle 用户的默认权限,Owner 为 `harttle:users`
45+
46+
启动后可以访问 <localhost:8384> 来使用服务。你需要在每台设备上都安装 Syncthing,
47+
让它们交换 ID 后即可互相同步文件。备份策略和共享目录都可以在 Web UI 上设置。
48+
如果你的服务像 [Harttle](/) 一样启动在远程服务器上,可以借助 SSH 把 Web UI 的端口 Forward 到本地:
49+
50+
```bash
51+
# 用你的服务器地址
52+
ssh 192.168.1.xx -L 8384:localhost:8384
53+
```
54+
55+
然后访问本地的 <localhost:8384>。后面的 Plex Web 端口也是一样,不再赘述。
56+
57+
# 搭建 Plex 服务
58+
59+
同样地,安装 [AUR plex][aur-plex] 并启动:
60+
61+
```bash
62+
yaourt -S plex-media-server
63+
systemctl start plexmediaserver
64+
systemctl enable plexmediaserver
65+
```
66+
67+
为了让 Plex 可以读写 Syncthing 的文件,需要让 Plex 也运行在 `harttle` 用户。
68+
需要做下面的两件事情。
69+
70+
## 1. 更改启动用户
71+
72+
编辑 Systemd Unit 文件 `/etc/systemd/system/multi-user.target.wants/plexmediaserver.service`,把 User 和 Group 改成你的:
73+
74+
```
75+
[Service]
76+
User=harttle
77+
Group=users
78+
```
79+
80+
## 2. 更改运行时文件权限
81+
82+
由于我们更改了 Plex 启动用户,也需要相应更改 Plex 的工作区目录 `/var/lib/plex`
83+
这个目录的 Owner 应当与启动用户一致,否则无法正常启动。
84+
如果你的目录不是这个,可以从 Systemd Unit 文件中的配置一路追踪到这个目录。
85+
86+
```bash
87+
chown harttle:users -R /var/lib/plex
88+
```
89+
90+
日志文件也在这里,可以用来调试:`/var/lib/plex/Plex\ Media\ Server/Logs`
91+
然后重启 Plex 的 Systemd Unit:
92+
93+
```bash
94+
systemctl daemon-reload
95+
systemctl restart plexmediaserver
96+
```
97+
98+
访问 `localhost:32400` 即可进行媒体内容和目录的管理。
99+
要借助 Syncthing 上传到 Plex,只需要把 Syncthing 和 Plex 目录设成一样的,
100+
上传 Syncthing 结点的对应文件夹的模式设为仅发送。
101+
102+
# 客户端
103+
104+
如果你从局域网其他机器也可以访问 Plex Media Server 就说明服务已经成功启动了。
105+
在启动 Plex 后就可以从小米电视访问 DLNA 服务了。安装 Plex Android 客户端后会更容易使用,从这里下载:
106+
<https://www.apkmirror.com/apk/plex-inc/plex/>。附使用截图:
107+
108+
![plex dashboard](/assets/img/blog/plex@2x.png)
109+
110+
[plex]: https://www.plex.tv/zh/
111+
[oott]: https://best33.com/
112+
[syncthing]: https://syncthing.net/
113+
[aur-plex]: https://wiki.archlinux.org/index.php/Plex
114+
[arch]: https://www.archlinux.org/
115+
[arch-install]: /2013/11/07/arch-install.html
116+
[systemd]: https://wiki.archlinux.org/index.php/systemd

assets/img/blog/plex@2x.png

3.57 MB
Loading
64.1 KB
Loading
68.6 KB
Loading
91.9 KB
Loading
76.8 KB
Loading
31.1 KB
Loading

0 commit comments

Comments
 (0)