【转载】Supervisord 的使用

Linux [[Supervisor]] 【转载】Supervisord 的使用 Supervisor(http://supervisord.org/)是用 Python 开发的一个 client/server 服务,是 Linux/Unix 系统下的一个进程管理工具,不支持 Windows 系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用 Supervisor 管理的进程,当一个进程意外被杀死, supervisort 监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写 shell 脚本来控制。 因为 Supervisor 是 Python 开发的,安装前先检查一下系统否安装了 Python2.4 以上版本。 下面以 Ubuntu 18.04,Python2.7 版本环境下,介绍 Supervisor 的安装与配置步聚: 安装 supervisor sudo apt-get install supervisor supervisor 安装完成后会生成三个执行程序:supervisortd、supervisorctl、echo_supervisord_conf,分别是 supervisor 的守护进程服务(用于接收进程管理命令)、客户端(用于和守护进程通信,发送管理进程的指令)、生成初始配置文件程序。 配置 运行 supervisord 服务的时候,需要指定 supervisor 配置文件,如果没有显示指定,默认在以下目录查找: # $CWD表示运行supervisord程序的目录。 $CWD/supervisord.conf $CWD/etc/supervisord.conf /etc/supervisord.conf /etc/supervisor/supervisord.conf (since Supervisor 3.3.0) ../etc/supervisord.conf (Relative to the executable) ../supervisord.conf (Relative to the executable) 可以通过运行 echo_supervisord_conf 程序生成supervisor的初始化配置文件,如下所示: mkdir /etc/supervisor echo_supervisord_conf > /etc/supervisor/supervisord.conf 配置文件参数说明 supervisor 的配置参数较多,下面介绍一下常用的参数配置,详细的配置及说明,请参考官方文档介绍。 注:分号(;)开头的配置表示注释 ...

Cobbler 安装与配置

Linux Ubuntu [[Cobbler]] Cobbler 安装与配置 Cobbler 介绍 Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。 Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。 Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。 Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。 安装 以下操作,皆在 CentOS Linux release 7.7.1908 (Core) 实现。 检测基础环境 # 查看 selinux 和防火墙是否关闭 [root@Cobbler ~] getenforce Disabled [root@Cobbler ~] systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) 如果 getenfore 的结果不是 Disabled,那么根据 getenforce命令 去关闭 SELinux。 更新yum源 [root@Cobbler ~] curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [root@Cobbler ~] curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo [root@Cobbler ~] yum clean all [root@Cobbler ~] yum makecache 安装 cobbler [root@Cobbler ~] yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd 启动服务 [root@Cobbler ~] systemctl start httpd.service [root@Cobbler ~] systemctl start cobblerd.service cobbler check [root@Cobbler ~] cobbler check 配置 cobbler 开机自启 $ chkconfig httpd on $ chkconfig cobblerd on $ chkconfig dhcpd on $ /etc/init.d/httpd restart $ /etc/init.d/cobblerd restart $ /etc/init.d/dhcpd restart 配置 cobbler [root@Cobbler ~] cobbler check The following are potential configuration items that you may want to fix: 1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work. This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it. 2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network. 3 : change 'disable' to 'no' in /etc/xinetd.d/tftp 4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely. Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements. 5 : enable and start rsyncd.service with systemctl 6 : debmirror package is not installed, it will be required to manage debian deployments and repositories 7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one 8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them Restart cobblerd and then run 'cobbler sync' to apply changes. 上面指出了八项问题,逐一解决。 ...

IP 命令的使用和解释

Linux Network IP 命令的使用和解释 ip 是网络架构中不可缺少的概念。这里的 ip 指的是 Linux 的命令,查看 man 的结果,ip - show / manipulate routing, network devices, interfaces and tunnels,可见这个命令可以控制路由,网络设备,网卡和隧道。 使用 Usage: ip [ OPTIONS ] OBJECT { COMMAND | help } ip [ -force ] -batch filename where OBJECT := { link | address | addrlabel | route | rule | neigh | ntable | tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm | netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila | vrf | sr } OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] | -h[uman-readable] | -iec | -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } | -4 | -6 | -I | -D | -B | -0 | -l[oops] { maximum-addr-flush-attempts } | -br[ief] | -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] | -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]} 常见对象 object link 网络设备 address ip地址 addrlabel label configuration for protocol address selection route 路由 neigh arp 或者 NDISC 缓存条目管理 ntable 临近网络操作管理 tunnel 基于 IP 的隧道 tuntap TUN/TAP 设备管理 maddress 多播地址 mroute 多播路由缓存条目 mrule 多播路由策略数据库里的规则 monitor 查看 netlink 信息 xfrm IPSec 策略管理 netns 网络命名空间管理 l2tp 基于 IP 的隧道网络 tcp_metrics tcp 指标管理 token 标记的接口认证管理 常见参数 -V, -Version 显示ip命名的版本信息 -h, -human 显示人可以看懂的信息 -s, -stats 输出更多信息 -d, -details 输出更详细的信息 -f, -family 指定协议簇,可选值有 inet, inet6, bridge, ipx, dnet, mpls 或者 link -4, shortcut for -family inet -6, shortcut for -family inet6 -B, shortcut for -family bridge -c, -color 带颜色的输出 -o, -oneline 单行显示 常用命令 ip address [show] 显示 IPv4 或者 IPv6 的地址信息 ip address show up 仅展示打开的网络设备的地址信息 ip address show dev eth0 展示 eth0 设备的地址信息 ip address add 192.168.1.1/24 dev eth1 将 ip 地址赋予 eth1 ip address delete 192.168.1.1/24 dev eth1 删除 ip 地址 ip address flush dev eth4 scope global 删除所有 eth4 的所有全局 IPv4 和 IPv6 的地址 ip a 的解析 ip a 也就是 ip addr,通过它可以查看很多信息。 ...

Linux Bond 配置(Ubuntu 18.04)

Linux Network Linux Bond 配置(Ubuntu 18.04) Linux bonding驱动提供了一个把多个网络接口设备捆绑为单个的网络接口设置来使用,用于网络负载均衡及网络冗余。 七种模式 俗称 配置简称 英文名 中文名 解释 bond0 balance-rr Round-robin policy 平衡轮询策略 传输数据包顺序是依次传输,直到最后一个传输完毕,此模式提供负载平衡和容错能力。 bond1 active-backup Active-backup policy 活动备份策略 只有一个设备处于活动状态。一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得。此模式提供了容错能力。 bond2 balance-xor XOR policy 平衡策略 传输根据 (源MAC地址 xor 目标MAC地址) mod 设备数量 的布尔值选择传输设备。 此模式提供负载平衡和容错能力。 bond3 broadcast Broadcast policy 广播策略 将所有数据包传输给所有设备。此模式提供了容错能力。 bond4 802.3ad IEEE 802.3ad Dynamic link aggregation IEEE 802.3ad 动态链接聚合 创建共享相同的速度和双工设置的聚合组。此模式提供了容错能力。每个设备需要基于驱动的重新获取速度和全双工支持;如果使用交换机,交换机也需启用 802.3ad 模式。 bond5 balance-tlb Adaptive transmit load balancing 适配器传输负载均衡 通道绑定不需要专用的交换机支持。发出的流量根据当前负载分给每一个设备。由当前设备处理接收,如果接受的设 备传不通就用另一个设备接管当前设备正在处理的mac地址。 bond6 balance-alb Adaptive load balancing 适配器负载均衡 包括mode5,由 ARP 协商完成接收的负载。bonding驱动程序截获 ARP在本地系统发送出的请求,用其中之一的硬件地址覆盖从属设备的原地址。就像是在服务器上不同的人使用不同的硬件地址一样。 mode0,mode2 和 mode3 理论上需要静态聚合方式 bond1,mode5 和 mode6 不需要交换机端的设置,网卡能自动聚合 bond4 需要支持 802.3ad,配置交换机 目的 整合两个千兆网口,将速率突破 1000 Mb/s。决定使用 bond6 实现。 ...

Ubuntu 18.04升级内核以及内存性能研究

Linux Ubuntu Ubuntu 18.04升级内核以及内存性能研究 自从用上了 AMD 7002 CPU之后,服务器上出现了 EDAC amd64: Error: F0 not found, device 0x1460 (broken BIOS?)。 通过 suse 的论坛支持,确定这是因为 “AMD ROMA” 这一代太高级了,Linux Kernel 没跟上,所以会出现这个问题。Ubuntu 18.04 的内核版本是 4.15.0-55-generic;Ubuntu 20.04 的内核版本是 5.4.0-33-generic;官网提供的稳定版内核版本是 5.7.2-050702-generic。 那么就要评估要不要升级内核了?是直接升级操作系统还是仅升级内核? 要不要升级内核? 这需要判断这个错误对 性能 和 稳定性 的影响程度。 先整理出两台机器: mtest01:7542, 64G 2933 DDR4 * 8,内核 4.15.0-55-generic mtest02: 7542, 64G 2933 DDR4 * 8,内核 5.7.2-050702-generic 重启后,通过 dmesg 检测,发现 mtest01 出现 EDAC amd64: Error: F0 not found, device 0x1460 (broken BIOS?) 问题,而 mtest02 没出现这个问题。 ...

Ubuntu 18.4 通用配置脚本

Linux Ubuntu Ubuntu 18.4 通用配置脚本 配置 ip 先决条件:网口名为 eno1 且为联通状态,若不是,请手动修改。 #! /bin/bash # config_ip.sh # sh config_ip.sh eno1 192.168.1.xxx 192.168.1.1 mv /etc/netplan /etc/netplan.bk mkdir -p /etc/netplan/ touch /etc/netplan/01-netcfg.yaml cat > /etc/netplan/01-netcfg.yaml<<EOF # This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets: $1: addresses: [$2/24] gateway4: $3 nameservers: addresses: - "$3" EOF cat /etc/netplan/01-netcfg.yaml echo 'Finish!' netplan apply if [ $? -eq 0] then echo 'Apply Success!' else echo 'Apply Failure!' fi 配置 DNS #! /bin/bash # config_dns.sh # sh config_dns.sh 192.168.1.x mv /etc/systemd/resolved.conf /etc/systemd/resolved.conf.bk cat > /etc/systemd/resolved.conf <<EOF [Resolve] DNS=$1 #FallbackDNS= #Domains= #LLMNR=no #MulticastDNS=no #DNSSEC=no #Cache=yes #DNSStubListener=yes EOF 配置源 #! /bin/bash # config_source.sh # sh config_source.sh mv /etc/apt/sources.list /etc/apt/sources.list.bk cat > /etc/apt/sources.list <<EOF # tsinghua deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://packages.grafana.com/oss/deb stable main deb-src https://packages.grafana.com/oss/deb stable main deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse # aliyun deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse # ubuntu deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse EOF apt-get update 配置集群免密登陆 生成默认密钥对 ssh-keygen -t rsa -C "default_key@default.namespace" ls ~/.ssh/ 获取认证文件 ssh-copy-id -i ~/.ssh/id_rsa xxx@xxx 通过生成的密钥通过 ssh-copy-id 指定一台机器,那么那台机器的 ~/.ssh/authorized_keys 就会更新,录入一条新的数据。 ...

Ubuntu 使用光纤设备遇到的问题

Linux Ubuntu Network Ubuntu 使用光纤设备遇到的问题 已有的设备: 一台全新的带有光口的交换机 普通服务器(无光模块) 不知生产日期的 8Gb/s 的光网卡 不知生产日期的 8Gb/s 的光模块 几根 LC-LC 光纤线 该接的线都接了,连上机器发现根本没识别网卡,光模块上的三个灯一直闪烁,我寻思👴没用过光纤,这到底该怎么排查呢。根据这篇文档进行操作。 识别 HBA 卡 # lspci | grep -i ql <== 由于lspci显示连接的pci设备过多,通过grep查找 82:01.0 Ethernet controller: QLogic Corp. ISP4032-based Ethernet IPv6 NIC 82:01.1 Network controller: QLogic Corp. ISP4032-based iSCSI TOE IPv6 HBA 查看是否有驱动 # lsmod | grep -i ql qla2xxx 260462 0 iscsi_boot_sysfs 16000 1 qla2xxx libiscsi 57278 4 qla2xxx,libiscsi_tcp,iscsi_tcp,ib_iser scsi_transport_iscsi 89279 5 qla2xxx,iscsi_tcp,ib_iser,libiscsi 驱动可能有点老,但毕竟也加载了。 查看使用信息 祭出 dmesg。 $ dmesg | grep -i ql xxxxxx xxxxxx xxxxxxx cable unplugged 电缆不通电?继续查,都是说线没插好或者驱动有问题。重新安装驱动再重启网络服务,无效。 ...

Ubuntu 修改时区和更新时间

Linux Ubuntu Ubuntu 修改时区和更新时间 修改时区 先查看当前系统时区。 root@ubuntu:/# date -R Wed, 06 May 2020 04:49:31 -0400 结果时区是:-0400 我需要的是东八区,这儿显示不是,所以需要设置一个时区。 # 运行tzselect root@ubuntu:/# tzselect # 选择亚洲 Asia,确认之后选择中国(China),最后选择北京(Beijing) Please identify a location so that time zone rules can be set correctly. Please select a continent, ocean, "coord", or "TZ". 1) Africa 2) Americas 3) Antarctica 4) Asia 5) Atlantic Ocean 6) Australia 7) Europe 8) Indian Ocean 9) Pacific Ocean 10) coord - I want to use geographical coordinates. 11) TZ - I want to specify the time zone using the Posix TZ format. #? 4 Please select a country whose clocks agree with yours. 1) Afghanistan 18) Israel 35) Palestine 2) Armenia 19) Japan 36) Philippines 3) Azerbaijan 20) Jordan 37) Qatar 4) Bahrain 21) Kazakhstan 38) Russia 5) Bangladesh 22) Korea (North) 39) Saudi Arabia 6) Bhutan 23) Korea (South) 40) Singapore 7) Brunei 24) Kuwait 41) Sri Lanka 8) Cambodia 25) Kyrgyzstan 42) Syria 9) China 26) Laos 43) Taiwan 10) Cyprus 27) Lebanon 44) Tajikistan 11) East Timor 28) Macau 45) Thailand 12) Georgia 29) Malaysia 46) Turkmenistan 13) Hong Kong 30) Mongolia 47) United Arab Emirates 14) India 31) Myanmar (Burma) 48) Uzbekistan 15) Indonesia 32) Nepal 49) Vietnam 16) Iran 33) Oman 50) Yemen 17) Iraq 34) Pakistan #? 9 Please select one of the following time zone regions. 1) Beijing Time 2) Xinjiang Time #? 1 The following information has been given: China Beijing Time Therefore TZ='Asia/Shanghai' will be used. Selected time is now: Wed May 6 16:49:49 CST 2020. Universal Time is now: Wed May 6 08:49:49 UTC 2020. Is the above information OK? 1) Yes 2) No #? 1 You can make this change permanent for yourself by appending the line TZ='Asia/Shanghai'; export TZ to the file '.profile' in your home directory; then log out and log in again. Here is that TZ value again, this time on standard output so that you can use the /usr/bin/tzselect command in shell scripts: Asia/Shanghai 复制文件到 /etc 目录下。 ...

Ubuntu 安装 ftp 服务

Linux Ubuntu Network Ubuntu 安装 ftp 服务 这是一个很简单的需求,相关的博文也相当多,安装的过程非常简单,但是配置相关的说明有些分散。 主要几步: 可选:创建目录 安装服务 写配置文件 访问服务 最麻烦的在于 写配置文件,ftp 通过文本格式的配置文件实现了权限管理,用户管理,目录管理和网络管理。 安装服务 $ apt-get install vsftpd vsftpd 意思为 “very secure FTP daemon(非常安全的FTP进程)”,当然只有更安全没有最安全。 那它到底安全在哪里呢,主要体现在以下两点: 权限控制,vsftpd 以一般用户登录,用户权限相对较小,对于系统就越安全,对于用户需要的系统级指令大部分被整合到 vsftpd 中了,用户不需要申请更高权限就足以完成绝大部分 ftp 指令;此外对于 ftp 本身内部的读写控制,vsftpd 也足以通过配置文件控制了; 目录限制,vsftpd 通过 chroot 可以控制 ftp 登录用户所能看到的目录范围,即限定 ftp 用户看到的根目录为系统中某一个目录,如此一个 ftp 用户就除了看到自己的 ftp 根目录不能看到其他比如配置文件、系统更目录等,保护了系统。 写配置文件 从安全的角度来看,尽量不要启用匿名;同时尽量使用一个统一的目录,方便管理(这样的考虑是因为将 ftp 作为一个统一的文件传输管理系统,如果每个用户单独目录就很难提到共享这个概念)。 还有个 主动模式/被动模式 的区别,具体的区别可以参考 Ubuntu 14.04 配置vsftpd实现FTP服务器 - 通过FTP连接AWS 的第 2 章。我的需求是使用被动模式。 从上述所说,重要的配置如下: anonymous_enable=NO # 不允许匿名用户登录 local_enable=YES # 允许本地用户组的用户登录 write_enable=YES # 允许本地用户上传文件 local_root = /home/xxxx/ftp # 本地用户登入时,将被切换到定义的目录下,默认值为各用户的家目录,通过这个指定目录,该目录需要手动创建 #使用被动模式 pasv_enable=YES pasv_min_port=1024 pasv_max_port=1048 pasv_address=你的访问IP(服务器外网IP) 更多的配置信息可以参考文末的参考链接前两项。 ...

Ubuntu 搭建 Gitlab

Linux Ubuntu [[GitLab]] Ubuntu 搭建 Gitlab 准备工作 $ sudo apt-get install ruby vim curl openssh-server ca-certificates $ gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/ $ bundle config mirror.https://rubygems.org https://mirrors.tuna.tsinghua.edu.cn/rubygems 安装 Gitlab Gitlab 官网找到的下载链接都是 30 天适用的企业版本,其实把 gitlab-ee 改成 gitlab-ce 即可。 curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash # GitLab: 13.0.1 (74623c80da9) FOSS # GitLab Shell: 13.2.0 # PostgreSQL: 11.7 sudo apt-get install gitlab-ce 后面就通过浏览器访问,配置自定义项目。 关于公钥密钥数据传输,这里掠过不谈。 备份数据 # 会自动在 /var/opt/gitlab/backups 目录下生成一个备份文件 gitlab-rake gitlab:backup:create # 修改备份地址 vi /etc/gitlab/gitlab.rb ... gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" ... vi /etc/crontab # 添加定时任务,每天凌晨两点,执行 gitlab 备份 0 2 * * * root /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1 恢复数据 确认新老机器的gitlab服务版本一致。 ...