分类 - 5.CentOS7

自动运行 自动脚本    2022-01-22 18:27:47    7    0    0

如果你在linux系统上启动了很多自己的服务,如果直接执行系统的reboot或者shutdown命令,可能会发生一些异常的现象,所以我们在重启和关机前,应该按照我们的意愿去自定义清理一些服务或者资源等。但是网上的方式大多是以Centos6为教程,修改chkconfig和rc0.d,rc6.d的内容。在Centos7中以及不适用了。
本文就介绍一下在Centos7系统中,使用systemctl的方式来自定义关机前执行脚本。

1、创建systemd服务

vi /usr/lib/systemd/system/stopSrv.service Centos
创建该文件然后加入下面的内容,需要把ExecStart=/home/my_script这一行换成自己的脚本路径

  1. [Unit]
  2. Description=close services before reboot and shutdown
  3. DefaultDependencies=no
  4. Before=shutdown.target reboot.target halt.target
  5. # This works because it is installed in the target and will be
  6. # executed before the target state is entered
  7. # Also consider kexec.target
  8. [Service]
  9. Type=oneshot
  10. ExecStart=/home/my_script #your path and filename
  11. [Install]
  12. WantedBy=halt.target reboot.target shutdown.target

vi /lib/systemd/system-shutdown/stopSrv.service Ubuntu 16.04

  1. [Unit]
  2. Description=Run command at shutdown
  3. # 假设要执行的命令依赖网络
  4. Requires=network.target
  5. DefaultDependencies=no
  6. Before=shutdown.target re
homeassistant 易微联    2021-03-12 08:16:32    6    0    0

一、易微联插件

1、安装位置

  1. /homeassistant/custom_components/sonoff

2、插件内容

二、插件调用

  • 修改homeassistant配置文件 /homeassistant/configuration.yaml
  1. .
  2. .
  3. .
  4. sonoff:
  5. username: '+86手机号' #易微联APP帐号
  6. password: '密码' #易微联APP密码
  7. scan_interval: 60
  8. grace_period: 600
  9. api_region: 'cn'
  10. entity_prefix: True
  11. debug: False
  12. .
  13. .
  14. .

三、重启 homeassistant

2020-10-22 19:54:30    45    0    2

易微联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里面该插件支持的设备就自动出现了。

参考资料:https://github.com/peterbuga/HASS-sonoff-ewelink

特殊注意

  • 当你发现日志中出现
  1. websocket error: Connection is already closed
  • 可做如下操作
  1. apk add --update python
  2. apk add --update py-pip
  3. pip install websocket-client==0.54.0
脚本    2020-05-05 18:58:40    20    0    0
find /path -mtime +30 -type f -name \*.zip -exec rm -f {} \; 以上就是删除30天前的指定路径下的所有zip文件 ![](/api/file/getImage?fileId=5f82ec8b3c9b99002d0000cf)
linux centos 图形界面    2020-02-22 18:07:41    10    0    0

一般来说centos主要用于服务器端,所以很少开启图形化界面,但是有时候为了工作方便也会偶尔开启图形界面,下面就让简单谈谈如何开启图形化界面,当然简化安装是没有这个程序的需要自行安装,可以yum安装下.

CentOS 作为服务器的操作系统是很常见的,但是因为需要稳定而没有很时髦的更新,所以很少做为桌面环境。在服务器上通常不需要安装桌面环境,最小化地安装 CentOS(也就是 minimal CentOS) 就可以了。不过在最小化安装的 CentOS 中通过 YUM 来安装桌面环境也是非常方便的。

原文:https://www.cnblogs.com/beyang/p/8513215.html

使用 yum groupinstall 指令很容易就能安装上图形界面的桌面系统

1. yum 的 group 指令

yum 可以以程序组的模式来安装成套的软件包。支持的软件包可以通过,

# yum grouplist
查询到。在 group 软件包中,Desktop、Desktop Platform、KDE Desktop、X Window System 是主要的桌面环境。

软件包列表根据系统使用的语言来显示,支持简体中文文件名。所以安装前最好用上述指令查询一下看看。如果系统使用了简体中文,而安装指令使用英文,可能会导致查询不到软件包这样的错误。下面的安装指令用的都是英语。

2. 图形桌面环境

要安装 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。

既然是桌面环

filebrowser    2019-11-22 17:23:18    94    0    0

先安装原版

 
  1. curl -fsSL https://filebrowser.xyz/get.sh | bash
 

下载“荒野无灯”版

kill    2019-11-19 10:11:31    17    0    0

ps -ef|grep [程序名]

ps -ef|grep filebrowser

  1. root 20135 13530 2 10:06 pts/30 00:00:00 filebrowser -r /opt -d /opt/filebrowser/filebrowser.db
  2. root 20239 13530 0 10:06 pts/30 00:00:00 grep --color=auto filebrowser

kill 20135

docker portainer webui    2019-11-09 20:34:24    50    0    1

安装

 
  1. docker run -d --name portainer --restart always \
  2. -p 9123:9000 \
  3. -v /opt/seafile/ssl:/certs \
  4. -v /var/run/docker.sock:/var/run/docker.sock \
  5. -v /opt/portainer/pub:/public \
  6. portainer/portainer --ssl --sslcert /certs/13ua.com.crt --sslkey /certs/13ua.com.key
  • public 为汉化目录
  • certs 为ssl证书目录
 
docker-compose    2019-10-02 20:18:58    20    0    1

方法1

  1. #查看docker compose版本
  2. docker-compose version
  3. #查看pip版本
  4. pip -v
  5. #上一条语句没有显示版本信息则运行下面语句安装 python-pip
  6. yum -y install epel-release
  7. yum -y install python-pip
  8. #查看pip版本
  9. pip -v
  10. #pip进行升级
  11. pip install --upgrade pip
  12. #进行安装compose 第一条语句报错执行第二条,执行成功则跳过第二条
  13. pip install docker-compose
  14. pip install docker-compose --ignore-installed requests
  15. docker-compose -version

方法2

  1. curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. chmod +x /usr/local/bin/docker-compose
  3. docker-compose --version
  • 如果有问题:Cannot open self /usr/local/bin/docker-compose or archive /usr/local/bin/docker-compose.pkg
  1. cd /usr/local/bin
  2. rm -rf docker-compose
  3. wget https://github.com/docker/compose/releases/download/1.14.0-rc2/docker-compose-Linux-x86_64
  4. mv docker-compose-Linux-x86_64 docker-compose
yum换源    2019-10-02 20:12:07    5    0    0

进入到yum源配置文件所在的文件夹

  1. [root@betty ~]# cd /etc/yum.repos.d/

下载163

  1. [root@betty yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

运行yum生成缓存

  1. [root@betty yum.repos.d]# yum makecache

更新系统

  1. [root@betty yum.repos.d]# yum -y update

查看结果

  1. ···
  2. Loading mirror speeds from cached hostfile
  3. * base: mirrors.163.com
  4. * extras: mirrors.163.com
  5. * updates: mirrors.163.com
  6. ···
docker    2019-10-02 20:01:47    5    0    0

安装Docker

  • 把yum包更新到最新(不要问我为什么)
  1. [root@localhost ~]# yum update
  2. 已加载插件:fastestmirror, langpacks
  3. Loading mirror speeds from cached hostfile
  4. * base: centos.ustc.edu.cn
  5. * extras: mirrors.aliyun.com
  6. * updates: centos.ustc.edu.cn
  7. 正在解决依赖关系
  8. --> 正在检查事务
  9. ---> 软件包 bind-libs.x86_64.32.9.9.4-61.el7 将被 升级
  10. ---> 软件包 bind-libs.x86_64.32.9.9.4-61.el7_5.1 将被 更新
  11. ---> 软件包 bind-libs-lite.x86_64.32.9.9.4-61.el7 将被 升级
  12. ---> 软件包 bind-libs-lite.x86_64.32.9.9.4-61.el7_5.1 将被 更新
  13. ---> 软件包 bind-license.noarch.32.9.9.4-61.el7 将被 升级
  14. ---> 软件包 bind-license.noarch.32.9.9.4-61.el7_5.1 将被 更新
  15. ...
  16. ...
  17. 验证中 : 32:bind-license-9.9.4-61.el7.noarch 8/8
  18. 更新完毕:
  19. bind-libs.x86_64 32:9.9.4-61.el7_5.1
  20. bind-libs-lite.x86_64 32:9.9.4-61.el7_5.1
  21. bind-license.noarch 32:9.9.4-61.el7_5.1
  22. bind-utils.x86_64 32:9.9.4-61.el7_5.1
  23. 完毕!
  24. [root@localhost ~]#
  • 安装需要的软件包
  1. [root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
  2. 已加载插件:fastestmirror, langpacks
  3. Loading mirror speeds from cached hos
ssh    2019-10-01 23:50:45    17    0    0

首先,要确保CentOS7安装了 openssh-server

  1. yum list installed | grep openssh-server
  • 此处显示已经安装了 openssh-server,如果没任何输出显示,表示没有安装

安装openssh-server

  1. yum install openssh-server

开启SSH服务

  • 到了/etc/ssh/目录下的sshd服务配置文件 sshd_config,用Vim编辑器打开
  1. ···
  2. Port 22
  3. ···
  4. ListemAddress 0.0.0.0
  5. ListemAddress ::
  6. ···
  7. PermitRootLogin yes
  8. ···
  • 保存退出

启动服务,加入开机启动

  1. service sshd start
  2. systemctl enable sshd

over

ip    2019-10-01 23:30:06    25    0    0

Centos7的网络IP地址配置文件在/etc/sysconfig/network-scripts/下

  • 首先,键入命令ip addr,查看当前ip地址
  • 键入命令vi /etc/sysconfig/network-scripts/ifcfg-ens33,修改:
  1. BOOTPROTO="static" #修改为静态,默认为dhcp
  2. IPADDR="192.168.2.219" #静态ip地址
  3. NETMASK="255.255.255.0" #子网掩码
  4. GATEWAY="192.168.2.1" #网关地址
  5. DNS1="114.114.114.114" #DNS服务器

保存重启,OK了。