mount_point/qcloud_action/os.conf
의 정보를 읽고 구성해야 합니다. 만약 사용자가 다른 구성 데이터인 UserData 를 사용해야 한다면 mount_point/
에서 파일을 직접 읽을 수 있습니다.hostname=VM_10_20_xxxxpassword=GRSgae1fw9frsG.rfrFeth0_ip_addr=10.104.62.201eth0_mac_addr=52:54:00:E1:96:EBeth0_netmask=255.255.192.0eth0_gateway=10.104.0.1dns_nameserver="10.138.224.65 10.182.20.26 10.182.24.12"
파라미터 이름 | 파라미터 의미 |
hostname | 호스트 이름 |
password | 암호화된 비밀번호 |
eth0_ip_addr | eth0 ENI의 랜 IP |
eth0_mac_addr | eth0 ENI의 MAC 주소 |
eth0_netmask | eth0 ENI의 서브넷 마스트 |
eth0_gateway | eth0 ENI의 게이트웨이 |
dns_nameserver | DNS 서버 확인 |
/dev/cdrom
을 마운트 포인트하고 아래 qcloud_action/os.conf
파일을 읽은 후 구성 정보를 가져옵니다.chpasswd -e
방식을 사용하여 설정할 수 있습니다.
암호화된 비밀번호는 특수 문자가 포함될 수 있으므로 먼저 파일에 배치한 후 chpasswd -e < passwd_file
방식으로 설정하는 것을 권장합니다.os_config
스크립트를 생성합니다.
사용자는 실제 상황에 따라 os_config
스크립트를 수정할 수 있습니다.#!/bin/bash### BEGIN INIT INFO# Provides: os-config# Required-Start: $local_fs $network $named $remote_fs# Required-Stop:# Should-Stop:# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: config of os-init job# Description: run the config phase without cloud-init### END INIT INFO###################user settings#####################cdrom_path=`blkid -L config-2`load_os_config() {mount_path=$(mktemp -d /mnt/tmp.XXXX)mount /dev/cdrom $mount_pathif [[ -f $mount_path/qcloud_action/os.conf ]]; then. $mount_path/qcloud_action/os.confif [[ -n $password ]]; thenpasswd_file=$(mktemp /mnt/pass.XXXX)passwd_line=$(grep password $mount_path/qcloud_action/os.conf)echo root:${passwd_line#*=} > $passwd_filefireturn 0elsereturn 1fi}cleanup() {umount /dev/cdromif [[ -f $passwd_file ]]; thenecho $passwd_filerm -f $passwd_filefiif [[ -d $mount_path ]]; thenecho $mount_pathrm -rf $mount_pathfi}config_password() {if [[ -f $passwd_file ]]; thenchpasswd -e < $passwd_filefi}config_hostname(){if [[ -n $hostname ]]; thensed -i "/^HOSTNAME=.*/d" /etc/sysconfig/networkecho "HOSTNAME=$hostname" >> /etc/sysconfig/networkfi}config_dns() {if [[ -n $dns_nameserver ]]; thendns_conf=/etc/resolv.confsed -i '/^nameserver.*/d' $dns_conffor i in $dns_nameserver; doecho "nameserver $i" >> $dns_confdonefi}config_network() {/etc/init.d/network stopcat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0IPADDR=$eth0_ip_addrNETMASK=$eth0_netmaskHWADDR=$eth0_mac_addrONBOOT=yesGATEWAY=$eth0_gatewayBOOTPROTO=staticEOFif [[ -n $hostname ]]; thensed -i "/^${eth0_ip_addr}.*/d" /etc/hostsecho "${eth0_ip_addr} $hostname" >> /etc/hostsfi/etc/init.d/network start}config_gateway() {sed -i "s/^GATEWAY=.*/GATEWAY=$eth0_gateway" /etc/sysconfig/network}###################init#####################start() {if load_os_config ; thenconfig_passwordconfig_hostnameconfig_dnsconfig_networkcleanupexit 0elseecho "mount ${cdrom_path} failed"exit 1fi}RETVAL=0case "$1" instart)startRETVAL=$?;;*)echo "Usage: $0 {start}"RETVAL=3;;esacexit $RETVAL
os_config
스크립트를 /etc/init.d/
디렉터리에 배치하고 다음 명령어를 실행합니다.chmod +x /etc/init.d/os_configchkconfig --add os_config
os_config
가 시작 서비스에 추가되었는지 확인합니다.chkconfig --list
문제 해결에 도움이 되었나요?