2016年12月27日 星期二

電腦 windows mklink 用法 (symbolic link)

windows mklink 用法
Linux上, symbolic link可以將檔案或資料夾產生一個或多各連結,
在 Windows 的 mklink ,也有相同功能。
用administrator 開啟命令提示字元,輸入mklink /?






1.建立
建立d:\temp連結目錄,指向e:\temp
mklink /d d:\temp e:\temp
建立d:\temp連結目錄,指向網路磁碟
mklink /d d:\temp \\138.20.1.141\e$\temp
2.刪除
rmdir d:\temp
rd d:\temp

2016年12月20日 星期二

電腦 Vmware-Esxi 5.5 snmp設定

Vmware-Esxi 5.5 snmp設定

檔案存在於/etc/vmware/snmp.xml

可於本機指令esxcli system snmp進行修改snmp.xml

esxcli system snmp set -r
esxcli system snmp set -c public
esxcli system snmp set -t 10.15.0.1@161/public
esxcli system snmp set -p 161
esxcli system snmp set -l warning
esxcli system snmp set -e yes

esxcli system snmp get 確認snmp.xml內容。

/etc/init.d/snmpd restart


esxcli system snmp set --enable true ( esxi 6.0 )

測試
snmpwalk -v 2c -c public 10.15.0.1

=============================================
ESXI 5.5
esxcli system snmp set -t 10.15.0.1@161/public,10.15.0.2@161/public

電腦 windows 網域環境中出現工作站與網域控制器信任失敗問題

windows 網域環境中出現工作站與網域控制器信任失敗問題

工作站使用網域帳號登入時,出現 " the trust relationship between this workstation and the primary domain failed "或 " 此工作站和主要網域間的信任關係失敗 " 的問題。

1.使用本機管理者帳號登入,退出網域及重新加入網域。

2.使用windows內建 powershell的 Reset-ComputerMachinePassword 指令
   a.下載powershell 4.0 ,安裝
       https://www.microsoft.com/en-us/download/details.aspx?id=40855
   b.執行 Reset-ComputerMachinePassword -Server <Name of any domain controller> -Credential <domain admin account>
       <Name of any domain controller> 為網域控制器主機名稱,如:dc.domian.com
       <domain admin account> 為網域管理者帳號,如: domain\administrator


參考資料

此工作站和主域间的信任关系失败

 

How To Fix Domain Trust Issues in Active Directory

 

DON’T REJOIN TO FIX: The trust relationship between this workstation and the primary domain failed

2016年11月22日 星期二

電腦 windows使用winscp的指令功能

在windows的cmd模式,使用ftp指令無法下載。
決定使用winscp來取代。

建立參數檔:script.txt
option batch abort
option confirm off
option transfer binary
open ftp://LoginID:LogPwd@FTP_Host
put d:\examplefile.txt
close
exit

建立執行檔:ftp.bat
winscp.com /script=\script.txt /ini=nul /log=\session.log

將ftp.bat、script.txt放在winscp資料夾
執行ftp.bat即可。也可寫入排程固定執行。



使用sftp
sftp://LoginID:LogPwd@FTP_Host -hostkey="ssh-rsa 1024  XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:X:XX:XX:XX:XX"

使用scp
winscp.exe scp://test@example.com:2222 /privatekey=mykey.ppk

使用ftps
winscp.exe ftps://martin@example.com /implicit /certificate="xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"

參考資料:
SFTP使用WinSCP
Useful Scripts
Scripting and Task Automation
Example
In the example below, WinSCP connects to example.com server with account user, downloads file and closes the session. Then it connects to the same server with the account user2 and uploads the file back.
# Connect
open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
# Change remote directory
cd /home/user
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
get examplefile.txt d:\
# Disconnect
close
# Connect as a different user
open sftp://user2:password@example.com/
# Change the remote directory
cd /home/user2
# Upload the file to current working directory
put d:\examplefile.txt
# Disconnect
close
# Exit WinSCP
exit
Save the script to the file example.txt. To execute the script file use the following command.
winscp.com /ini=nul /script=example.txt
==
For simple scripts you can specify all the commands on command-line using /command switch:
winscp.com /ini=nul /command "open sftp://user:password@example.com/ -hostkey=""ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx""" "get examplefile.txt d:\" "exit"
==
In Windows batch file, you can use ^ to split too long command-line to separate lines by escaping following new-line character:
winscp.com /ini=nul /command ^
    "open sftp://user:password@example.com/ -hostkey=""ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx""" ^
    "get examplefile.txt d:\" ^
    "exit"
See other useful example scripts.

2016年11月18日 星期五

電腦 nginx增加ssl功能

增加ssl
nginx.conf
server {
    listen              443 ssl;
    server_name           www.example.com;
    ssl_certificate          www.example.com.crt;
    ssl_certificate_key  www.example.com.key;
    ssl_protocols          TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers             HIGH:!aNULL:!MD5;
    ...
}
測試ssl
openssl s_client -connect www.example.com:443
==
HTTPS server optimization

worker_processes auto;
nginx.conf
http {
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;

    server {
        listen              443 ssl;
        server_name         www.example.com;
        keepalive_timeout   70;

        ssl_certificate         www.example.com.crt;
        ssl_certificate_key  www.example.com.key;
        ssl_protocols         TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers             HIGH:!aNULL:!MD5;
        ...

==
Name-based HTTPS servers
server {
    listen          443 ssl;
    server_name     www.example.com;
    ssl_certificate www.example.com.crt;
    ...
}

server {
    listen          443 ssl;
    server_name     www.example.org;
    ssl_certificate www.example.org.crt;
    ...
}

or
server {
    listen          192.168.1.1:443 ssl;
    server_name     www.example.com;
    ssl_certificate www.example.com.crt;
    ...
}

server {
    listen          192.168.1.2:443 ssl;
    server_name     www.example.org;
    ssl_certificate www.example.org.crt;
    ...
}
==
An SSL certificate with several names

ssl_certificate     common.crt;
ssl_certificate_key common.key;

server {
    listen          443 ssl;
    server_name     www.example.com;
    ...
}

server {
    listen          443 ssl;
    server_name     www.example.org;
    ...
}

Configuring HTTPS servers

電腦 Linux-將IIS的SSL憑證移至Centos使用


將IIS 匯出的 PKCS12 憑證檔 (mycert.pfx) 轉換
openssl pkcs12 -in mycert.pfx -out mycert.txt -nodes
輸入憑證密碼,建立 mycert.txt 檔案

mycert.txt 檔案,裡面同時包含兩個憑證,分別是 伺服器私鑰(RSA PRIVATE KEY) 與 伺服器憑證(CERTIFICATE)

將mycert.txt中包含
-----BEGIN RSA PRIVATE KEY-----

-----END RSA PRIVATE KEY-----
複製到server.key

將mycert.txt中包含
-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----
複製到server.crt

就可以將server.key、server.crt導入到網站(apache、nginx)使用


將 IIS 中已安裝的 SSL 憑證移至 Apache 2.2 for Win32 安裝

2016年11月17日 星期四

電腦 CentOS yum server 建置-對外更新

Yum Server 建置-對外更新


CentOS 7 以最小安裝設定完成,如果無網路對外安裝套件,建罝yum server安裝套件。

新增硬碟(40G)為/data,放置更新檔。

建立更新目錄
mkdir -p /data/centos/7

安裝相關更新套件
yum install yum-utils createrepo

下載套件
cd /data/centos/7
reposync --repoid=updates --repoid=extras --repoid=base

建立索引檔
createrepo /data/centos/7/base/
createrepo /data/centos/7/extras/
createrepo /data/centos/7/updates/


建立網站服務,讓client更新
使用httpd
yum install httpd
systemctl start httpd
systemctl enable httpd

建立更新目錄連結
mkdir -p /var/www/html/centos/7/updates /var/www/html/centos/7/extras/ /var/www/html/centos/7/base/
cd /var/www/html/centos/7/updates && ln -s /data/centos/7/updates/ x86_64 && cd -
cd /var/www/html/centos/7/extras && ln -s /data/centos/7/extras/ x86_64 && cd -
cd /var/www/html/centos/7/base && ln -s /data/centos/7/base/ x86_64 && cd -

建立更新repo
vim /etc/yum.repos.d/local.repo


[local-base]
name=Local Server-base
baseurl=http://192.168.1.72/centos/7/base/x86_64
enabled=1

[local-extras]
name=Local Server-extras
baseurl=http://192.168.1.72/centos/7/extras/x86_64
enabled=1

[local-updates]
name=Local Server-updates
baseurl=http://192.168.1.72/centos/7/updates/x86_64
enabled=1

指定由local更新

yum update --disablerepo="*" --enablerepo="local*"


每月定期更新排程
vi /etc/cron.monthly/repoupdate.sh
#!/bin/sh
cd /data/centos/7
reposync --repoid=updates --repoid=extras --repoid=base
createrepo /data/centos/7/base/
createrepo /data/centos/7/extras/
createrepo /data/centos/7/updates/

chomd +x /etc/cron.monthly/repoupdate.sh