设置开机自启动
创建home-assistant@homeassistant.service服务:
sudo nano /etc/systemd/system/home-assistant@homeassistant.service
复制以下内容,定义服务,其中After
定义先行服务,ExecStart
执行启动脚本:
[Unit]
Description=Home Assistant
After=network-online.target
[Service]
Type=simple
User=homeassistant
WorkingDirectory=/home/homeassistant/.homeassistant
ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"
RestartForceExitStatus=100
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
chomd
命令将文件权限更改为可读、可执行,不可写:
sudo chmod 555 /etc/systemd/system/home-assistant@homeassistant.service
重新加载systemd
,enable
设置下次开机启动,start
立即激活home-assistant@homeassistant服务:
sudo systemctl --system daemon-reload
sudo systemctl enable home-assistant@homeassistant
sudo systemctl start home-assistant@homeassistant
more about systemd:https://blog.csdn.net/u014163312/article/details/119080802
内网穿透
看Offical文档:https://www.cpolar.com/docs
- 获取安装脚本进行安装(国内):
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
- 通过
cpolar version
查看版本号,验证安装,去↑ cpolar官网注册,选择免费套餐即可,获取token。配置token:
cpolar authtoken xxxxxxx
-
简单穿透测试
cpolar http 8080
,这里是将随机域名映射至主机(树莓派)的8080端口,支持http
协议。 -
(可选)配置自启动服务:
sudo systemctl enable cpolar
sudo systemctl start cpolar
sudo systemctl status cpolar
- 配置ssh连接,在dashboard界面(https://dashboard.cpolar.com/status)可以看到在线隧道:
cpolar在激活之后生成在线隧道,将树莓派本地端口映射至在线隧道端口即可,-p
为端口号:
ssh pi@×.tcp.vip.cpolar.cn -p ×××××
- (可选)配置VNC连接,首先启动vncserver,默认的vnc端口为5900,但是注意启动服务之后,内网地址为
192.168.3.54:k
,实际端口应为 5090 + k 5090+k 5090+k,通过cpolar tcp 5900+k
映射该端口,会得到一个域名,用VNC viewer连接即可。