部署Unity-Cache-Server v6.3.0 for Centos7

发布于 2019-07-04  1480 次阅读


服务器环境 Centos 7 -1810

服务器安装 略

服务器升级 sudo yum update -y

[title]挂载磁盘[/title]SSD 500G
分区

[root@unity-cache-server-116-40 ~]# fdisk -l
Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Disk /dev/sdb: 256.1 GB, 256060514304 bytes, 500118192 sectors
Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Disk /dev/mapper/centos-swap: 8388 MB, 8388608000 bytes, 16384000 sectors
Disk /dev/mapper/centos-home: 192.7 GB, 192694714368 bytes, 376356864 sectors
[root@unity-cache-server-116-40 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-976773167, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-976773167, default 976773167):
Using default value 976773167
Partition 1 of type Linux and of size 465.8 GiB is set
Command (m for help): p
Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xb7d670ef
Device Boot Start End Blocks Id System
/dev/sda1 2048 976773167 488385560 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

格式磁盘

[root@unity-cache-server-116-40 ~]# mkfs -t ext4 /dev/sda1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
30531584 inodes, 122096390 blocks
6104819 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2271215616
3727 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

挂载

[root@unity-cache-server-116-40 ~]# mount /dev/sda1 /opt
[root@unity-cache-server-116-40 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 1.7G 49G 4% /
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 9.3M 7.7G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sdb2 1014M 173M 842M 18% /boot
/dev/sdb1 200M 12M 189M 6% /boot/efi
/dev/mapper/centos-home 180G 33M 180G 1% /home
tmpfs 1.6G 0 1.6G 0% /run/user/0
tmpfs 1.6G 0 1.6G 0% /run/user/1000
/dev/sda1 459G 73M 435G 1% /opt

设置开机启动自动挂载

[root@unity-cache-server-116-40 ~]# vi /etc/fstab
/dev/sda1 /opt ext4 defaults 0 0

[title]安装 NodeJS[/title] 【NodeJS 12版本】

curl -sL https://rpm.nodesource.com/setup_12.x | bash -  
yum install -y nodejs

[title]安装 Unity Cache Server[/title]

NodeJS 安装后自带 NPM 包管理器。
注意:虽然现在最新的 NodeJS LTS 是 12,但是 Unity Cache Server 要求使用 NodeJS 8 LTS 版本。但我们也可以用12

npm install unity-cache-server -g

[title]配置Unity Cache Server[/title]

mkdir -p /opt/unity-cache-server/config
unity-cache-server --save-config /opt/unity-cache-server/config/default.yml

修改配置

vi /opt/unity-cache-server/config/default.yml

进程数
建议修改进程数为 1 个以上,能更有效地提升速度。

options:

下面增加

workers: 5

,注意这是 Yaml 文件,使用空格进行缩进,

workers

前面有

4

个空格。
缓存路径

Cache.options.cache_fs.cachePath

必须使用绝对路径,需要将值从

.cache_fs 

改为

/opt/unity-cache-server/.cache_fs


如果未使用绝对路径,启动服务时不会提示任何错误直接退出。

[title]设置Systemd服务[/title]
增加专用用户

adduser unity -s /sbin/nologin
chown -R unity:unity /opt/unity-cache-server

配置服务文件

vi /etc/systemd/system/unity-cache-server.service

粘贴服务文件内容:

[Unit]
Description=Unity Cache Server Service
After=network.target
[Service]
Type=simple
User=unity
ExecStart=/bin/unity-cache-server --NODE_CONFIG_DIR=/opt/unity-cache-server/config
Restart=on-abort
[Install]
WantedBy=multi-user.target

[title]运行控制[/title]
开机自启动、运行与状态

systemctl enable unity-cache-server  #设置开机启动
systemctl start unity-cache-server    #启动服务
systemctl status unity-cache-server   #查看服务状态

检查运行日志
运行以下命令可以以 tail 方式持续实时地显示日志,使用 Ctrl+C 退出:

journalctl -u unity-cache-server -f

停止服务

systemctl stop unity-cache-server

[title]防火墙[/title]
需要将默认端口 8126 放到允许列表中:

firewall-cmd --zone=public --add-port=8126/tcp --permanent
firewall-cmd --reload

[title]测试[/title]

Unity/Edit/Preferences/Cache Server
Cache Server Mode 

选择

 Remote

IP Address 

框中输入服务器 IP
点击

 Check Connection

按钮测试
成功的话会显示

Connection successful.

[title]清理[/title]
需要手动清理,执行以下脚本删除 180 天或超过 200GiB 的文件。

unity-cache-server-cleanup --cache-path /opt/unity-cache-server/.cache_fs --log-level 5 --max-cache-size 214748364800 --expire-time-span 180.00:00:00

[title]升级[/title]

systemctl stop unity-cache-server  #停止服务
npm update unity-cache-server -g  #执行npm 升级
systemctl start unity-cache-server   #启动服务
systemctl status unity-cache-server  #查看服务状态

一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。