2016-09-09 34 views
0

我正在嘗試創建一個EC2實例來託管Perforce服務器。我的實例被配置爲以下的用戶數據:AWS EC2用戶數據不能正確解碼

#!/bin/bash 

# Add a newline to the ec2-user prompt string 
echo PS1=\"\\n\$PS1\" >> /home/ec2-user/.bashrc 

# Update all packages 
yum update –y 

# Install Perforce packages 
# The RHEL/7 part of the baseurl should be replaced with 
# the latest RHEL version that both Amazon and Perforce support 
rpm –import https://package.perforce.com/perforce.pubkey 
cd /etc/yum.repos.d/ 
echo [perforce] > perforce.repo 
echo name=Perforce >> perforce.repo 
echo baseurl=http://package.perforce.com/yum/rhel/7/x86_64 >> perforce.repo 
echo enabled=1 >> perforce.repo 
echo gpgcheck=1 >> perforce.repo 
yum install –y helix-p4d 

# Make directories for the server, owned by new 「perforce」 user 
cd /opt/perforce/servers/ 
mkdir danware 
cd danware 
mkdir danware-db danware-chkpts journal 
chown –R perforce:perforce danware 

我已經測試上述各命令,並知道,當以該順序手動執行他們的工作。然而,亞馬遜的base64編碼/解碼系統的某些方面似乎正在阻礙。在啓動(並通過所有系統檢查)後,從EC2控制檯轉到「操作>實例設置>查看/更改用戶數據」時,會看到以下用戶數據。請注意幾乎每個連字符「 - 」已被替換爲一些奇怪的「a」字符。

enter image description here

但是,我不知道這是問題,因爲在/var/log/cloud-init-output.log日誌文件給我下面的輸出(我更換了一些重複的文字以節省空間)。注意Failed running /var/lib/cloud/instance/scripts/part-001這行說明我已經驗證了001這部分文件實際上是確實有正確顯示的連字符。

[...] 
Cloud-init v. 0.7.6 running 'modules:final' at Fri, 09 Sep 2016 06:23:39 +0000. Up 86.66 seconds. 
Loaded plugins: priorities, update-motd, upgrade-helper 
No Match for argument: –y 
No packages marked for update 
RPM version 4.11.2 
Copyright (C) 1998-2002 - Red Hat, Inc. 
This program may be freely redistributed under the terms of the GNU GPL 

Usage: rpm [-aKfgpqVcdLilsiv?] [-a|--all] [-f|--file] [-g|--group] [...] 
Loaded plugins: priorities, update-motd, upgrade-helper 
Resolving Dependencies 
--> Running transaction check 
---> [...] 

Dependencies Resolved 

================================================================================ 
Package     Arch  Version    Repository  Size 
================================================================================ 
Installing: 
helix-p4d    x86_64  2016.1-1429894  perforce  24 k 
Installing for dependencies: 
helix-cli    x86_64  2016.1-1429894  perforce  8.8 k 
helix-cli-base   x86_64  2016.1-1429894  perforce  1.4 M 
helix-p4d-base   x86_64  2016.1-1429894  perforce  3.1 k 
helix-p4d-base-16.1  x86_64  2016.1-1429894  perforce  2.4 M 
helix-p4dctl    x86_64  2016.1-1429894  perforce  1.2 M 

Transaction Summary 
================================================================================ 
Install 1 Package (+5 Dependent packages) 

Total download size: 5.0 M 
Installed size: 13 M 
Is this ok [y/d/N]: Exiting on user command 
Your transaction was saved, rerun it with: 
yum load-transaction /tmp/yum_save_tx.2016-09-09.06-23.dRP_r2.yumtx 
/var/lib/cloud/instance/scripts/part-001: line 22: cd: /opt/perforce/servers/: No such file or directory 
chown: invalid user: ‘–R’ 
Sep 09 06:23:41 cloud-init[2517]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1] 
Sep 09 06:23:41 cloud-init[2517]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts) 
Sep 09 06:23:41 cloud-init[2517]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/dist-packages/cloudinit/config/cc_scripts_user.pyc'>) failed 
Cloud-init v. 0.7.6 finished at Fri, 09 Sep 2016 06:23:41 +0000. Datasource DataSourceEc2. Up 88.53 seconds 

更討厭,我認爲從日誌文件中的早期No Match for argument: –y線指的是從我的用戶數據yum update -y線。果然,僅僅從EC2 documentation頁面運行示例用戶數據腳本(其也使用yum update -y),給了我同樣的錯誤/警告!亞馬遜自己的示例腳本不起作用!?那麼任何人都可以回答爲什麼A)AWS沒有正確顯示用戶數據代碼,以及B)爲什麼我的用戶數據會產生上面顯示的錯誤?非常感謝幫助!

+0

這可能是字符編碼的問題。嘗試從aws-cli – hjpotter92

+0

@ hjpotter92設置用戶數據,如果/ var/lib/cloud/instance/scripts/part-001文件與我通過AWS控制檯輸入的用戶數據完全匹配,這會真的成爲字符編碼問題嗎? ? – Rabadash8820

回答

2

對於系如

yum update –y 

的字符使用的是一個 「EN DASH U + 2013」​​

爲連字符通常的字符爲 「連字符號U + 002D」

解決您的用戶數據源使用「字號減」,並有另一個去

我檢查通過切ñ粘貼的字符代碼到這個在線網站http://www.fileformat.info/info/unicode/char/search.htm?q=-&preview=entity

不知道你是否能看到區別,但是這是你的連字符

yum update –y 

,這是一個「字號減」

yum update -y 
+0

哇,這樣做,卓越的工作@Vorsprung!現在我確實看到了這些連字符之間的區別,但是你怎麼知道哪一個是對的,哪個是錯的?回想起來,我認爲我的問題的真正根源在於,我開始在Microsoft Word(作爲更大文檔的一部分)中寫下用戶數據腳本,然後才最終複製到Notepad ++中,以免擔心某些編碼問題正在發生。顯然,只是複製粘貼並沒有糾正字符代碼。顯然,Word在單詞的結尾處使用連字符作爲連字符,但在連字符中使用連字符 - 連字符! – Rabadash8820