本人在生產環境中的一臺機器使用了寫好的jar包
的啓動腳本
發現啓動不了jar包,然後自己使用java命令單獨啓動jar包,出現以下報錯
root@aly-gz-web-1:/etc/init.d# java -Dfile.encoding=UTF-8 -Xmx2048M \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=30113 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar /data/appdata/kjyl_1000020/kjly.jar
Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: aly-gz-web-1: aly-gz-web-1: Name or service not known
該報錯的引起是因爲服務器無法找到當前主機名對應的ip
然後我就去查看本機的/etc/hosts
文件,發現hosts文件中該機器公網IP
和該機器的主機名映射
的有問題,然後將其修改爲正常後,如下:
# 編輯/etc/hosts文件
vim /etc/hosts
# 有問題的
154.188.27.71 aly-gz-web-100
# 修改後(正確的主機名)
154.188.27.71 aly-gz-web-1
最後在執行jar包啓動腳本,成功啓動
root@aly-gz-web-1:/etc/init.d# /etc/init.d/kjyl_1000020 start
{"changed": true, "changes": "kjyl_1000020 start Success"}