【转载】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 的配置参数较多,下面介绍一下常用的参数配置,详细的配置及说明,请参考官方文档介绍。 注:分号(;)开头的配置表示注释 ...

ansible tower 的搭建

Linux Ansible ansible tower 的搭建 下载 axel https://releases.ansible.com/ansible-tower/setup-bundle/ansible-tower-setup-bundle-3.7.3-1.tar.gz -n 10 可能会出现:重定向过多 的问题,手动编译 axel 或者使用 wget 即可。 # 下载源码包 wget -O axel-2.16.1.tar.gz https://file.idait.cn/axel-2.16.1.tar.gz # 解压 tar xzvf axel-2.16.1.tar.gz # 进入目录 cd axel-2.16.1/ # 检查编译 ./configure --prefix=/usr/local/axel # 报错 No package 'openssl' found,则 yum install openssl-devel make && make install #报错请安装 gcc 工具 不报错请忽略 yum groupinstall "Development tools" #axel 执行路径 echo 'PATH=/usr/local/axel/bin:$PATH' > /etc/profile.d/axel.sh #使文件生效 . /etc/profile 配置并安装 cd /opt/ tar xf ansible-tower-setup-bundle-3.7.3-1.tar.gz cd ansible-tower-setup-bundle-3.7.3-1/ # 配置密码 vim inventory [tower] localhost ansible_connection=local [database] [all:vars] admin_password='abcdefg' pg_host='' pg_port='' pg_database='awx' pg_username='awx' pg_password='abcdefg' # 安装 ./setup.sh 破解 # 安装 pip cd /tmp axel https://bootstrap.pypa.io/get-pip.py -n 10 python get-pip.py # 安装 uncompyle6 pip install uncompyle6 cd /var/lib/awx/venv/awx/lib/python3.6/site-packages/tower_license ls -al 总用量 12 -rw-r--r-- 1 root root 8348 9月 28 16:00 __init__.pyc drwxr-xr-x 2 root root 37 11月 15 04:02 __pycache__ # 反汇编 init.pyc uncompyle6 __init__.pyc >__init__.py # 修改 __init__.py 文件 def _check_cloudforms_subscription(self): return True #添加这一行 if os.path.exists('/var/lib/awx/i18n.db'): return True else: if os.path.isdir('/opt/rh/cfme-appliance'): if os.path.isdir('/opt/rh/cfme-gemset'): pass try: has_rpms = subprocess.call(['rpm', '--quiet', '-q', 'cfme', 'cfme-appliance', 'cfme-gemset']) if has_rpms == 0: return True except OSError: pass return False .... # 修改 "license_date=253370764800L" 为 "license_date=253370764800" def _generate_cloudforms_subscription(self): self._attrs.update(dict(company_name='Red Hat CloudForms License', instance_count=MAX_INSTANCES, license_date=253370764800, #修改 license_key='xxxx', license_type='enterprise', subscription_name='Red Hat CloudForms License')) ... #------------------------------------------------------------------ #修改完重新编译一下 [root@tower tower_license]# python3 -m py_compile __init__.py [root@tower tower_license]# python3 -O -m py_compile __init__.py #重启服务 [root@tower tower_license]# ansible-tower-service restart

ansible vault 的使用

Linux Ops Ansible ansible vault 的使用 ansible 在某些特殊的操作,例如 become 提取操作,再或者有些配置文件有机密信息,不想明文保存,那么就需要用到 vault 这个工具。它随着 ansible 发行,调用方式为 ansible-vault。 在不是非常保密严格的场合,可以只配置 2-3 个 vault 密码,去加密 ansible 用到的所有文件。 现在假设当前目录下有以下文件: ansible.cfg hosts hello.yml 那么除了 ansible.cfg 不能被加密,其他数据都可以加密。相当于用一个密码隐藏另一堆机密数据。 模块说明 create: 创建一个新文件,并直接对其进行加密 decrypt: 解密文件 edit: 用于编辑 ansible-vault 加密过的文件 encrypy: 加密文件 encrypt_strin: 加密字符串,字符串从命令行获取 view: 查看经过加密的文件 rekey: 重新设置密码 每个模块都很容易理解。 每个模块的作用可以参考: ansible笔记(43):使用 ansible-vault 加密数据 Ansible 加密模块 Vault 使用方式 这里提供两种加密明文密码的使用姿势。 首先,我们需要创造一个 vault 的密码,这个密码可以人工创造,或者交给 openssl 自动生成,存储在特定文件里。 $ openssl rand -base64 100 > vault.pass 接着编辑 ansible.cfg 文件(该文件绝不能被 vault 加密)。 ...

ansible 运行持续进程及配置环境变量

Linux Ops Ansible ansible 运行持续进程及配置环境变量 配置环境变量 ansible 是通过 ssh 登陆的,同时也是 Non-Login 的方式登陆,这种登陆情况下,部分环境参数是拿不到的。Login 和 Non-Login 的区别可以参考 Difference between Login shell and Non login shell。 那么如果一行 shell 运行的指令需要用到环境参数该怎么处理? 根据 Non-Login shell 调用顺序,~/.bashrc 是会被调用的,所以可以想办法把参数文件写在 ~/.bashrc 中,这样就可以运行 shell。 另一种思路是,不想破坏系统的 ~/.bashrc 文件,或者环境变量本身也是经常变的,那么就自制一个文件,通过 source 启用,设想很好,但是实际操作不行,我这边的环境(ubuntu 18.04 server)提示 source:command not found。有些解释是,ansible 的 shell 不是 bash,没有 bash 的特性。 但 source 的方法不行,还有另一个方法,启用 environment。 --- - hosts: all remote_user: test gather_facts: True tasks: # 在需要环境的任务下,一一指定变量,在执行过程中会导入这些变量 - name: some command need environment shell: cmd: xxx yyy zzz chdir: /your/path environment: ARGS1: 1 ARGS: 2 后台持续运行 后台持续运行的方法很多,正规点的利用 supervisord,systemd 配置一个服务,让服务在后台运行,但这需要配置文件,有没有更好的处理方法,nohup 能否在 ansible 中使用,答案是:可以。 ...

arp 实现网络传输速率倍增

Linux Network arp 实现网络传输速率倍增 测试目标 最近想要突破千兆交换机给定的极限,尝试过 bond6 实现,发现还是需要万兆交换机支持。 换个思路,先确定下目前的需求是什么: 一个主节点,配置了五个网口,每个网口配置一个 ip,定义为 192.168.1.1-5 五个普通节点,分别有一个网口且分配一个 ip,定义为 192.168.1.11-15 现在想达到的目标是: - 五个普通节点分别向主节点的不同 ip 发数据,使得主节点的网络吞吐(进口)达到 5000 Mb/s - 五个普通节点分别要求从主节点的不同 ip 取数据,使得主节点的网络吞吐(出口)达到 5000 Mb/s 测试方案也很简单,就是讲一个大文件通过 scp 传递或者要求接收的方式判断网络吞吐。 直观来看,这两个目标很容易达到,虽然连接在千兆交换机上,但是主节点连了五根线,理论可以达到 5000 Mb/s的。 实际测试过程 定义几个概念: 主节点称为 m 主节点的网口带上数字,记为 m1-m5 普通节点称为 s,五个即 s1-25 普通节点只有一个网络端口,所以网口和普通节点同名 定义两个测试过程: s1-s5 分别向 m1-m5 发送数据,记为实验一 s1-s5 分别要求 m1-m5 发送数据,记为实验二 实验结果是: 实验一的结果是,五个发送请求的带宽总和是 3000Mb/s 实验二的结果是,五个拉取请求的带宽总和是 1000Mb/s 这个结果令我有些不解,开始用工具监控数据,但不再聚焦于五个普通节点,而是专门去监控主节点的五个网口。 分析过程 主节点的五个网口的数据,实验一中,m1:1000,m2:1000,m3:3000,m4:0,m5:0;实验二中m3:1000,其他都是0。 分析到这里能解释实验现场,但是根本原因还不明确,往底层去看,可能是网络层和链路层的问题,随之想到了 arp 协议。 arp 协议定义了 ip 和 mac 地址的关系,先查下每台机器的 arp 信息,下面是大致的信息: ...

bash shell buildin command

Linux Shell bash shell buildin command 这里肤浅的以 bash 为例,实际概念应该是 shell buildin commond。 前几天,突发奇想,Linux 的可执行命令,例如 ls,cat,echo 都是可执行文件,一般在 /bin/ 下。但是 cd 却一直找不到(Ubuntu 18.04 server),通过 find 全盘搜索也找不到。 昨天在处理一个系统环境的问题时,发现 source 也找不到所在路径,就很好奇这到底是怎么了,系统如何知道 cd 或者 source 在哪里,在 path 路径中完全找不到。 在查找资料中,想起了一件事,所谓的 Linux 系统,是指 Linux 内核,而人和 Linux 打交道是通过 shell 实现的。所以 shell 可以更人性化,例如正则批量。而 source 也是 bash 的一个特性,用来导入环境变量。 可以通过 type 判断一个命令属于什么。 type: type [-afptP] name [name ...] Display information about command type. For each NAME, indicate how it would be interpreted if used as a command name. Options: -a display all locations containing an executable named NAME; includes aliases, builtins, and functions, if and only if the `-p' option is not also used -f suppress shell function lookup -P force a PATH search for each NAME, even if it is an alias, builtin, or function, and returns the name of the disk file that would be executed -p returns either the name of the disk file that would be executed, or nothing if `type -t NAME' would not return `file' -t output a single word which is one of `alias', `keyword', `function', `builtin', `file' or `', if NAME is an alias, shell reserved word, shell function, shell builtin, disk file, or not found, respectively Arguments: NAME Command name to be interpreted. Exit Status: Returns success if all of the NAMEs are found; fails if any are not found. $ type -a cd cd is a shell builtin $ type -a source source is a shell builtin $ type -a echo echo is a shell builtin echo is /bin/echo 可以看到 echo 是内建命令,但也是系统命令,那么会使用哪一个呢。 ...

centos-root LVM 扩容问题

Linux [[CentOS]] file system centos-root LVM 扩容问题 最近开了一个 jumpserver 服务,突然挂了,一查原来是系统的根目录只有50G,数据写不下了,只剩 40k 的空间。好在 centos7 默认使用 LVM 进行文件系统的挂载,那只有加盘了。 加上 1 TiB 的硬盘,通过 pvcreate /dev/sdb ,出现 Device /dev/sdb excluded by a filter。此时因为该盘可能因为有分区,所以不行,可以尝试 wipefs -a /dev/sdb 来解决问题。 然后再让 vg:centos 增加一块 pv :vgextend centos /dev/sdb。此时可能会出现 Couldn't create temporary archive name。这是因为根目录可用空间太少了,删点日志再执行这个指令就可以了。 接着 vg 就有可用空间了,使用 lvextend 增加容量:lvextend -L +1024G /dev/mapper/centos-root。这里一般不会有什么问题,会直接通过。 但是上部操作完成后,查看 df -h 还是只有 50G,因为没有让系统知道这件事。国内的资料显示需要执行:e2fsck -f /dev/mapper/centos-root 和 resize2fs /dev/mapper/centos-root。但我执行都不可以,会说 root 已经挂载,那么只能在维护模式下使用?那不就还是要重启? 在一篇英文资料中提到,可以执行 fsadm resize /dev/centos/root 通知系统文件系统大小已经变更。 ...

ceph 安装细节

Linux [[Ceph]] ceph 安装细节 根据 存储集群快速入门 进行操作。对内部一些没说明白的进行补充。 创建独立用户 useradd -m -s /bin/bash storage echo "storage ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/storage chmod 0440 /etc/sudoers.d/storage passwd storage 块设备使用 文件系统使用 常见问题 librados: client.bootstrap-osd authentication error 问题 参考: 解决。是base64加密的问题。 $ ceph auth get client.bootstrap-osd --name mon. --keyring /var/lib/ceph/mon/ceph-ceph211/keyring exported keyring for client.bootstrap-osd [client.bootstrap-osd] key = AQCi8/peqAO2FRAAyVYDh3SoE2MuTe8hmv0mzg== caps mon = "allow profile bootstrap-osd" ceph HEALTH_WARN no active mgr ceph-deploy mgr create host-name RBD image feature set mismatch 参考: RBD kernel module fails to map an image to a block device。 ...

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. 上面指出了八项问题,逐一解决。 ...

cobbler 服务在 docker 下运行

Linux [[Docker]] Cobbler cobbler 服务在 docker 下运行 主要参考 Cobbler 批量装机。 在宿主机上的 /mnt 内挂载镜像。 $ sudo mkdir /mnt/ubuntu18.04 $ sudo mkdir /mnt/centos $ sudo mount -t iso9660 -r -o ro,loop /tmp/ubuntu-18.04.3-server-amd64.iso /mnt/ubuntu18.04 $ sudo mount -t iso9660 -r -o ro,loop /tmp/CentOS-7-x86_64-DVD-1908.iso /mnt/centos 编辑自动应答脚本 ubuntu1804.seed: d-i debian-installer/locale string en_US.UTF-8 d-i console-setup/ask_detect boolean false d-i keyboard-configuration/layoutcode string us d-i keyboard-configuration/variantcode string d-i netcfg/choose_interface select auto d-i netcfg/get_hostname string $myhostname d-i netcfg/get_nameservers string 192.168.31.1 d-i netcfg/get_ipaddress string d-i netcfg/get_netmask string 255.255.255.0 d-i netcfg/get_gateway string 192.168.31.1 d-i netcfg/confirm_static boolean true d-i netcfg/without_default_route boolean true d-i netcfg/enable boolean false d-i time/zone string Asia/Shanghai d-i clock-setup/utc boolean true d-i clock-setup/ntp boolean true d-i clock-setup/ntp-server string ntp.ubuntu.com d-i mirror/country string manual d-i mirror/http/hostname string $http_server d-i mirror/http/directory string $install_source_directory d-i mirror/http/proxy string d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs # d-i partman-auto/disk string /dev/sda # d-i partman-auto/method string regular # d-i partman-auto/choose_recipe select fsm # d-i partman-lvm/device_remove_lvm boolean true # d-i partman-md/device_remove_md boolean true # d-i partman-auto/expert_recipe string \ # fsm :: \ # 1024 100% 1024 linux-swap method{ swap } \ # format{ } \ # . \ # 20480 20480 20480 ext4 method{ format } \ # mountpoint{ /tmp } \ # format{ } use_filesystem{ } filesystem{ ext4 } \ # options/relatime{ relatime } \ # . \ # 1 2048 1000000000 ext4 method{ format } \ # mountpoint{ /data } \ # format{ } use_filesystem{ } filesystem{ ext4 } \ # options/relatime{ relatime } \ # . # d-i partman-lvm/confirm_nooverwrite boolean true # d-i partman-lvm/confirm boolean true # d-i partman-partitioning/confirm_write_new_label boolean true # d-i partman/confirm_nooverwrite boolean true # d-i partman/confirm boolean true # d-i partman/choose_partition \ # select Finish partitioning and write changes to disk d-i passwd/root-login boolean true d-i passwd/root-password-crypted paddssword $1$root$6lvA6eQ6m1Qum8aZ4VWPV1 d-i passwd/make-user boolean true d-i passwd/user-fullname string firefly d-i passwd/username string firefly d-i passwd/user-password-crypted password $1$firefly$AbmnMjNadI/O7S/2vlojK. d-i passwd/user-uid string d-i passwd/user-default-groups string sudo adm cdrom dialout lpadmin plugdev sambashare d-i user-setup/allow-password-weak boolean false d-i user-setup/encrypt-home boolean false d-i apt-setup/services-select multiselect security d-i apt-setup/security_host string mirrors.aliyun.com d-i apt-setup/security_path string /ubuntu d-i debian-installer/allow_unauthenticated string false $SNIPPET('preseed_apt_repo_config') d-i pkgsel/include string ntp ssh wget vim d-i pkgsel/include string vim openssh-server d-i grub-installer/skip boolean false d-i lilo-installer/skip boolean false d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean true d-i finish-install/keep-consoles boolean false d-i finish-install/reboot_in_progress note d-i cdrom-detect/eject boolean true d-i debian-installer/exit/halt boolean false d-i debian-installer/exit/poweroff boolean false d-i preseed/early_command string wget -O- \ http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_early_default | \ /bin/sh -s d-i preseed/late_command string wget -O /target/etc/apt/sources.list http://$http_server/sources.list ; \ wget -O /target/etc/locale.conf http://$http_server/locale.conf ; \ wget -O /target/etc/default/locale http://$http_server/locale ; \ cd /target ; \ chroot ./ apt-get update 启动虚拟机,并进入。 ...