2019年2月24日 星期日

delete all lines in vi vim

To delete all lines in vim, use this command:

:1,$d
This vim “delete all lines” command can be read like this:

The : character starts vim’s “last line mode.”
The 1 means, “starting at line 1”
The ,$ means, “until the end of the file”
The d means, “delete”

2019年2月20日 星期三

2019年1月29日 星期二

NXLog Installation


nxlog-ce-2.10.2150
  • NXLog Manager
  • NXLog Community Edition: Send data to most popular solutions. Need to ship data to ELK, Graylog, Loggly or some other SIEM? We got you covered!
  • NXLog Enterprise Edition




安裝的是 NXLog Community Edition,安裝好之後我們要去修改設定檔,
設定檔是 C:\Program Files (x86)\nxlog\conf\nxlog.conf,內容如下。

## This is a sample configuration file. See the nxlog reference manual about the
## configuration options. It should be installed locally and is also available
## online at http://nxlog.org/docs/

## Please set the ROOT to the folder your nxlog was installed into,
## otherwise it will not start.

#define ROOT C:\Program Files\nxlog
define ROOT C:\Program Files (x86)\nxlog

Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
LogFile %ROOT%\data\nxlog.log

<Extension _syslog>
    Module      xm_syslog
</Extension>

<Input iislog> 我們先給 Input 標籤一個自定義的名字 iislog,我們要在標籤裡面去設定一組輸入的來源。
    Module      im_file Module:設定 為im_file
    File      "C:\\inetpub\\logs\\LogFiles\\W3SVC1\\u_ex*" File:設定 IIS Log 檔案的儲存位置
    SavePos      TRUE SavePos:設定為 TRUE,用來記住上次的讀檔位置。
</Input>

<Output logstash> 給 Output 檔籤一個自定義的名字 logstash,我們在標籤裡面去設定一組輸出的目的。
    Module      om_tcp Module:設定 為om_tcp
    Host        IP or hostname  Host:設定為 Logstash or GrayLog 伺服器的名稱或位址
    Port        12201 Port:設定為 Logstash 伺服器開啟監聽的埠號
</Output>

<Route 1>
    Path        iislog => logstash
</Route>

<Route>
Route 是告訴 NXLog 哪一個 Input 要對應到哪一個 Output,Input 及 Output 可以用逗號隔開設定多組,例如這樣:

<Route 1>多對多
    Path        iislog1,iislog2,… => logstash1,logstash2,…
</Route>

但是如果我們想指定 iislog1 只輸出給 logstash1、iislog2 則輸出給 logstash1 及 logstash2,這個時候就要設定第二組 Route 去另外指定,像這樣:

<Route 1>一對一
    Path        iislog1 => logstash1
</Route>

<Route 2>一對多
    Path        iislog2 => logstash1,logstash2
</Route>

Configuration file:
C:\Program Files (x86)\nxlog\conf\nxlog.conf

Log file
C:\Program Files (x86)\nxlog\data\nxlog.log

Refer [料理佳餚] ELK 搭檔 NXLog 收集 IIS Log







2018年9月16日 星期日

Windows Battery report Command

powercfg /batteryreport /output "C:\battery_report.html"
開 command line 貼上這行指令,就會輸出到 C:\battery_report.html








2018年7月12日 星期四

dig host nslookup command in Linux

dig:
dig @NameServer 網域名稱 Type

host:
host -t Type 網域名稱 NameServer

nslookup:
nslookup -type=Type 網域名稱 NameServer

其中 Type 的參數有


  1. any
  2. a: 查 IP Address
  3. mx: 查郵件伺服器
  4. ns: 查名稱伺服器
  5. cname: 查別名
  6. ptr: 由 IP Address 反查網域名稱
  7. hinfo: 查伺服器的系統資訊

$ dig @ns1.google.com www.google.com # 指定 NS1 的 dns server
$ dig google.com @8.8.4.4 # 指定 dns server (結果省略, 請自行測試)
$ dig +trace google.com # 追蹤看經過哪些節點 (結果省略, 請自行測試)
$ dig +trace google.com @8.8.8.8 # 指定 dns server + 追蹤路徑經過 (結果省略, 請自行測試)

CentOS 6 without dig command by default

#yum install bind-utils

:::

  Installing : 32:bind-libs-9.8.2-0.68.rc1.el6.x86_64                       1/2
  Installing : 32:bind-utils-9.8.2-0.68.rc1.el6.x86_64                      2/2
  Verifying  : 32:bind-libs-9.8.2-0.68.rc1.el6.x86_64                       1/2
  Verifying  : 32:bind-utils-9.8.2-0.68.rc1.el6.x86_64                      2/2

#host www.pchome.com.tw
www.pchome.com.tw has address 220.130.119.180

# dig www.pchome.com.tw

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6 <<>> www.pchome.com.tw
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10971
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.pchome.com.tw.             IN      A

;; ANSWER SECTION:
www.pchome.com.tw.      68      IN      A       220.130.119.180

;; Query time: 0 msec
;; SERVER: 10.1.107.40#53(10.1.107.40)
;; WHEN: Thu Jul  5 12:37:33 2018
;; MSG SIZE  rcvd: 51

# nslookup www.pchome.com.tw
Server:         10.1.107.40
Address:        10.1.107.40#53

Name:   www.pchome.com.tw
Address: 220.130.119.180




2018年7月4日 星期三

電子書: Puppet 從入門就放棄


Puppet 是一個基於實現 infrastructure as a code 的組態管理工具,與其相同性質的有 Ansible、SaltStack、Chef 等工具,Puppet 的特性是幾乎涵蓋所有的 OS System,並且適合在大量佈署的環境下使用。

為什麼會說 從入門就放棄 !? 我是從一個 System manager 的角度去看 Puppet,遇到蠻大多數的 System manager 都是因為不想要 coding 所以才選擇走 System manager 這個職位。

但是隨著時代改變,軟體吃掉全世界的這個議題已經越來越明顯,自動化已經是一個不可或缺的項目,Puppet 是一個強大的組態設定工具,因為支援許多判斷式所以導致會很像在 coding,但換來的是可以非常彈性的管理你的 Configure。

藉由本書希望可以將 Puppet 的門檻降低,走向美好的自動化世界

Linux DNS 解析問題



用戶端重試
DNS 主要是 UDP 通訊協定。 因為 UDP 通訊協定並不保證訊息傳遞,所以 DNS 通訊協定本身會處理重試邏輯。 每個 DNS 用戶端 (作業系統) 可以展現不同的重試邏輯,根據建立者喜好設定而定:
Windows 作業系統會在 1 秒後重試,然後再依序隔 2、4、4 秒後重試。
預設 Linux 安裝程式會在 5 秒之後重試。 您應該將此變更為以 1 秒的間隔重試 5 次。
檢查 Linux 虛擬機器上目前的設定 'cat /etc/resolv.conf',並查看 'options' 行,例如:


options timeout:1 attempts:5

/etc/sysconfig/network

RES_OPTIONS="rotate timeout:1 attempts:1"

resolv.conf 檔案會自動產生且不可編輯。 新增 [選項] 行的特定步驟會因發行版本而有所不同:


為了達到最佳效能,當您在 Azure DNS 伺服器中使用虛擬機器時,請停用 IPv6,並將執行個體層級公用 IP 指派給每部 DNS 伺服器虛擬機器。


Azure 中 Linux 虛擬機器的 DNS 名稱解析選項

2018年4月26日 星期四

SQL 2014 Server HA failover solution without shared storage installation process

1. Base OS
2. Check MBR disk type D: disk
3. Add .NET Framework 3.5 and Failover features
4. Install SQS 2014, SP2, Balance Data Distributor
5. Enable Cluster Service
6. Check SQL/Cluster service works
7. Enable Always-on and 
8. Create new sql listener by creat Availability Group wizard (Bad)
9. Import and configure replica DB
























No disk in it since we do not have SAN Share Storage












Final

2018年4月17日 星期二

CentOS 7 Installation, SSH Enablement, Proxy Setting


1. OS installation



2. Proxy Setting

在一般公司的環境下Client端都需要設定Proxy才可以對外連線
假設Proxy的IP:192.168.1.10 , port:8080
編輯 .bash_profile (root目錄下) ,新增以下(紅字):

http_proxy=192.168.1.10:8080
ftp_proxy=192.168.1.10:8080
export http_proxy
export ftp_proxy

執行
[root@Server ~]# source .bash_profile

看看是否設定成功
[root@Server ~]# echo $http_proxy
192.168.1.10:8080

  • 針對所有使用者
如果要讓這台主機的所有 http / https 都走 proxy 就設定在 /etc/profile

2.1 For Yum proxy setting
/etc/yum.conf
add line proxy=http://192.160.1.1:8080

$ vim /etc/apt/apt.conf
Acquire::http::Proxy "http://proxy.example.com";

2.2 Docker Hub Proxy setting [Refer]

mkdir /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/http-proxy.conf

[Service]
Environment="HTTP_PROXY=http://10.1.107.222:8080"

systemctl daemon-reload
systemctl show --property Environment docker


設定永久變數
  • 僅在目前使用者
永久變數可以寫在登入後會讀取的 ~/.bash_profile , ~/.bashrc

  • 針對所有使用者
如果要讓這台主機的所有 http / https 都走 proxy 就設定在 /etc/profile

  • 僅 apt or yum 使用時才用 proxy



3. Yum install OpenSSH server
$ sudo yum install openssh openssh-server






4. Edit /etc/ssh/sshd_config

Port 22 -> xxx

PermitRootLogin no

Protocol 2



sudo systemctl restart sshd.service

sudo systemctl enable sshd.service

sudo systemctl status  sshd.service



5. Config Firewall

SELinux disable

Check Firewall already disabled
#getenforce

If Firewall not show disabled, please modify the file.
#vi /etc/sysconfig/selinux
SELINUX=disabled
(Need to reboot)

# firewall-cmd --permanent --add-port=200-300/tcp
success
# firewall-cmd --reload
successls


CentOS7 Firewall refer:
https://www.rootusers.com/how-to-open-a-port-in-centos-7-with-firewalld/
http://blog.xuite.net/tolarku/blog/363801991-CentOS+7+Firewalld+%E9%98%B2%E7%81%AB%E7%89%86%E8%AA%AA%E6%98%8E%E4%BB%8B%E7%B4%B9

6. Add new user

#Add user for DEV or QA

useradd John
passwd John

#chmod 660 /etc/sudoers
Add user into sudoer to get root permission
#vi /etc/sudoers
John ALL=(ALL)  ALL


Docker Command

#1 pull images $docker pull chusiang/takaojs1607 #2 list images $docker images #3.1 run docker $docker run -it ### bash #3.2 run do...