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

2018-05-16

AWS 使用Windows建立SSH key 連線 EC2

當建立新的EC2時,最後一步驟Launch後,會詢問是否要建立或選擇現有的key pair來使用。

Step 1. 我們選擇建立新的kay pair, 選好後要立即下載,如果當下沒有下載之後就無法再下載了。
Step 2. 使用Putty Key Generator, 載入剛剛儲存的 *.pem檔,副檔名選擇all files才看的到。



Step3. 看到這個畫面及成功了,提示有說明要"Save private key"

Step 4.  在Putty => connection => SSH => Auth, 加入剛剛儲存的private key  *.ppk檔即可連線成功。

Step 5. EC2 預設使用 ec2-user登入







2018-03-11

Docker 指令筆記

systemctl status/start/stop/restart  docker

指令解說明文件:
https://docs.docker.com/v17.12/edge/engine/reference/commandline/docker/#child-commands


儲存與載入印象檔
docker images
docker save -o xxx.tar repository:tag
docker load --input xxx.tar
docker load < xxx.tar

docker run -t -i  docker.io/ubuntu /bin/bash
-t: 讓Docker 分配一個虛擬終端(pseudo-tty),並綁定到容器的標準輸入上。
-i:讓容器的標準輸入保持打開
-d:背景執行
docker pa -a
docker rmi -f 79d


docker stop 79d
docker start 79d
docker restart 79d
docker inspect -f {{".Architechture"}} 79d

docker exec -it 79d517743a51 /bin/bash

匯入/匯出容器
docker export  xxx > aaa.tar 會遺失資料層的堆疊資訊
cat xxx.tar | docker import - repository


Data Volumes
docker run -d -P --name web -v /webapp repository:tag
docker run -d -P --name web -v /tmp/webapp:/opt/webapp repository:tag
docker run -d -P --name web -v/tmp/webapp:/opt/webapp:ro repository:tag
docker run -d -P --name web -v ~/.bash_history:/root/.bash_history repository:tag

Data Volumes 容器
docker run -it -v /dbdata --name dbdata ubuntu
docker run -it --vloumes-from dbdat --name db1 ubuntu
docker run -it --vloumes-from dbdat --name db2 ubuntu

Data Vloumes 容器備份
docker run --volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata
恢復:
1. 先建立一個帶有資料卷的容器 dbdata2
docker run -v /dbdata --name dbdata2 ubuntu /bin/bash
2. 再建立另一個容器,掛載 dbdata2 的容器,並使用 untar 解壓備份檔案到掛載的容器卷中
docker run --volumes-from dbdata2 -v $(pwd):/backup busybox tar xvf
/backup/backup.tar

2017-06-05

Linux bash history add timestamp

1. vim ~/.bashrc
在最下方加入 HISTTIMEFORMAT='%F %T '
 - %F – expands to full date same, as %Y-%m-%d (year-month-date).
 - %T – expands to time; same as %H:%M:%S (hour:minute:seconds).

2. source ~/.bashrc

2017-04-04

Linux mount disk


Step 1. 查看硬碟資訊,發現有兩顆 /dev/vad 與 /dev/vab

[root@xxxxx tmp]# fdisk -lu

Disk /dev/vda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003a7b4

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   104855551    52426752   83  Linux
Disk /dev/vdb: 536.9 GB, 536870912000 bytes
16 heads, 63 sectors/track, 1040253 cylinders, total 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Step 2. 新增磁區

[root@xxxxx tmp]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x492efa4a.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit

   x   extra functionality (experts only)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4):1
First cylinder (1-1040253, default 1): default 
Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-1040253, default 1040253): default 
Command (m for help): w

Step 3. 設定磁區格式 ext4
[root@xxxxx tmp]# mkfs -t ext4 /dev/vdb
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768000 inodes, 131072000 blocks
6553600 blocks (5.00%) reserved for the super user
.....

Step 4. 建立disk UUID
[root@xxxxx tmp]# tune2fs -U random /dev/vdb
tune2fs 1.41.12 (17-May-2010)

Step 5. 查看UUID
[root@xxxxx tmp]# blkid /dev/vdb

/dev/vdb: UUID="8217a44e-70f1-4f84-850d-c9e8f30ae5bb" TYPE="ext4"

Step 6. 註冊UUID
[root@xxxxx tmp]# vim /etc/fstab
UUID=b7aae0d4-268c-4b60-914a-f3b48e22819c /                       ext4    defaults        1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

UUID=8217a44e-70f1-4f84-850d-c9e8f30ae5bb /project ext4


Step 6. 掛載磁區到你要的目錄
[root@xxxxx tmp]# mount -t ext4 /dev/vdb /project



完成
[root@ICN-Beta-IXBataAll01 salt]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G  1.3G   46G   3% /
tmpfs           3.9G     0  3.9G   0% /dev/shm

/dev/vdb        493G   70M  467G   1% /project