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

2016-07-01

Linux Open Files

1. 查看kernal open files 上限

[root@xxx fd]# cat /proc/sys/fs/file-max
2000000

2. 查看有多少個kernal files被開啟
[root@xxx fd]# sysctl fs.file-nr
fs.file-nr = 2144       0       2000000

3. 修改max open files
vi /etc/sysctl.conf 加入 fs.file-max = xx,
執行sysctl -p 讓設定生效

4. ulimit -a 查看每個user的使用上限
可以修改設定檔 /etc/security/limits.conf 來設定
* soft nofile 655360
* hard nofile 655360
ulimit -n
ulimit -n 655360

5. 寫了一個shellscript 每分鐘log下來。

#!/bin/bash
while :
do
# cd /proc/<PID>/fd
 today=$(date +"%m-%d-%Y")
 filename="/tmp/${today}.log"
 tt=$(date +"%T")
# echo "$tt" >> "${filename}"
 #lsof | wc -l >> "${filename}"
 ss=$(lsof | wc -l)
 echo ${tt}" "${ss}  >> "${filename}"
sleep 60

done


2015-06-05

CentOS ssh 無法執行 java

今天發生透過Jenkins要遠端啟動shellscript, 卻無法執行的情況,
但是直接在本機端執行可以的,已有設定環境變數。

原因ssh時不會執行/etc/profile 內的環境變數

shellscript內容是去呼叫一個jar檔:
#!/bin/bash
nohup java -jar /xxx/abc.jar 2>&1

ssh遠端指令:
ssh xx@10.10.10.10 "sh /xxx/abc.sh"

解決方式:
在/etc/profile.d 底下新增一個shellscript, 名稱都可以jdk1.5.sh,
裡面加入:
export JAVA_HOME=/project/server/jdk1.5
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin


其他方式
1. 使用alternatives 
https://www.cnblogs.com/killkill/archive/2010/08/23/1806468.html

2. 使用 #!/bin/bash --login
https://bbs.csdn.net/topics/392163467

3. java 帶完全路徑
--
/etc/profile 與 /etc/profile.d 差異
.Login shell 啟動時才會運行 /etc/profile 這個腳本
/etc/profile對所有使用者生效
./etc/profile.d 存放一些應用程式所需的啟動腳本
.~/.bash_profile只對當前使用者生效
.~/.bashrc:該檔案包含專用於你的bash shell的bash資訊,當登入時以及每次開啟新的shell時,該檔案被讀取.每個使用者都有一個.bashrc檔案,在使用者目錄下


2012-06-27

Google Chrome RestoreOnStartup Registry

朋友的Chrome瀏覽器被公司設定為每次重開後都顯示公司首頁,所以瀏覽的網頁無法存下來,

教學修改機碼方式來異動為"還原上次工作階段

步驟如下:

1. Start the Registry Editor (regedit.exe)

2. 找到機碼的位置:

電腦\HKEY_USERS\xxxx\Software\Policies\Google\Chrome\Recommended

3. 修改為1



4. 相關機碼的說明:
https://getadmx.com/?Category=Chrome&Policy=Google.Policies.Chrome::RestoreOnStartup&Language=zh-tw
https://getadmx.com/?Category=Chrome&Policy=Google.Policies.Chrome::RestoreOnStartup_recommended

5. 查看policy

chrome://policy/