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 网卡的局域网 IP |
eth0_mac_addr | eth0 网卡的 MAC 地址 |
eth0_netmask | eth0 网卡的子网掩码 |
eth0_gateway | eth0 网卡的网关 |
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
本页内容是否解决了您的问题?