[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>概述
docker部署java开发web项目。nohup显示打印日志出现中文乱码,中文显示为问号???。
<>环境
服务器系统:centos7、docker部署项目
<>具体操作如下
<>1.查看系统支持和默认的字符集,更新yum
locale -a #查看系统支持字符集
echo $LANG #查看默认字符集
yum update
<>2.下载中文包和对应的依赖包
yum install -y kde-l10n-Chinese
yum reinstall -y glibc-common
rpm -qa | grep glibc-common-2.17-222.el7.x86_64
yum groupinstall “fonts” -y
yum install -y system-config-language
<>3.添加UTF-8和GBK和GB2312字符集
localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
localedef -c -f GBK -i zh_CN zh_CN.GBK
localedef -c -f GB2312 -i zh_CN zh_CN.GB2312
locale -a #查看
<>4.修改系统字符集
echo ‘LANG=“zh_CN.UTF-8”’ > /etc/locale.conf #修改系统字符集
source /etc/locale.conf
echo ‘export LC_ALL=“zh_CN.utf8”’ >> /etc/profile
source /etc/profile
<>5.退出容器重启服务器
exit
reboot
<>6.检查容器字符集
echo $LANG
echo $LC_ALL
touch 中文.txt
<>
<>后续一:重启容器使用nohup命令看日志发现还是乱码,再重启项目jar包反而不乱码了,emo了
<>思路:修改自启动系统文件(一般是/etc/rc.d/rc.local)中的java -jar命令(添加-Dfile.encoding=utf-8)
java -Dfile.encoding=utf-8 -jar xxx.jar --spring.profiles.active=pro
>nohup.out &
<>前提条件是java项目Maven打包的时候添加依赖(原因:Java源代码->Java字节码->JVM->操作系统)
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<>后续二:这样上述改后又出现问题了,发现数据库插入中文数据的时候数据库乱码了,emo++
<>经历:经尝试,发现docker run使用 /bin/bash命令初始化的时候会乱码和/usr/sbin/init命令不会,但是容器内很多服务不启动
<>思路:创建容器run的时候,给容器定义编码格式(添加’-e LANG=en_US.UTF-8’)
docker run -dit -p 映射端口:端口 --name=容器名 -e LANG=en_US.UTF-8 镜像名 /bin/bash
<>结束语:
人际的起点:一表人才(长相)两套西装(穿着打扮)
人际的媒介:三杯酒量(入肚的食物)四圈麻将(社交运动)
人际的交往:五方郊游(扩大范围)、六出祁山(深入往来)
人际的技巧:七术打马(有马屁味道但不是拍马屁)、八口吹牛(吹捧自己适可而止)
人际的修养:九分努力(不断的精进)、十分忍耐(努力不一定达到好的结果,所以要十分忍耐,最大的考验是忍辱负重)