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 启动虚拟机,并进入。 ...

CTF(鶸)密码学

Python Algorithm CTF(鶸)密码学 一、摩斯密码 1、特点 题面只有三个值。 2、解题思路 转换成 ascii,出现 flag 标识符即结束,否则根据转后的数据进行下一步处理。 二、栅栏密码 1、特点 密文字符串出间隔性的出现 flag 的标识符。 2、解题思路 分栏破译。 def inputData(): string = input("请输入栅栏加密的文字:") code = input("请输入分栏:(0代表从2到6逐个分栏):") code = int(code) return string,code def code2(string): string_temp = [] string_temp.append(string[0::2]) string_temp.append(string[1::2]) print("分成2栏的结果是:%s" % (''.join(string_temp))) def code3(string): string_temp = [] string_temp.append(string[0::3]) string_temp.append(string[1::3]) string_temp.append(string[2::3]) print("分成3栏的结果是:%s" % (''.join(string_temp))) def code4(string): string_temp = [] string_temp.append(string[0::4]) string_temp.append(string[1::4]) string_temp.append(string[2::4]) string_temp.append(string[3::4]) print("分成4栏的结果是:%s" % (''.join(string_temp))) def code5(string): string_temp = [] string_temp.append(string[0::5]) string_temp.append(string[1::5]) string_temp.append(string[2::5]) string_temp.append(string[3::5]) string_temp.append(string[4::5]) print("分成5栏的结果是:%s" % (''.join(string_temp))) def code6(string): string_temp = [] string_temp.append(string[0::6]) string_temp.append(string[1::6]) string_temp.append(string[2::6]) string_temp.append(string[3::6]) string_temp.append(string[4::6]) string_temp.append(string[5::6]) print("分成6栏的结果是:%s" % (''.join(string_temp))) def main(): string, code = inputData() if (code == 0): code2(string) code3(string) code4(string) code5(string) code6(string) elif (code == 2): code2(string) elif (code == 3): code3(string) elif (code == 4): code4(string) elif (code == 5): code4(string) elif (code == 6): code4(string) else: print("error") if __name__ == "__main__": main() 三、Rot13 1、特点 凯撒加密的第十二种方式,但是可以字符和数字混合在其中。 ...

Deepin 切换壁纸小工具

Linux Python Deepin 切换壁纸小工具 切换壁纸这种事,找到接口,一行代码就可以解决,本来打算用 bash 脚本,但是考虑到随机选取壁纸等因素,用 python 的 os 模块完成任务。 一、思路 找到切换壁纸的接口 设置壁纸库(文件夹) python 脚本完成功能 半小时触发脚本自动切换壁纸 二、实现过程 1、切换壁纸接口 本脚本只在 Linux 下使用。 在 Linux 下(准确说是 GNOME 桌面),通过 gsettings set 指令完成对特定值(壁纸文件位置)进行修改,即可修改壁纸。 # Ubuntu 下切换指令(注意有个 file) gsettings set org.gnome.desktop.background picture-uri "file:/home/user/Desktop/1.jpg" #Deepin 下切换指令(注意没有 file) gsettings set com.deepin.wrap.gnome.desktop.background picture-uri "/home/user/Desktop/1.jpg" 2、设置壁纸库 这步没什么好说的啊,把喜欢的壁纸放在一个文件夹下,方便之后的存取使用。 3、python 完成功能 直接上代码,看代码注释就好了。 # -*- coding: utf-8 -*- # @Date : 2018-05-21 12:07:17 # @Author : Light (halysl0817@gmail.com) # @Link : ${link} # @Version : $Id$ import os import random """ TODO(halysl0817@gmail.com):Change the wallpaper by changing the time 利用linux下的crontab工具实现半小时切换一次, */30 * * * * python /xxx/changebackground.py """ # 更换壁纸指令,此为deepin更换指令,不代表所有linux发行版更换指令 cmd = "gsettings set com.deepin.wrap.gnome.desktop.background picture-uri " # 图片目录,用户可自主更换 path = "/home/light/Documents/code/spider-on-lol/lolSpider/lolSpider/img/hero_skin_img/full/" # 利用os.listdir()方法获取图片目录下的所有文件名的列表 pic_list = os.listdir(path) # 确切的文件位置,以及确切的更换指令 real_path = path + str(random.choices(pic_list))[2:-2] real_cmd = cmd + "\"" + real_path +"\"" # 执行 os.system(real_cmd) 4、自动切换壁纸 利用 Linux 下的 crontab 完成定时任务。 ...

dmidecode 的使用

Linux dmidecode 的使用 dmidecode 命令可以让你在 Linux 系统下获取有关硬件方面的信息。dmidecode 的作用是将 DMI 数据库中的信息解码,以可读的文本方式显示。由于 DMI 信息可以人为修改,因此里面的信息不一定是系统准确的信息。dmidecode 遵循 SMBIOS/DMI 标准,其输出的信息包括 BIOS、系统、主板、处理器、内存、缓存等等。 DMI(Desktop Management Interface,DMI)就是帮助收集电脑系统信息的管理系统,DMI 信息的收集必须在严格遵照 SMBIOS 规范的前提下进行。SMBIOS(System Management BIOS)是主板或系统制造者以标准格式显示产品管理信息所需遵循的统一规范。SMBIOS 和 DMI 是由行业指导机构 Desktop Management Task Force(DMTF) 起草的开放性的技术标准,其中DMI设计适用于任何的平台和操作系统。 DMI 充当了管理工具和系统层之间接口的角色。它建立了标准的可管理系统更加方便了电脑厂商和用户对系统的了解。DMI 的主要组成部分是 Management Information Format(MIF) 数据库。这个数据库包括了所有有关电脑系统和配件的信息。通过 DMI,用户可以获取序列号、电脑厂商、串口信息以及其它系统配件信息。 语法 dmidecode [选项] 选项 -d:(default:/dev/mem)从设备文件读取信息,输出内容与不加参数标准输出相同。 -h:显示帮助信息。 -s:只显示指定DMI字符串的信息。(string) -t:只显示指定条目的信息。(type) -u:显示未解码的原始条目内容。 –dump-bin file:将DMI数据转储到一个二进制文件中。 –from-dump FILE:从一个二进制文件读取DMI数据。 -V:显示版本信息。 dmidecode参数string及type列表: Valid string keywords are: 下列选项,可通过 dmidecode -s xxx 来查看,对于特定的单项,更方便获取结果。 bios-vendor bios-version bios-release-date system-manufacturer system-product-name system-version system-serial-number system-uuid baseboard-manufacturer baseboard-product-name baseboard-version baseboard-serial-number baseboard-asset-tag chassis-manufacturer chassis-type chassis-version chassis-serial-number chassis-asset-tag processor-family processor-manufacturer processor-version processor-frequency Valid type keywords are: 下面选项,可通过 dmidecode -t xxx 来获取信息,一般是某一单类别硬件信息。 ...

find 的使用

Linux find 的使用 find 用于 Linux 的查找,它的使用方法比较多。 # 常规根据文件名查询 find / -name xxx # 查找文件夹 find / -name -type d xxx # 根据文件属性进行查找 find / -user root -ls find / -user root -group root -ls find / -uid 1 -gid 1 -ls find / -nouser -ls # 根据文件权限进行查找 find / -perm 755 -type f -ls find / -perm 750 -type d -ls find / -perm /750 -type d -ls # 表示任何一个目录只要其所有者具有读写执行中的任何一项权限,或是其所属组具有读和执行中的任何一项权限,就可以符合查找条件 find / -perm -750 -type d -ls # 表示所要查找的目录其所有者必须具有读写执行权限,同时其所属组必须具有读和执行权限,对其他用户的权限没有要求 link 根据文件属性或权限进行find查找

GitHub 配置 ssh key

Github SSH GitHub 配置 ssh key 生成 key ssh-keygen -t rsa -C "your_email@example.com" 代码参数含义: -t 指定密钥类型,默认是 rsa ,可以省略。 -C 设置注释文字,比如邮箱。 -f 指定密钥文件存储文件名。 然后在交互式页面,指定文件位置,推荐设置为 ~/.ssh/id_rsa_github。 然后回车,回车,等待命令结束后,通过 ls -al ~/.ssh 观察是否多了两个文件 id_rsa_github 和 id_rsa_github.pub。 将 key.pub 添加到 GitHub 账户 a. 首先你需要拷贝 id_rsa_github.pub 文件的内容,你可以用编辑器打开文件复制,也可以用命令复制该文件的内容,如: $ clip < ~/.ssh/id_rsa_github.pub b、登录你的github账号,从右上角的设置( Account Settings )进入,然后点击菜单栏的 SSH key 进入页面添加 SSH key。 c、点击 Add SSH key 按钮添加一个 SSH key 。把你复制的 SSH key 代码粘贴到 key 所对应的输入框中,记得 SSH key 代码的前后不要留有空格或者回车。当然,上面的 Title 所对应的输入框你也可以输入一个该 SSH key 显示在 github 上的一个别名。默认的会使用你的邮件名称。 ...

Go 的第一个爬虫

[[Go]] Web Crawler Go 的第一个爬虫 使用 Go 实现了第一个爬虫,只使用了标准模块,无第三方模块。整体难度较低,获取 http.cat 里所有猫的照片,先从入口进入,正则匹配相关图片的 url,然后通过 file.Write 实现内容的下载,在整个过程中,使用了 http、bytes、ioutil、os、regexp 等模块,对 Go 的文件模块、路径模块和正则模块有了简单的了解。 定义结构体,保存数据 var base_url = "https://http.cat" type cat struct { // 一个结构体代表一个爬取项目 name, url string } 爬取页面代码 func httpGet(url string) (data []byte, statusCode int) { // get 请求从 url 拿数据,返回 []byte, status code fmt.Printf("date:%s\turl:%s\n", time.Now(), url) resp, err := http.Get(url) if err != nil { statusCode = -100 return data, statusCode } defer resp.Body.Close() data, err = ioutil.ReadAll(resp.Body) if err != nil { statusCode = -200 return data, statusCode } statusCode = resp.StatusCode return data, statusCode } 直接返回 []byte 是方便外部处理更方便。可以直接写入,或者 string([]byte) 转换为字符串。 正则拿到 url func regexParse(data string) []cat { // 从爬虫结果中通过正则提取所有目标数据的 name 和 url imageExp := regexp.MustCompile(`\((/images/\d{3}.jpg)\)"></div><div class="Thumbnail_content__2eR9q"><div class="Thumbnail_title__2iqYK">(\d{3})</div><p>([\w-´ ]*)`) res := make([]cat, 0) tds := imageExp.FindAllStringSubmatch(data, 100) for _, value := range tds { var buffer1 bytes.Buffer var buffer2 bytes.Buffer buffer1.WriteString(value[2]) buffer1.WriteString("_") buffer1.WriteString(value[3]) name := buffer1.String() buffer2.WriteString(base_url) buffer2.WriteString(value[1]) url := buffer2.String() res = append(res, cat{name, url}) } return res } 通过 bytes.Buffer 实现字符串的拼接,还有其他几种拼接方案。正则通过 regular expressions 101 测试。 ...

grafana-backup的使用

Linux Monitoring [[Grafana]] grafana-backup的使用 这个工具依赖于 grafana api 实现数据的备份和恢复,和服务具体的部署无关,仅需要接口地址和 token。(如果需要备份组织和用户则需要配置admin的账号密码)。 安装 两种方式: 直接安装 pip install grafana-backup 源码安装 git clone https://github.com/ysde/grafana-backup-tool.git cd grafana-backup-tool pip install . tip:centos7 安装pip以及换源 yum -y install epel-release yum install python-pip pip install --upgrade pip mkdir ~/.pip echo '[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple' > ~/.pip/pip.conf 备份 备份和恢复都需要依赖配置文件,这个工具支持三种方式: 环境变量 配置硬编码 ~/.grafana-backup.json 配置 推荐使用第三种方式。 一个简易的配置类似于: { "general": { "debug": true, "verify_ssl": true, "backup_dir": "_OUTPUT_", "backup_file_format": "%Y%m%d%H%M", "pretty_print": false }, "grafana": { "url": "http://{{ ip }}:{{ port }}", "token": "{{ token }}", "search_api_limit": 5000, "default_password": "00000000", "admin_account": "", "admin_password": "" } } 上述的配置中,需要根据实际情况填写ip和端口。token的申请则使用 grafana 的 admin 用户在 web 页面上申请 admin 权限的 API 即可拿到。大致的操作路径:Configuration –> API keys –> Add API key –> Role=admin –> Add。 ...