golang使用oracle碰到go/lib/time/zoneinfo.zip: no such file or directory

繼前一篇ubuntu16.04搭建oracle環境用於golang開發文章以後,開發的功能終於於5-29日晚上線發佈。結果版本發佈過程當中出現了問題,所以記錄下來。html

過程是線上環境沒有提早安裝oracle client,致使應用啓動失敗。就先找了一臺虛擬機模擬版本發佈,結果致使出現了以下兩個問題:git

  1. 安裝完oracle client後,啓動報error while loading shared libraries: libaio.so.1

直接使用命令apt install libaio1就解決了。github

  1. 這個問題碰到就比較懵
panic: open /opt/go/lib/time/zoneinfo.zip: no such file or directory

goroutine 1 [running]:
github.com/mattn/go-oci8.init.0()
	/home/chensl004/Workspace/go/src/github.com/mattn/go-oci8/globals.go:185 +0x25c

按理來講,線上環境不該該依賴開發環境$GOROOT下的東西,就用關鍵字「go/lib/time/zoneinfo.zip: no such file or directory」百度了一下,找到這樣一篇文章Golang生產環境中time包的zonefile.zip問題,解決方案是將開發環境下的zoneinfo.zip拷貝到相應的運行環境中。golang

但解決問題過程當中,手癢在線上環境部署並運行了一下,在沒有拷貝zoneinfo.zip和沒有golang環境的狀況下,沒有任何問題。當時就納悶了,爲何線上環境能夠,而模擬環境不行,以爲根本緣由不在於有不有zoneinfo.zip。ubuntu

而後去看了github.com/mattn/go-oci8/globals.go中報錯的代碼位置,主要是加載27個時區,列表以下:swift

// build timeLocations: GMT -12 to 14
	timeLocationNames := []string{"Etc/GMT+12", "Pacific/Pago_Pago", // -12 to -11
		"Pacific/Honolulu", "Pacific/Gambier", "Pacific/Pitcairn", "America/Phoenix", "America/Costa_Rica", // -10 to -6
		"America/Panama", "America/Puerto_Rico", "America/Punta_Arenas", "America/Noronha", "Atlantic/Cape_Verde", // -5 to -1
		"GMT",                                                                         // 0
		"Africa/Lagos", "Africa/Cairo", "Europe/Moscow", "Asia/Dubai", "Asia/Karachi", // 1 to 5
		"Asia/Dhaka", "Asia/Jakarta", "Asia/Shanghai", "Asia/Tokyo", "Australia/Brisbane", // 6 to 10
		"Pacific/Noumea", "Asia/Anadyr", "Pacific/Enderbury", "Pacific/Kiritimati", // 11 to 14
	}

我挨個在模擬環境查看文件,結果還真的就發現America/Punta_Arenas這個文件在/usr/share/zoneinfo下沒有,本機和線上環境都是有的,好奇就去網上搜了一下這個時區有什麼特殊的地方。在網上找到一個github的issue,Missing Timezone America/Punta_Arenas,裏面有這樣一句話「Since last year, Punta Arenas has a different timezone than Chile」,而且附上了一個連接2017a release of tz code and data available,裏面有這樣一段話oracle

Chile's Region of Magallanes moves from -04/-03 to -03 year-round.
     Its clocks diverge from America/Santiago starting 2017-05-13 at
     23:00, hiving off a new zone America/Punta_Arenas.

大概就是tz發表一個申明,新增了America/Punta_Arenas這樣一個時區。查詢了相關信息,在ubuntu裏面時區是由tzdata生成的,就看了一下模擬環境的/etc/lsb_releaseui

# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"

懷疑是模擬環境沒有進行操做系統更新致使時區信息版本太低,沒有America/Punta_Arenas這個時區。所以使用apt install tzdata更新了此軟件版本,以後成功啓動,問題解決。spa

附上golang加載時區的順序,主要是代碼time/zoneinfo.go操作系統

1. 加載環境變量ZONEINFO指定的文件或路徑
2. 查看unix系統的安裝路徑,默認是/usr/share/zoneinfo
3. 查找$GOROOT/lib/time/zoneinfo.zip  # 本次爆出的問題就是這裏,轉換爲編譯時指定的$GOROOT,如:open /opt/go/lib/time/zoneinfo.zip: no such file or directory
相關文章
相關標籤/搜索