半自動化系統安裝

半自動化之系統安裝

自制應答文件

1. 使⽤kickstart半⾃動化安裝CentOS系統

  • 理解kickstart文件的做用和編寫格式。
    KickStart是一種半自動化的安裝方式。KickStart的工做原理是經過記錄典型的安裝過程當中所需人工干預填寫的
    各類參數,並生成一個名爲ks.cfg的文件;在其後的安裝過程當中(不僅侷限於生成KickStart安裝文件的機器)當
    出現要求填寫參數的狀況時,安裝程序會首先去查找KickStart生成的文件,當找到合適的參數時,就採用找到的
    參數,當沒有找到合適的參數時,才須要安裝者手工干預。這樣,若是KickStart文件涵蓋了安裝過程當中出現的所
    有須要填寫的參數時,安裝者徹底能夠只告訴安裝程序從何處取ks.cfg文件,而後去忙本身的事情。等安裝完畢,
    安裝程序會根據ks.cfg中設置的重啓選項來重啓系統,並結束安裝。

2. KickStart⽂件格式與anaconda-ks.cfg⽂件格式⼗分相似,整體由三部分組成:

1. 命令段:

指明各類安裝前配置,如鍵盤類型等linux

  • 必備命令:
    authconfig:認證方式配置
    authconfig --useshadow --passalgo=sha512
    bootloader:bootloader的安裝位置及相關配置
    bootloader --location=mbr --driveorder=sda –
    append="crashkernel=auto rhgb quiet"
    keyboard:設定鍵盤類型
    ang:語言類型
    part:建立分區
    rootpw:指明root的密碼
    timezone:時區vim

  • 可選命令
    install OR upgrade
    text:文本安裝界面
    network
    firewall
    selinux
    halt
    poweroff
    reboot
    repo
    user:安裝完成後爲系統建立新用戶
    url: 指明安裝源
    key –skip 跳過安裝號碼,適用於rhel版本centos

2. 程序包段:

指明要安裝的程序包組或程序包,不安裝的程序包等
%packages
@group_name
檢查ks⽂件語法錯誤:
ksvalidator /path/to/ks.cfg服務器

3. 腳本段:

%pre:安裝前腳本
運行環境:運行於安裝介質上的微型Linux環境
%post:安裝後腳本
運行環境:安裝完成的系統
安裝後腳本很是有用,咱們能夠在這裏定義系統安裝完成後自動安裝yum源,建立一些普通用戶等功能。
生成ks應答文件方法:
1.參照anaconda-ks.cfg文件修改(不經常使用)
2.利用system-config-kickstart圖形工具製做(經常使用)網絡

檢查ks⽂件語法錯誤:
ksvalidator /path/to/ks.cfgapp


前提準備

系統安裝程序anaconda以及光盤中isolinux目錄的功能:
anaconda:系統安裝程序
anaconda安裝系統可分爲三個階段:
安裝前配置階段:
安裝過程使用的語言;
鍵盤類型;
安裝目標存儲設備;
Basic Storage:本地磁盤;
特殊設備:iSCSI;
設定主機名;
配置網絡接口;
時區;
管理員密碼;
設定分區方式及MBR的安裝位置;
建立一個普通用戶;
選定要安裝的程序包;

系統在完成安裝後,會在⽤戶家⽬錄⾃動⽣成⼀個anaconda-ks.cfg配置⽂件,記錄了安裝系統時選擇的各類參數,安裝
包等內容。dom

系統光盤中isolinux目錄列表文件說明:
boot.cat:相似於系統啓動時MBR的做用
grub.conf:grub.conf文件鏡像
initrd.img:是ramfs虛擬文件系統(先cpio,再gzip壓縮)
isolinux.bin:至關於grub的第二階段
isolinux.cfg:isolinux.bin的配置文件,當光盤啓動,會自動去找isolinux.cfg文件
memtest:內存檢測,這是一個獨立程序
splash.jpg:光盤啓動界面的背景圖
vesamenu.c32:菜單風格,菜單圖標
vmlinuz:內核鏡像。
可用的centos6系統。

一、系統默認未安裝system-config-kickstart,先進⾏yum安裝ssh

[root@centos7 ~]#yum install system-config-kickstart.noarch

二、運⾏kickstart(會生成一個圖形化工具)ide

[root@centos7 ~]#system-config-kickstart

在這裏插入圖片描述
設置這個以前你要作一個http的yum倉庫。
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

在這裏插入圖片描述 寫安裝後後文件使新的操做系統擁有必定功能

[06:19:58 root@centos html]#ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:uaSUcve3zpBKOHXaa5XQb+G1+nkaShHt7Q//qiqHgiI root@centos.yang.com
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|             .   |
|           .. .  |
|       . .. .o...|
|    . + S ...+.oo|
|     + * * .o.+o |
|     .+ +.=.o.+ .|
|E . . .oo.o* + ++|
| . .   ..+oo*.+=*|
+----[SHA256]-----+
(生成ssh的公鑰私鑰對)
[06:32:04 root@centos html]#
[06:32:04 root@centos html]#ssh-copy-id 127.0.0.1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:5mW0aEb7Z8qFTeDBRng6t5CFhjujGSdYa5vp1S6rq80.
ECDSA key fingerprint is MD5:28:3a:27:1a:ab:1c:a0:c5:5c:a6:f2:50:23:f4:77:3f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@127.0.0.1's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '127.0.0.1'"
and check to make sure that only the key(s) you wanted were added.
(把文件拷貝到本地)
[06:49:34 root@centos ~]#cd .ssh
[06:49:51 root@centos .ssh]#ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[06:49:55 root@centos .ssh]#ll(查看authorized_keys權限)
total 16
-rw------- 1 root root  402 Nov 12 06:48 authorized_keys
-rw------- 1 root root 1679 Nov 12 06:32 id_rsa
-rw-r--r-- 1 root root  402 Nov 12 06:32 id_rsa.pub
-rw-r--r-- 1 root root 2053 Nov 12 06:48 known_hosts
[06:50:10 root@centos .ssh]#cd ..
[06:50:20 root@centos ~]#ll -d .ssh (查看.ssh目錄權限)
drwx------. 2 root root 80 Nov 12 06:48 .ssh
(腳本里的權限要和這裏的同樣。)
[06:50:31 root@centos ~]#cat .ssh/authorized_keys (查看公鑰複製與腳本里做爲key驗證使用。)
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTQNHJOrFP0eljtDEpsU4SH0lzrZ/uK9IJgwiVo0Cem0g57xtf8k52WxlOXJO6OhV4C2oEWh0i2wUZtKIOStrDgPO17xWIt2ogEgPVj2OGS5MBdDi0IpVEg++P/HhG+69hHPK7VngYW3pHCnOfO4cuQ3oxIemg2Yk8AsVlrKLkfmhJIy9Cluc8yxO9aACsZ+SqejNR+uWZsGHIs/teJdeQF9QwgHr/1DwvbupoAN0Y7ZqVFzdSATGOb0QO1L+4Vj6tjd0pRnOAyoTc6oQl+3XWTrfdTWvSJJRtNWbAd0xSnE5mOgIL9lhr3SdnnJtBbHjY0A57uqV3kZ7WZShToOyh root@centos.yang.com

在這裏插入圖片描述
在這裏插入圖片描述
到這裏基本上應答文件就已經制做完成了,不滿意的話能夠在進行修改。

[root@centos7 ~]#vim ks7_mini2.cfg

以後把製做好的應答文件放到以前的http服務器上

[06:51:04 root@centos ~]#cd /var/www/html/
[07:46:42 root@centos html]#
[07:46:44 root@centos html]#ls
centos
[07:46:45 root@centos html]#mkdir ksdir
[07:46:55 root@centos html]#ls
centos  ksdir
[07:46:57 root@centos html]#pwd
/var/www/html
[07:47:12 root@centos html]#cd ksdir/
[07:47:22 root@centos ksdir]#pwd
/var/www/html/ksdir
[root@centos7 ~]#vim ks7_mini2.cfg 
[root@centos7 ~]#scp ks7_mini2.cfg 192.168.39.121:/var/www/html/ksdir

在這裏插入圖片描述
以後再從新使用vmr製做一個虛擬機
在這裏插入圖片描述
在這個界面按Esc鍵進入anaconda界面
在這裏插入圖片描述
以後輸入http的路徑
在這裏插入圖片描述
回車系統就會自動安裝了,不用在手動管理了。
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
這裏看一下key驗證有沒有實現。

[09:14:08 root@centos ~]#scp 1.txt 192.168.39.135:/root/
The authenticity of host '192.168.39.135 (192.168.39.135)' can't be established.
ECDSA key fingerprint is SHA256:XIqej+HofAyUdoNtkcyK9myMo5LaGYjBx4qkWNUjnuI.
ECDSA key fingerprint is MD5:6e:cf:b7:a5:99:ce:a6:05:ae:cb:41:d7:a5:17:2e:15.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.39.135' (ECDSA) to the list of known hosts.
1.txt                                  100%    0     0.0KB/s   00:00    
[09:14:32 root@centos ~]#scp xiangqi2_while.sh 192.168.39.135:/root/
xiangqi2_while.sh                                                                                                          100%  819   419.8KB/s   00:00    
(第一次輸了yes第二次什麼也沒輸key驗證登陸成功)
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:7d:42:24 brd ff:ff:ff:ff:ff:ff
    inet 192.168.39.135/24 brd 192.168.39.255 scope global noprefixroute dynamic eth0
       valid_lft 1653sec preferred_lft 1653sec
    inet6 fe80::c95d:730e:fbfe:7644/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@localhost ~]# ls
1.txt  anaconda-ks.cfg  original-ks.cfg  xiangqi2_while.sh

(到這這個半自動化的系統安裝已經完成,注意幾點這個實驗我事先配好了http的yum倉庫)

相關文章
相關標籤/搜索