如果你在linux系统上启动了很多自己的服务,如果直接执行系统的reboot或者shutdown命令,可能会发生一些异常的现象,所以我们在重启和关机前,应该按照我们的意愿去自定义清理一些服务或者资源等。但是网上的方式大多是以Centos6为教程,修改chkconfig和rc0.d,rc6.d的内容。在Centos7中以及不适用了。
本文就介绍一下在Centos7系统中,使用systemctl的方式来自定义关机前执行脚本。
vi /usr/lib/systemd/system/stopSrv.service Centos
创建该文件然后加入下面的内容,需要把ExecStart=/home/my_script这一行换成自己的脚本路径
[Unit]
Description=close services before reboot and shutdown
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
# This works because it is installed in the target and will be
# executed before the target state is entered
# Also consider kexec.target
[Service]
Type=oneshot
ExecStart=/home/my_script #your path and filename
[Install]
WantedBy=halt.target reboot.target shutdown.target
vi /lib/systemd/system-shutdown/stopSrv.service Ubuntu 16.04
[Unit]
Description=Run command at shutdown
# 假设要执行的命令依赖网络
Requires=network.target
DefaultDependencies=no
Before=shutdown.target re
/homeassistant/custom_components/sonoff
.
.
.
sonoff:
username: '+86手机号' #易微联APP帐号
password: '密码' #易微联APP密码
scan_interval: 60
grace_period: 600
api_region: 'cn'
entity_prefix: True
debug: False
.
.
.
易微联sonoff改造开关本身支持天猫精灵,小爱同学这些,关键价格还十分亲民。为什么偏偏为了接入HA刷固件,失去保修,失去易微联APP本身的控制,这样真的十分方便吗?
小白一直没有放弃易微联sonoff直接接入HA的想法,易微联API接口都看了好几遍。没功底没看懂。哈哈。
就在昨天,爬谷歌看见老外写了一个插件,马上折腾,心里别提有多高兴了。
目前插件只支持:Sonoff Basic,Sonoff 4CH Pro(R2),sonoff S20, Gang Generic Wall Switch,Gang Generic Wall Switch,WHDTS WiFi Momentary Inching Relay。
一般情况我们都是买Sonoff Basic,或者Sonoff RF。
下载插件,放进custom_components目录
custom_components
├── sonoff.py
└── switch
└── sonoff.py
然后HA配置configuration.yaml:
sonoff:
username:
password: [password]
scan_interval: 60 (optional)
grace_period: 600 (optional)
api_region: 'eu' (optional)
然后重启HA,sonoff里面该插件支持的设备就自动出现了。
websocket error: Connection is already closed
apk add --update python
apk add --update py-pip
pip install websocket-client==0.54.0
一般来说centos主要用于服务器端,所以很少开启图形化界面,但是有时候为了工作方便也会偶尔开启图形界面,下面就让简单谈谈如何开启图形化界面,当然简化安装是没有这个程序的需要自行安装,可以yum安装下.
CentOS 作为服务器的操作系统是很常见的,但是因为需要稳定而没有很时髦的更新,所以很少做为桌面环境。在服务器上通常不需要安装桌面环境,最小化地安装 CentOS(也就是 minimal CentOS) 就可以了。不过在最小化安装的 CentOS 中通过 YUM 来安装桌面环境也是非常方便的。
使用 yum groupinstall 指令很容易就能安装上图形界面的桌面系统
yum 可以以程序组的模式来安装成套的软件包。支持的软件包可以通过,
# yum grouplist
查询到。在 group 软件包中,Desktop、Desktop Platform、KDE Desktop、X Window System 是主要的桌面环境。
软件包列表根据系统使用的语言来显示,支持简体中文文件名。所以安装前最好用上述指令查询一下看看。如果系统使用了简体中文,而安装指令使用英文,可能会导致查询不到软件包这样的错误。下面的安装指令用的都是英语。
要安装 KDE 桌面环境,执行指令,
# yum groupinstall "X Window System" "KDE Desktop" Desktop
即可,同时安装了 3 个软件包。注意,因为 KDE Desktop 和 X Window System 两个软件包名称中间都包含空格,需要用引号引起来才行。
要安装 Gnome 桌面环境,执行指令,
# yum groupinstall "X Window System" "Desktop Platform" Desktop
即可,也是同时安装了 3 个软件包,其中 X Window System 是必须的,不管是 Gnome 还是 KDE。
既然是桌面环
curl -fsSL https://filebrowser.xyz/get.sh | bash
ps -ef|grep filebrowser
root 20135 13530 2 10:06 pts/30 00:00:00 filebrowser -r /opt -d /opt/filebrowser/filebrowser.db
root 20239 13530 0 10:06 pts/30 00:00:00 grep --color=auto filebrowser
kill 20135
docker run -d --name portainer --restart always \
-p 9123:9000 \
-v /opt/seafile/ssl:/certs \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /opt/portainer/pub:/public \
portainer/portainer --ssl --sslcert /certs/13ua.com.crt --sslkey /certs/13ua.com.key
#查看docker compose版本
docker-compose version
#查看pip版本
pip -v
#上一条语句没有显示版本信息则运行下面语句安装 python-pip
yum -y install epel-release
yum -y install python-pip
#查看pip版本
pip -v
#pip进行升级
pip install --upgrade pip
#进行安装compose 第一条语句报错执行第二条,执行成功则跳过第二条
pip install docker-compose
pip install docker-compose --ignore-installed requests
docker-compose -version
curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
Cannot open self /usr/local/bin/docker-compose or archive /usr/local/bin/docker-compose.pkg
cd /usr/local/bin
rm -rf docker-compose
wget https://github.com/docker/compose/releases/download/1.14.0-rc2/docker-compose-Linux-x86_64
mv docker-compose-Linux-x86_64 docker-compose
[root@betty ~]# cd /etc/yum.repos.d/
[root@betty yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@betty yum.repos.d]# yum makecache
[root@betty yum.repos.d]# yum -y update
···
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
···
[root@localhost ~]# yum update
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: centos.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 bind-libs.x86_64.32.9.9.4-61.el7 将被 升级
---> 软件包 bind-libs.x86_64.32.9.9.4-61.el7_5.1 将被 更新
---> 软件包 bind-libs-lite.x86_64.32.9.9.4-61.el7 将被 升级
---> 软件包 bind-libs-lite.x86_64.32.9.9.4-61.el7_5.1 将被 更新
---> 软件包 bind-license.noarch.32.9.9.4-61.el7 将被 升级
---> 软件包 bind-license.noarch.32.9.9.4-61.el7_5.1 将被 更新
...
...
验证中 : 32:bind-license-9.9.4-61.el7.noarch 8/8
更新完毕:
bind-libs.x86_64 32:9.9.4-61.el7_5.1
bind-libs-lite.x86_64 32:9.9.4-61.el7_5.1
bind-license.noarch 32:9.9.4-61.el7_5.1
bind-utils.x86_64 32:9.9.4-61.el7_5.1
完毕!
[root@localhost ~]#
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hos
yum list installed | grep openssh-server
yum install openssh-server
···
Port 22
···
ListemAddress 0.0.0.0
ListemAddress ::
···
PermitRootLogin yes
···
service sshd start
systemctl enable sshd
ip addr
,查看当前ip地址 vi /etc/sysconfig/network-scripts/ifcfg-ens33
,修改:
BOOTPROTO="static" #修改为静态,默认为dhcp
IPADDR="192.168.2.219" #静态ip地址
NETMASK="255.255.255.0" #子网掩码
GATEWAY="192.168.2.1" #网关地址
DNS1="114.114.114.114" #DNS服务器