2021-01-03

CentOS 7 journal log

問題: 在查找硬碟空間使用率時,看到/run/log/journal的使用空間4GB,因此來研究

過程:

/run/log/journal 是用來存放執行systemd時的log,

清除時可以清除archice的log, 避免連system.journal也清除,

清除後重啟 systemctl restart systemd-journald.service


清除指令:

.清除超過的時間: journalctl --vacuum-time=30d

.清除超過的空間: journalctl --vacuum-size=3G


設定檔路徑: 

/etc/systemd/journald.conf


其他指令:

journalctl [OPTIONS...] [MATCHES...]


Query the journal.


Flags:

     --system              Show the system journal

     --user                Show the user journal for the current user

  -M --machine=CONTAINER   Operate on local container

  -S --since=DATE          Show entries not older than the specified date

  -U --until=DATE          Show entries not newer than the specified date

  -c --cursor=CURSOR       Show entries starting at the specified cursor

     --after-cursor=CURSOR Show entries after the specified cursor

     --show-cursor         Print the cursor after all the entries

  -b --boot[=ID]           Show current boot or the specified boot

     --list-boots          Show terse information about recorded boots

  -k --dmesg               Show kernel message log from the current boot

  -u --unit=UNIT           Show logs from the specified unit

  -t --identifier=STRING   Show entries with the specified syslog identifier

  -p --priority=RANGE      Show entries with the specified priority

  -e --pager-end           Immediately jump to the end in the pager

  -f --follow              Follow the journal

  -n --lines[=INTEGER]     Number of journal entries to show

     --no-tail             Show all lines, even in follow mode

  -r --reverse             Show the newest entries first

  -o --output=STRING       Change journal output mode (short, short-iso,

                                   short-precise, short-monotonic, verbose,

                                   export, json, json-pretty, json-sse, cat)

     --utc                 Express time in Coordinated Universal Time (UTC)

  -x --catalog             Add message explanations where available

     --no-full             Ellipsize fields

  -a --all                 Show all fields, including long and unprintable

  -q --quiet               Do not show privilege warning

     --no-pager            Do not pipe output into a pager

  -m --merge               Show entries from all available journals

  -D --directory=PATH      Show journal files from directory

     --file=PATH           Show journal file

     --root=ROOT           Operate on catalog files underneath the root ROOT

     --interval=TIME       Time interval for changing the FSS sealing key

     --verify-key=KEY      Specify FSS verification key

     --force               Override of the FSS key pair with --setup-keys


Commands:

  -h --help                Show this help text

     --version             Show package version

  -F --field=FIELD         List all values that a specified field takes

     --new-id128           Generate a new 128-bit ID

     --disk-usage          Show total disk usage of all journal files

     --vacuum-size=BYTES   Reduce disk usage below specified size

     --vacuum-time=TIME    Remove journal files older than specified date

     --flush               Flush all journal data from /run into /var

     --header              Show journal header information

     --list-catalog        Show all message IDs in the catalog

     --dump-catalog        Show entries in the message catalog

     --update-catalog      Update the message catalog database

     --setup-keys          Generate a new FSS key pair

     --verify              Verify journal file consistency



2020-11-10

Rancher 無法移動 Namespace 問題

問題:

user不知道做甚麼操作,在project內的namespace被移出了,在他的權限範圍內看不到,所以也無法搬回去。


過程:

登入Rancher後,發現該namespace N1被放置在All, 嘗試move namespace後,出現以下的error

"can't move namespace. Project P1 has resource quota set"

查詢官網文件

https://rancher.com/docs/rancher/v2.x/en/project-admin/namespaces/#moving-namespaces-to-another-project

Note: 說明

.You cannot move a namespace into a project that already has a resource quota configured.

意思是說你不能移動一個namespace, 到已經有設定namespace resource quotes的project下。


解法:

1. 先把該project的namespace resource quotes都不設,清空。

2. 移動該namespace, 就可以搬移了。

3. 再把namespace resource quotes設定回去。



2020-11-02

CentOS 憑證路徑

 安裝ca-certificates package:
yum install ca-certificates

啟用動態設定:
update-ca-trust force-enable

加入新的憑證:
cp abc.crt /etc/pki/ca-trust/source/anchors/

設定憑證生效:
update-ca-trust extract

參考:
https://manuals.gfi.com/en/kerio/connect/content/server-configuration/ssl-certificates/adding-trusted-root-certificates-to-the-server-1605.html

CURL 基本指令

 .查看詳細資訊

curl http://abc.com --verbose

* About to connect() to abc.com port 8080 (#0)
*   Trying 10.0.0.1...
* Connected to abc.com (10.0.0.1) port 8080 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt  <== 吃憑證的路徑
  CApath: none

.帶入憑證

curl --cacert RootCA.crt --cert ClientCA.pem:passwd http://abc.com


.不驗證憑證

curl -k

curl --insecure


.取得網站憑證資訊

echo QUIT | openssl s_client -connect abc.com:8080 -servername abc.com -showcerts


openssl s_client -connect abc.com:8080 -servername abc.com -showcerts </dev/null 2>/dev/null | sed -n '/^-----BEGIN CERT/,/^-----END CERT/p'


openssl s_client -connect abc.com:8080 -servername abc.com -showcerts </dev/null 2>/dev/null | awk '/^-----BEGIN CERT/,/^-----END CERT/'


openssl s_client -connect abc.com:8080 -servername abc.com -showcerts </dev/null 2>/dev/null | sed -n '/^-----BEGIN CERT/,/^-----END CERT/p' > example.crt


.變成設定檔方式

abc.conf
cacert = "RootCA.crt"
cert = "ClientCA.pem:mypasswd"
url = "https://mail.ichiayi.com/t.txt"

curl --conf testcurl.conf




參考:

https://blog.miniasp.com/post/2020/08/23/curl-and-self-signed-certificated-or-CA-certificate

https://www.ichiayi.com/wiki/tech/curl_ssl

2020-10-14

Kubernetes Pod cannot allocate memory

問題:

在檢查pod event時,出現以下的error log:

unable to ensure pod container exists: failed to create container for [kubepods burstable pod52610281-d2fe-438b-bc34-ec6c18621a99] : mkdir /sys/fs/cgroup/memory/kubepods/burstable/pod52610281-d2fe-438b-bc34-ec6c18621a99: cannot allocate memory


處理過程:

第一時間看到錯誤集中出現在某一台node上,先cordon有問題的node, 不要再讓pod被排程進來,pod schedule到其他node上是好的,所以針對該node查找問題。


檢查:

$ cat /sys/fs/cgroup/memory/kubepods/memory.kmem.slabinfo
Input/output error  # 無memory leak

$ cat /sys/fs/cgroup/memory/kubepods/memory.kmem.slabinfo
slabinfo - version: 2.1
# name            <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail>
# 有memory leak


解決方法:

1. 這個問題是cgroup bug(memory leak)最快的方式就是,Drain後重啟該node,不過一陣子後還是會發生。

2. 更新kernel到5.14.7-1.el7.elrepo.x86_64 後解決。


其他方式可參考: https://zhuanlan.zhihu.com/p/343031257


2020-09-17

Redis Note

.查看Redis 資訊

$ redis-cli info
[...]
# Replication
role:slave
master_host:192.168.50.11
master_port:6379
master_link_status:down


.修改Redis master/slave mode

$ redis-cli
redis 127.0.0.1:6379> slaveof no one

redis 127.0.0.1:6379> info

[...]

# Replication

role:master

connected_slaves:0


https://www.claudiokuenzler.com/blog/470/how-to-do-redis-master-slave-cluster-switch-failover

2020-09-16

AWS Note

 EC2:

.Change hostname

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-hostname.html


.Install docker

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html

2019-11-04

Linux 修改時區, JVM 異常

.java process 認的時區設定位置在/etc/localtime,不是/bin/date
.因為改完時區後,檢查的方式是下 date -R,這個方式是看/bin/date的時間,所以看是正常的,
但java process是認/etc/localtime, 而這個檔案上次修改被設定softlink指到/usr/share/zoneinfo/Europe/Moscow, 所以在怎麼重啟java 還是沒有效,將softlink移除,重啟java後恢復正常。

2019-10-21

阿里雲不同帳號-同地區-內網互通設定

集團為了拆帳,不同分公司分了不同帳號,有需求要互通,設定如下:
A: aaa@aaa.com  香港
B: bbb@bbb.com 香港

方法一: 透過console設定
A帳號的部分設定如下:
1. 授權對象填入B帳號的SG或是IP.
2. 帳號ID填入B帳號的ID(非登入帳號),在帳號管理裡會有帳號ID。

B帳號則填入A帳號的資訊。














方法二:使用API的方式
帳號帳號ID安全性群組安全性群組ID
帳號Aa@aliyun.comsg1sg-bp1azkttqpldxgtedXXX
帳號Bb@aliyun.comsg2sg-bp15ed6xe1yxeycg7XXX

1. 在sg1安全性群組中添加允許存取sg2安全性群組入方向的規則。
aliyun ecs AuthorizeSecurityGroup --SecurityGroupId sg-bp1azkttqpldxgtedXXX --RegionId cn-qingdao --IpProtocol all  --PortRange=-1/-1. --SourceGroupId sg-bp15ed6xe1yxeycg7XXX --SourceGroupOwnerAccount b@aliyun.com --NicType intranet

2. 在sg2安全性群組中添加允許存取sg1安全性群組入方向的規則。
aliyun ecs AuthorizeSecurityGroup --SecurityGroupId sg-bp15ed6xe1yxeycg7XXX --RegionId cn-qingdao --IpProtocol all  --PortRange=-1/-1. --SourceGroupId sg-bp1azkttqpldxgtedXXX --SourceGroupOwnerAccount a@aliyun.com --NicType intranet

註: 主要關注的參數為SecurityGroupIdSourceGroupIdSourceGroupOwnerAccount


參考資訊:
https://www.alibabacloud.com/help/tc/doc-detail/40597.htm#section-bpp-qvf-ip5
https://www.alibabacloud.com/help/tc/doc-detail/25385.htm
https://help.aliyun.com/knowledge_detail/38163.html

寶塔 Linux 面板安裝

官網: http://bt.cn

Installation

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

Restart

bt restart


安裝完成後,會有登入資訊:





2019-09-30

CentOS 7 Docker 無法連線 Docker daemon?


訊息內容:
[root@localhost ~]# docker search mysql
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

解決方式:
重啟docker service
[root@localhost ~]# systemctl restart docker

參考資料:
https://blog.yowko.com/cannot-connect-docker-daemon/

2018-10-22

Saltstack ERROR Unable to manage file: 'utf8' codec can't decode

在saltstack執行修改時區的腳本時發生了以下的錯誤訊息:

----------
          ID: push_timezone
    Function: file.managed
        Name: /etc/localtime
      Result: False
     Comment: Unable to manage file: 'utf8' codec can't decode byte 0x9b in position 44: invalid start byte
     Started: 10:22:43.427622
    Duration: 165.908 ms
     Changes:

Summary for Public_release_es-xxx
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time: 165.908 ms


解決方式: 在原本腳本裡加入shwo_changes
push_timezone:
  file.managed:
    - name: /etc/localtime
    - source: salt://init/files/localtime
    - show_changes: False
    - user: root
    - group: root
    - mode: 644


參考資料:
https://github.com/saltstack/salt/issues/47042


2018-10-17

Check Redis Health

[root@XXX src]# ./redis-cli
127.0.0.1:6379> info server
# Server
redis_version:3.2.9
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:b67c3abd80fae6f4
redis_mode:standalone
os:Linux 2.6.32-696.10.1.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.7
process_id:932
run_id:f68cda36eec10544798104368d9615935a7ed79c
tcp_port:6379
uptime_in_seconds:2245027
uptime_in_days:25
hz:10
lru_clock:10997976
executable:/usr/local/bin/redis-server
config_file:/etc/redis/6379.conf
127.0.0.1:6379>


redis-cli infoComplete info about the redis-instance
redis-cli info serverServer Information, cersions, configs, binary
redis-cli info clientsConnected clients
redis-cli info memoryStatistics about memory usage and limits
redis-cli info persistenceInfo about RDB and AOF
redis-cli info statsConnection, network, keyspace statistics
redis-cli info replicationReplication settings and status
redis-cli info cpuCPU utilization
redis-cli info clusterCluster settings and status
redis-cli info keyspaceDisplay dbs and number of keys