From db7b3a2889ac16be763bbaf7d6e5164e392cfac3 Mon Sep 17 00:00:00 2001 From: veypi Date: Tue, 14 Jul 2020 05:28:18 +0800 Subject: [PATCH] add cobbler raspberry --- csdn_markdown.md | 5 +- raspberry/cobbler.md | 431 +++++++++++++++++++++++++++++++++++++++++++ raspberry/main.md | 95 ++++++++-- 3 files changed, 517 insertions(+), 14 deletions(-) create mode 100644 raspberry/cobbler.md diff --git a/csdn_markdown.md b/csdn_markdown.md index 1eac086..97401ae 100644 --- a/csdn_markdown.md +++ b/csdn_markdown.md @@ -86,8 +86,8 @@ class SomeClass: ###脚注 生成一个脚注[^footnote]. - [^footnote]: 这里是 **脚注** 的 *内容*. - +[^footnote]: 这里是 **脚注** 的 *内容*. + ### 目录 用 `[TOC]`来生成目录: @@ -153,6 +153,7 @@ cond(no)->op --------- [1]: http://math.stackexchange.com/ + [2]: https://github.com/jmcmanus/pagedown-extra "Pagedown Extra" [3]: http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference [4]: http://bramp.github.io/js-sequence-diagrams/ diff --git a/raspberry/cobbler.md b/raspberry/cobbler.md new file mode 100644 index 0000000..5417c51 --- /dev/null +++ b/raspberry/cobbler.md @@ -0,0 +1,431 @@ + + +# 树莓派 配置 cobbler + +[TOC] + +## 安装 + +本来Google的方案需要从源码安装,但是尝试了下apt, 发现有现成的包,~~所以简单太多了~~ 版本太老,有额外的问题要处理. + +```bash +sudo apt install cobbler cobbler-web +# 安装过程中会让输密码 +# 该包是2.6.6版本 有点老,现在来说有好几个bug +# cobbler-web 有bug, 不兼容新的 +sudo pip install Django==1.8.9 +``` + +![image-20200712010915940](https://public.veypi.com/img/screenshot/20200712010915.png) + +```bash +# 结果输出 +Setting up liblwp-protocol-https-perl (6.07-2) ... +Setting up debmirror (1:2.32) ... +Setting up cobbler (2.6.6+dfsg1-13) ... +Considering dependency proxy for proxy_http: +Enabling module proxy. +Enabling module proxy_http. +To activate the new configuration, you need to run: + systemctl restart apache2 +Module wsgi already enabled +Enabling module rewrite. +To activate the new configuration, you need to run: + systemctl restart apache2 +ERROR: Module python does not exist! +Enabling site cobbler. +To activate the new configuration, you need to run: + systemctl reload apache2 +Created symlink /etc/systemd/system/multi-user.target.wants/cobbler.service → /lib/systemd/system/cobbler.service. +# 在重启前需要配置cobbler +``` + + + +## 配置 + +```bash +# 配置文件 /etc/cobbler/settings + +# 自动化部署系统的密码的哈希, 用下行命令生成 +# openssl passwd -1 +# $1$j9.kasLF$4v5dJWXMDUmxYTXO9qPiG. +# 密文第一项 1 指hash方式, 第二项 j9.kasLF 指的salt,这样子用以系统判断密码是否正确但是又不存储密码,密码和salt都相同时才能计算出唯一的密文 +default_password_crypted: "$1$j9.kasLF$4v5dJWXMDUmxYTXO9qPiG." + +# 设置cobbler的ip, 不要设置0.0.0.0,设置一个不隔离广播域的内网ip +server: 192.168.1.2 +# 设置的tftp ip,用于下载镜像,通常与上一个一样 +next_server: 192.168.1.2 + +# 是否开启DHCP,0不开启 1开启 +# 为了启动 pxe, 需要开启dhcp分发地址 并引导系统 到tftp server下载网络启动文件 +manage_dhcp: 1 +``` + +```bash +# 配置DHCP /etc/cobbler/dhcp.template +# 不要修改 next-server 项,该配置会自动从上面拉取变量 +# 不要修改 #for dhcp_tag in $dhcp_tags.keys(): 这一行之后的内容 +subnet 192.168.1.0 netmask 255.255.255.0 { + option routers 192.168.1.1; + option domain-name-servers 114.114.114.114,8.8.8.8; + option subnet-mask 255.255.255.0; + filename "/pxelinux.0"; + default-lease-time 2.8.0; + max-lease-time 43200; + next-server $next_server; +} +``` + +cobbler 会将 镜像存储到 /var/lib/cobbler/www/cobbler/ks_mirror/下, 注意容量和权限 + +```bash +sudo systemctl enable cobbler +sudo systemctl start cobbler +# 检测 会提示一些操作, 根据需要去做 +sudo cobbler check +sudo cobbler sync +# 会发现该指令报错 缺pxelinux.0等一批loaders +``` + +Raspberry 安装syslinux + +```bash +scp CentOS-8.2.2004-x86_64-dvd1.iso pi@x.x.x.x:/home/pi/ +ssh pi@x.x.x.x +sudo mount -o loop ~/CentOS-8.2.2004-x86_64-dvd1.iso /media/ +sudo cp /media/BaseOS/Packages/syslinux-nonlinux-6.04-4.el8.noarch.rpm /tmp +sudo apt install rpm2cpio +sudo rpm2cpio /tmp/syslinux-nonlinux-6.04-4.el8.noarch.rpm | cpio -idmv +sudo cp /tmp/usr/share/syslinux/* /usr/lib/syslinux/ +sudo umount /media + +# 现在正常 +sudo cobbler sync +``` + + + +## 导入镜像 + +```bash +# http://mirrors.aliyun.com/centos 下载镜像, 下载minimal版方便测试 +sudo mkdir /mnt/centos_mini +sudo mount -t iso9660 -o loop,ro ~/CentOS-8.2.2004-x86_64-dvd1.iso /mnt +sudo cobbler import --name=centos8-mini --arch=x86_64 --path=/mnt/centos_mini + +# 出现这个问题 +task started: 2020-07-12_041754_import +task started (id=Media import, time=Sun Jul 12 04:17:54 2020) +No signature matched in /var/lib/cobbler/www/cobbler/ks_mirror/centos8-x86_64 +!!! TASK FAILED !!! +# 使用该指令之后再导入一次 +sudo cobbler signature update +sudo cobbler import --name=centos8 --arch=x86_64 --path=/mnt + +# 出现这个问题 +Exception occured: +Exception value: 'default_kickstart' +Exception Info: + File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 87, in run + rc = self._run(self) + File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 231, in runner + self.logger + File "/usr/lib/python2.7/dist-packages/cobbler/api.py", line 938, in import_tree + return import_module.run(path,mirror_name,network_root,kickstart_file,arch,breed,os_version) + File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 132, in run + self.signature = self.scan_signatures() + File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 192, in scan_signatures + self.kickstart_file = sigdata["breeds"][breed][version]["default_kickstart"] + +# 找到 distro_signatures 文件, 替换 default_autoinstall 为 default_kickstart +sudo vim /var/lib/cobbler/distro_signatures.json +:%s/default_autoinstall/default_kickstart/ + + +sudo cobbler import --name=centos8-mini --arch=x86_64 --path=/mnt/centos_mini +## 出现错误 +creating new profile: cobbler-centos8-x86_64 +Exception occured: +Exception value: 'kickstart not found: None' +Exception Info: + File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 87, in run + rc = self._run(self) + File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 231, in runner + self.logger + File "/usr/lib/python2.7/dist-packages/cobbler/api.py", line 938, in import_tree + return import_module.run(path,mirror_name,network_root,kickstart_file,arch,breed,os_version) + File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 140, in run + os.path.walk(self.path, self.distro_adder, distros_added) + File "/usr/lib/python2.7/posixpath.py", line 239, in walk + walk(name, func, arg) + File "/usr/lib/python2.7/posixpath.py", line 239, in walk + walk(name, func, arg) + File "/usr/lib/python2.7/posixpath.py", line 231, in walk + func(arg, top, names) + File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 255, in distro_adder + adtls.append(self.add_entry(dirname,kernel,initrd)) + File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 349, in add_entry + profile.set_kickstart(self.kickstart_file) + File "/usr/lib/python2.7/dist-packages/cobbler/item_profile.py", line 211, in set_kickstart + raise CX(_("kickstart not found: %s") % kickstart) + +!!! TASK FAILED !!! +# 尝试查询distro, 发现centos已经导入,但是没有profile +sudo cobbler distro list +# 返回 +# cobbler-centos8-mini-x86_64 +sudo cobbler profile list +# 没有返回任何profile,中间出现了错误 导入distro成功但配置profile失败 + +# 手动删除 distro +sudo cobbler distro remove --name=cobbler-centos8-mini-x86_64 +# 现在我们检查到底出什么错 +sudo vim /usr/lib/python2.7/dist-packages/cobbler/item_profile.py +# 211行 如下图所示 修改,打印出到底是什么 +# 重新导入 输出为 +creating new profile: cobbler-centos8-mini-x86_64 +Exception occured: +Exception value: 'kickstart not found: sample.ks' +Exception Info: + File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 87, in run + rc = self._run(self) + ....... + File "/usr/lib/python2.7/dist-packages/cobbler/item_profile.py", line 212, in set_kickstart + raise CX(_("kickstart not found: %s") % temp) +!!! TASK FAILED !!! +# 看来是sample.ks 未找到 +# find_kickstart() 函数为 +def find_kickstart(url): + """ + Check if a kickstart url looks like an http, ftp, nfs or local path. + If a local path is used, cobbler will copy the kickstart and serve + it over http. + + Return None if the url format does not look valid. + """ + if url is None: + return None + x = url.lstrip() + for y in ["http://", "nfs://", "ftp://", "/"]: + # make sure we get a lower-case protocol without + # affecting the rest of the string + x = re.sub(r"(?i)%s" % y, y, x, count=1) + if x.startswith(y): + if x.startswith("/") and not os.path.isfile(x): + return None + return x + return None +# 明显输入为'sample.ks'时输出为None, 推测是未给url加绝对路径,文件在/var/lib/cobbler/kickstarts/sample.ks +# /usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py: 192 直接读取并没有添加,所以需要我们自己手动添加 +sudo vim /var/lib/cobbler/distro_signatures.json +:%s/sample.ks/\/var\/lib\/cobbler\/kickstarts\/sample.ks/ + + +# 重新导入, 一次成功 +sudo cobbler import --name=centos8-mini --arch=x86_64 --path=/mnt/centos_mini +# 输出 +➜ test sudo cobbler distro list + cobbler-centos8-mini-x86_64 +➜ test sudo cobbler profile list + cobbler-centos8-mini-x86_64 + +➜ test sudo cobbler distro report --name=cobbler-centos8-mini-x86_64 +Name : cobbler-centos8-mini-x86_64 +Architecture : x86_64 +TFTP Boot Files : {} +Breed : redhat +Comment : +Fetchable Files : {} +Initrd : /var/lib/cobbler/www/cobbler/ks_mirror/centos8-mini-x86_64/images/pxeboot/initrd.img +Kernel : /var/lib/cobbler/www/cobbler/ks_mirror/centos8-mini-x86_64/images/pxeboot/vmlinuz +Kernel Options : {} +Kernel Options (Post Install) : {} +Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/cobbler-centos8-mini-x86_64'} +Management Classes : [] +OS Version : rhel8 +Owners : ['admin'] +Red Hat Management Key : <> +Red Hat Management Server : <> +Template Files : {} + +➜ test sudo cobbler profile report --name=cobbler-centos8-mini-x86_64 +Name : cobbler-centos8-mini-x86_64 +TFTP Boot Files : {} +Comment : +DHCP Tag : default +Distribution : cobbler-centos8-mini-x86_64 +Enable gPXE? : 0 +Enable PXE Menu? : 1 +Fetchable Files : {} +Kernel Options : {} +Kernel Options (Post Install) : {} +Kickstart : /var/lib/cobbler/kickstarts/sample.ks +Kickstart Metadata : {} +Management Classes : [] +Management Parameters : <> +Name Servers : [] +Name Servers Search Path : [] +Owners : ['admin'] +Parent Profile : +Internal proxy : +Red Hat Management Key : <> +Red Hat Management Server : <> +Repos : [] +Server Override : <> +Template Files : {} +Virt Auto Boot : 1 +Virt Bridge : virbr0 +Virt CPUs : 1 +Virt Disk Driver Type : raw +Virt File Size(GB) : 5 +Virt Path : +Virt RAM (MB) : 512 +Virt Type : kvm +``` + +![image-20200714013540086](https://public.veypi.com/img/screenshot/20200714013540.png) + +修改centos用的kickstart文件 + +```bash +cd /var/lib/cobbler/kickstarts/ +sudo cp sample.ks centos8.ks +sudo cobbler profile edit --name=cobbler-centos8-mini-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8.ks +# 验证 +sudo cobbler profile report --name=cobbler-centos8-mini-x86_64 | grep kickstart +# 同步 +sudo cobbler sync +``` + + + +## Centos8.ks + +```bash +#platform=x86, AMD64, or Intel EM64T +#os=centos8 + +# Install OS instead of upgrade +install +# Use text mode install +text +# System keyboard +keyboard us +# System language +lang en_US +# System timezone +timezone Asia/ShangHai + + +# System authorization information +auth --useshadow --enablemd5 +#Root password +rootpw --iscrypted $default_password_crypted + + +# Firewall configuration +firewall --disabled +# SELinux configuration +selinux --disabled + + +# Use network installation +url --url=$tree + + +# Clear the Master Boot Record +zerombr +# System bootloader configuration +# bootloader --location=mbr +# interface can be named as eth* +bootloader --location=mbr --append="net.ifnames=0 biosdevname=0 rhgb quiet" + +# Partition clearing information +clearpart --all --initlabel +# Allow anaconda to partition the system as needed +autopart +# or +# # create 1MB biosboot type partition, centos7 and centos8 . +# part biosboot --fstype=biosboot --size=1 +# # Disk partitioning information +# part /boot --fstype=xfs --size=300 +# part pv.122 --fstype="lvmpv" --grow +# volgroup VolGroup00 --pesize=16384 pv.122 +# logvol / --fstype="xfs" --size=10000 --name=LogVol00 --vgname=VolGroup00 + + +# If any cobbler repo definitions were referenced in the kickstart profile, include them here. +$yum_repo_stanza +# Network information +$SNIPPET('network_config') +# Do not configure the X Window System +skipx +# Run the Setup Agent on first boot +firstboot --disable +# Reboot after installation +reboot + +%pre +$SNIPPET('log_ks_pre') +$SNIPPET('kickstart_start') +$SNIPPET('pre_install_network_config') +# Enable installation monitoring +$SNIPPET('pre_anamon') + +%packages +$SNIPPET('func_install_if_enabled') +# if you need puppet to install pkgs, just uncomment it +# $SNIPPET('puppet_install_if_enabled') +@core +@base +tree +nmap +wget +telnet +%end + +%post --nochroot +$SNIPPET('log_ks_post_nochroot') +%end + +%post +$SNIPPET('log_ks_post') +# Start yum configuration +$yum_config_stanza +# End yum configuration +$SNIPPET('post_install_kernel_options') +$SNIPPET('post_install_network_config') +$SNIPPET('func_register_if_enabled') +$SNIPPET('puppet_register_if_enabled') +$SNIPPET('download_config_files') +$SNIPPET('koan_environment') +$SNIPPET('redhat_register') +$SNIPPET('cobbler_register') +# Enable post-install boot notification +$SNIPPET('post_anamon') +# Start final steps +$SNIPPET('kickstart_done') +# End final steps +``` + + + +## 验证 + + + + + +--------------- + +[1]: http://cobbler.github.io +[2]: https://cobbler.readthedocs.io/en/latest/ +[3]: https://bashtheshell.com/guide/setting-up-pxe-boot-server-on-raspberry-pi/ +[4]: http://wiki.inford.net/使用树莓派3构建PXE服务器自动安装操作系统 + + + + + diff --git a/raspberry/main.md b/raspberry/main.md index e9ca4f8..8113b0d 100644 --- a/raspberry/main.md +++ b/raspberry/main.md @@ -1,6 +1,8 @@ # 树莓派安装使用 -## linux下 安装 +## 安装 + +- 命令行 ``` bash df -h # 查看已有硬盘 @@ -8,28 +10,97 @@ df -h # 查看已有硬盘 df -h # 查看新增磁盘 fdisk /dev/sdx # 删除增加分区 -dd bs=4M if=2017-11-29-raspbian-stretch.img of=/dev/sdX # 写入镜像 +dd bs=4M if=2020-05-27-raspios-buster-armhf.img of=/dev/sdX # 写入镜像 sudo watch -n 5 pkill -USR1 ^dd$ # 查看dd进程 ``` +- 客户端 + + Raspberry 有推出一款制作启动器的客户端,比较简洁美观,支持Linux、Mac、Windows. [下载地址][https://www.raspberrypi.org/downloads/] + + 可以在线下载制作,也可以用本地镜像(Use custom) + + ![](https://public.veypi.com/img/screenshot/20200712001917.png) + + ![image-20200712002720911](https://public.veypi.com/img/screenshot/20200712002720.png) + + + +## 开启ssh + +​ sdk写入镜像后插入树莓派,通电3分钟等待系统初始化完成,拔出sdk, 在根目录创建 ssh 文件,无须写入信息 + + ## 换源 ```bash -$ sudo nano /etc/apt/sources.list -#注释掉原文件内容,用以下内容取代: +# 编辑 `/etc/apt/sources.list` 文件,删除原文件所有内容,用以下内容取代: +deb http://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os/raspbian/ buster main non-free contrib rpi +deb-src http://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os/raspbian/ buster main non-free contrib rpi -deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi -deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi +# 编辑 `/etc/apt/sources.list.d/raspi.list` 文件,删除原文件所有内容,用以下内容取代: +deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui +``` -#使用管理员权限(经由sudo),编辑/etc/apt/sources.list.d/raspi.list文件。参考命令行为: -$ sudo nano /etc/apt/sources.list.d/raspi.list -#注释掉原文件内容,用以下内容取代: +## zsh + +```bash +sudo apt install zsh +sudo curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh +chsh -s /bin/zsh +``` + + + +## 代理 + +```bash +# raspberry 很多时候需要在命令行上访问外面的世界,可以临时用自己笔记本的, 没必要去重新搭建配置 +# vpn 是自己笔记本/主机 ip 地址, 端口是自己设置的特殊软件端口 +export http_proxy=http://vpn:1087;export https_proxy=http://vpn:1087; +``` + + + +## 静态ip + +```bash +# /etc/dhcpcd.conf +interface eth0 +static ip_address=192.168.0.2/24 +#static ip6_address=fd51:42f8:caae:d92e::ff/64 +static routers=192.168.0.1 +static domain_name_servers=223.5.5.5 114.114.114.114 +``` + +## 配置wifi + +```bash +# 先设置wlan country, 不设置无法启动无线网卡,所有启动操作都会提示 RTNETLINK answers: Operation not possible due to RF-kill +# 选择 4 4 +sudo raspi-config +# 查找ssid +sudo iwlist wlan0 scan +sudo vim /etc/wpa_supplicant/wpa_supplicant.conf +# 添加配置 +network={ + ssid="testing" + psk="testingPassword" +} +# 重启 +sudo wpa_cli -i wlan0 reconfigure +``` + + + +------------------------ + +[1]: https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md + + -deb http://mirror.tuna.tsinghua.edu.cn/raspberrypi/ stretch main ui -deb-src http://mirror.tuna.tsinghua.edu.cn/raspberrypi/ stretch main ui -``` \ No newline at end of file