show code js

2019年5月2日 星期四

VPS Create, base and safe config 建立第一個VPS並作基礎及安全調適

租下自已第一個VPS需要作什麼呢?答案是作基礎設定及安全方面的調整,必竟剛安裝完OS的VPS是很脆弱的,放置一段時間就會在登入後得到很多連入失敗的訊息。

Your frist VPS was creating, you can config it about base or safe setting.
You can see more log of session to connect your VPS, that is not safe.

這邊只提供基本的調整,並且以Centos為主,若是使用其他OS也可以找到相對應的資訊。

Just for OS of Centos, if you choose other os, you can search those keywords by google.

Have fun with you.

祝玩的愉快

  1. Important: Dropbox support, if you use it for git or share files, you must check out before 如l果你使用Drobpx要注意已經不支援部份Linux的磁碟格式
  2. download putty(remote control) and login your vps and winscp to upload file to vps(file transfer)
    下載putty或其他ssh連線工具連到你的vps,使用winscp或filezilla使用sftp連到vps上下傳檔案
  3. 3party: more mod need those, or you can pass this.第三方軟件、工具
    1. yum install epel-release -y
    2. replace vi: nano(to edit file easy): yum install nano -y 文字編輯器,比內建的vi還好用
      #as cat or vi
      #Save and exit the file by pressing Ctrl-x, then y, then Enter.
  4. Choose VPS 選擇VPS
  5. Choose and Rebuild OS for Centos 7 x64 or Newest with 64bit 選擇64位元或更新的版本
    1. random SSH port: can start firewalld and remove ssh and add other port number to transfer to port 22 不要使用預設的ssh埠,作以下的修改
      1. vi or nano /etc/ssh/sshd_config
      2. remark # at port 22 and change 22 to other number 將#去除後將22改為其他數字1~65535
      3. if you had installd firewall-cmd, must add this new port 如果你有啟用防火牆記得要確認
      4. reboot
      5. if you can not connect VPS, use Admin Panel to config it. 如果連不上,可使用主機商提供的控制台在後端取得登入位置、帳密後進入修改,如果在前端設定失敗遺失連線後都可以在這裡進行管理,如果親臨主機
    2. change root password: passed 修改root密碼,也有人將root封鎖並在之前建立一組新的同等於root的帳號密碼,主要防止被暴力破解及防猜
  6. Check OS version and bit 確認作業系統名稱、版本及位元
    1. os version: cat /etc/*release*
    2. os bit: uname -a
  7. (pass)close password mode: if you wanna to do, please create and install ca before this. 關閉帳密模式,在建立憑證後並作首次連線時,會確認憑證,關閉後只有有安裝憑證的裝置才可以連入,不怕帳密被洩漏
    1. vi or nano /etc/ssh/sshd_config
    2. change: passwordauthentication no
  8. change host name 改變主機名稱
    1. hostnamectl set-hostname your_domain.com
    2. hostnamectl, show just host name
  9. Yum maintain 這是centos的軟件安裝工具,作基本的維護,也可以每次開機自動執行或手動執行
    1. clean: yum clean all -y
    2. upgrade: yum upgrade -y
    3. update: yum -y update
  10. os config 系統設定:時區、ntp及語言
    1. chage timezone: timedatectl set-timezone Asia/Taipei
    2. Enable NTP: timedatectl set-ntp yes
      #if this is fail because is use new function is chrony of yum
    3. Change Language: 
      1. default: localectl
      2. list: localectl list-locales | grep zh_
      3. change: localectl set-locale LANG=zh_TW.utf8
      4. restart: reboot
  11. disable ipv6:關閉ipv6 有些時候為了某些原因需要關閉它
    1. vi or nano /etc/sysctl.conf, add below
      net.ipv6.conf.all.disable_ipv6 = 1
      net.ipv6.conf.default.disable_ipv6 = 1
    2. active: reboot or sysctl -p
  12. firewall 防火牆
    1. install: yum install firewalld -y
    2. enable: systemctl enable firewalld
    3. start: systemctl start firewalld
    4. list: --permanent is always, if not use it, your setting will lose after vps reboot 增加此參數表示永久有效,如果沒有加則重開機後就會失效
      1. temp: firewall-cmd --list-all
      2. always: firewall-cmd --list-all --permanent
    5. add new service: [--permanent forevery, if no this args will now and clean after reload or reboot]
      firewall-cmd --permanent --add-service=[service.name]
      {firewall-cmd --permanent --zone=public --add-service=[service.name]}
      firewall-cmd --reload
    6. add new port:
      firewall-cmd --permanent --add-port=[port number]/[tcp/udp]
      firewall-cmd --reload
    7. ssh port not default: need setting in firewall 如果你的ssh連線埠不是預設,需要注意在這邊測試與設定
    8. port convert transfer to port: 
      1. remove service default port
      2. firewall-cmd --permanent --add-forward-port=port=1234:proto=tcp:toport=5678
        {firewall-cmd --zone=public --add-forward-port=port=1234:proto=tcp:toport=5678 --permanent}
  13. SSH Safe only by denyhosts 防功擊模組,可以白名單與黑名單進行管理,遇到功擊將會自動列入黑名單
    1. 3party epel-release: run 5-3
    2. install: yum install denyhosts -y
    3. white ip: nano /etc/hosts.allow #sshd: 220.130.38.233
    4. black ip: nano /etc/hosts.deny #sshd: ALL **
    5. restart: systemctl restart denyhosts
    6. unlock ip:
      nano /etc/hosts.deny
      nano /var/lib/denyhosts/hosts
      nano /var/lib/denyhosts/hosts-restricted
      nano /var/lib/denyhosts/hosts-root
      nano /var/lib/denyhosts/hosts-valid
      nano /var/lib/denyhosts/users-hosts
      systemctl restart denyhosts
  14. DDOS safe 防護ddos功擊模組
    1. ip status: ip -s l(link)
      #ip -s l | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
      #ip addr show
    2. install:
      wget http://www.inetbase.com/scripts/ddos/install.sh
      chmod 0700 install.sh
      sh install.sh
      #on : prompt key "q" and enter to exit
    3. default: nano /usr/local/ddos/ddos.conf
      FREQ=1 ;检测时间间隔,默认是一分钟,如果修改这个要重新设置Cron Job
      NO_OF_CONNECTIONS=150 ;最大连接数,超过这个就会禁止IP
      APF_BAN=1 ;使用APF设置为1,使用iptables设置为0
      KILL=1 ;是否禁止IP
      EMAIL_TO=”root” ;邮件通知,写上接收邮件的邮箱
      BAN_PERIOD=600 ;禁止IP时长,默认是600秒
    4. white ip: nano /usr/local/ddos/ignore.ip.list
    5. lock modify: chattr +i /usr/local/ddos/ignore.ip.list
    6. unlock modify: chattr -i /usr/local/ddos/ignore.ip.list
    7. uninstall:
      wget http://www.inetbase.com/scripts/ddos/uninstall.ddos
    8. chmod 0700 uninstall.ddos
      ./uninstall.ddos
  15. add new root user 增加新的帳號
    1. create
      1. adduser [username]
      2. passwd [username]
      3. usermod -aG wheel [username]
    2. test
      1. su - username
當然關於安全設定與系統調校還有很多項目與面向,可以善用搜尋找到自已想要的調整,這邊只提供我較常用的項目(我都不使用預設的埠號,因此,有些已經沒有再使用了)

If you need more safe config or info, you can use google to search more info for you need.
Those are my usually use itme by myself, but some item was not now.

什麼是VPS(Virtual Private Server)

玩VPS一陣子了,
總算想來整理一下累積下來的資料來作發表,
也讓這裡再次充電。

打著VPS關鍵字上網找,可以找到一整堆的資訊,但真假、優劣那辨,
也需要花不少時間找到合適自已,或可以建立自已要的功能在VPS上。

VPS與HOST或虛擬主機有什麼分別,簡單來說,如果想要簡單建置主機、管理,
就選擇HOST、虛擬主機,而想要打造自已個人獨有的服務器,那麼VPS就適合你。

VPS主機商會隨著VPS的規格提供不同的OS可以安裝,有的甚至可以自訂OS,
當然還有其他更特別、高階的VPS,如ANDROID OS、GPU VPS或實體VPS,
當然在硬體上也有區分OPENVZ、KVM、SSD等等,可以多了解後再下手。

VPS租金有多有少,少的未必不好用,貴的也不一定會好用,還是要多了解,
當然初期會建議先玩玩便宜的VPS為入門、學習,但動作要快,眾多VPS商的價格已水漲船高。

另外VPS雖然獨立,但大部份都會超賣,所以效能各家有異,現在流暢也不一定以後會保持。

在接下來我會在VPS建立上作分享筆記。

備註:如果不想常常重灌,還是選HOST、虛擬主機吧。

2019年2月17日 星期日

二小時快速學會寫程式之課程1一開發環境配置(第1小時)

1.啟動Web Server use IIS(Internet Information Service)
   1-1.首先
      1-1-1.點擊控制台
      1-1-2.點擊程式集
      1-1-3.點擊開啟或關閉Windows功能
   1-2.將IIS鉤選後,再將IIS功能展開,在應用程式開發的子項中,將CGI鉤選,然後確定
   1-3.接著就會完成IIS的功能啟動,打開瀏覽器,在網址列輸入 http://localhost 即可看到IIS的歡迎畫面
   1-4.補充
      1-4-1.由於後面安裝MYSQL時可能需要 Framework 3.5 因此可在此一併開啟之功能,而 Framework 4.0 則需要下載後安裝
      1-4-2.承上,win10都只要啟動即可
      1-4-3.可自行決定是否安裝到4.5.1版
2.安裝PHP
   2-1.首先至windows.php.net下載具有installer的PHP版本,請選擇要開發使用的PHP版本,使用封裝程式對新手較為簡便,安裝時只要注意選擇IIS FastCGI為安裝選項後即可確定到完成安裝為止  。
   2-2.另外介紹另一種更為簡單的方式,
      2-2-1.進入 http://www.microsoft.com/web/downloads/platform.aspx 下載 Web Platform Installer並完成安裝
      2-2-2.開啟 Web Platform Installer 搜尋 PHP 即可列出關鍵字 PHP的套件
      2-2-3.將您需要的PHP版本後點擊右邊的{新增}鈕即可,如果資料庫要使用MSSQL請加安裝Microsoft Drivers for PHP for SQL Server in IIS (or IIS Express)
         2-2-3-1.增加安裝 URL Rewrite
         2-2-3-2.PHP Manager,如果您是win7直接在上一步驟選擇後即可,若是win10請搜尋PHP Manager for IIS10,下載後並完成安裝
      2-2-4.新增好後,按下確定即可進行套件安裝
      2-2-5.安裝完成後,在 C:\inetpub\wwwroot下新增 phpinfo.php 檔案,檔案內容請輸入 <?php phpinfo(); ?>  後存檔
      2-2-6.開啟瀏覽器並且輸入 http://localhost/phpinfo.php 即可看到 PHP 環境的各項配置   
      2-2-7.記得確認php版本是否正確
   2-3.啟用擴充功能,開啟IIS控制台,展開至Default Web Site,進入PHP Manager後在PHP Extensions將需要的擴充功能啟用或是新增
3.安裝MYSQL
   3-1.主程式
      3-1-1.因為版本的關系可能需要Framework 3.5 及 Framework 4.0 請先行安裝
      3-1-2‧至MYSQL.COM網站,點擊上方的Download(GA)
      3-1-3‧找到 MySQL Community Edition (GPL) 點擊 Community (GPL) Downloads,再點擊 MySQL Community Server 下方的 Download
      3-1-4‧選擇好版本及安裝的方式後 點擊 Download (盡可能選擇離線安裝,以免受網路影響)
      3-1-5‧安裝過程中注意記下root帳密
   3-2‧安裝MYSQL工具
      3-2-1.使用網站套件 phpmyadmin
         3-2-1-1.請至 www.phpmyadmin.net 下載最新套件
         3-2-1-2.解壓縮後將目錄改名為phpmyadmin,然後將目錄內的config.sample.ini.php改名為config.ini.php,然後將整個目錄複製到 C:\inetpub\wwwroot
         3-2-1-3.開啟瀏覽器並輸入 http://localhost/phpmyadmin 即可看到登入的畫面
         3-2-1-4.輸入MYSQL的ROOT帳戶的密碼即可進入資料庫

2019年1月23日 星期三

SoildWork Sim

劃CAD也是我的興趣之一,試試設計L架作模擬測試,也可以作組合件測試