2018年2月4日 星期日

Windows 10 SMB 設定

MIS總會遇到些奇奇怪怪的問題



問題:共用資料夾與印表機無法使用

環境Windows 10 

方向一、確認網路連線 共用資料夾 設定

方向二、共用資料夾 連線錯誤代碼 0x80004005

方向三、進入powershell 確認 SMB各版本服務



進入控制台>新增移除程式>WINDOWS安裝元件  安裝SMBv1 元件

2018年1月29日 星期一

Windows 10 開始功能表 修復

Windows 10 開始功能表

 當開始功能表故障時網路的教學大多為

工作管理員>程序>檔案總管 右鍵 重新啟用

但其實不見效,目前是方法一和四較有用 方法二會卡住。

 方法一:(不確定是否有效,但能解決多數系統的問題)
 以系統管理員權限執行「命令提示字元」 依次輸入以下指令:
Dism /Online /Cleanup-Image /CheckHealth
Dism /Online /Cleanup-Image /ScanHealth
Dism /Online /Cleanup-Image /RestoreHealth

 或是使用sfc /scannow

 說明: Windows 映像修復

  方法二:(以powershell來修復) 使用過後無效

 以系統管理員權限執行「命令提示字元」 輸入「powershell」並輸入以下指令: 
Get-AppxPackage | % { Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppxManifest.xml" -verbose }

 注意指令是一列的,沒有分段

 方法三:(第二快的方法)
以win+r叫出「執行」,輸入netplwiz並執行,重新建立一個帳號並設為系統管理員, 然後把原本的帳號刪掉,以新帳號繼續使用。(和原帳號相關的東西可能會不見)

 方法四: 
1、進入C:\Users\你的帳號\AppData\Local\TileDataLayer\Database,刪除掉vedatamodel.edb這個檔案,或是刪除Database整個資料夾 我是選擇直接刪除整個database資料夾。

 2、你會發現點擊功能表,什麼都沒有。但是開始功能表已經有反應了,此時重開機 

3、系統會自動產生所有應用的列表。但是微軟本身的應用沒有了。所以必須再次使用powershell,然後執行以下指令 Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}

結果遇到1709 升級後的BUG
只好用暗黑兵法
Class Shell

2018年1月22日 星期一

How to install LibreNMS for CentOS 7

再安裝用過Cacti、Whatsup、Zabbix後目前覺得此套介面最好用

目前還在摸索中

安裝筆記如下:
環境:CentOS 7.4 mini

yum install mariadb-server mariadb
systemctl start mariadb
firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload
mysql_secure_installation

mysql_secure_installation
Enter current password for root (enter for none): 第一次設定,直接按 Enter 鍵即可
Set root password? [Y/n] 按 Y 設定資料庫 root 密碼
New password: 輸入新密碼
Re-enter new password: 再次輸入新密碼
Password updated successfully!

建立資料庫使用者與權限
mysql -u root -p

CREATE USER 'librenmsuser'@'localhost' IDENTIFIED BY 'librenmspassword';
GRANT ALL PRIVILEGES ON librenmsdb.* TO 'librenmsuser'@'localhost';
FLUSH PRIVILEGES;
exit;
設定資料庫參數
[mysqld] 
innodb_file_per_table=1
sql-mode=""PRIVILEGES;
exit;
設定開機時自動啟動服務,重啟服務套用設定
systemctl enable mariadb

systemctl restart mariadb


安裝LibreNMS

安裝epel套件
yum install epel-release
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安裝PHP7、net-snmp、httpd套件
yum -y install php70w php70w-cli php70w-gd php70w-mysql php70w-snmp php70w-pear php70w-curl php70w-common httpd net-snmp mariadb ImageMagick jwhois nmap mtr rrdtool MySQL-python net-snmp-utils cronie php70w-mcrypt fping git vim
pear install Net_IPv4-1.3.4
pear install Net_IPv6-1.2.2b2



設定Git 套件 設定使用者名稱與信箱
git config --global user.name "username"
git config --global user.email user@email.com


設定PHP
vim /etc/php.ini 

date.timezone = "Asia/Taipei"

由GIT安裝LibreNMS
cd /opt
 git clone https://github.com/librenms/librenms.git librenms
 
#Add librenms user
useradd librenms -d /opt/librenms -M -r
usermod -a -G librenms apache

cd /opt/librenms
mkdir rrd logs
chmod 775 rrd


設定Apache Config
 vim /etc/httpd/conf.d/librenms.conf

  DocumentRoot /opt/librenms/html/
  ServerName  librenms.example.com
  CustomLog /opt/librenms/logs/access_log combined
  ErrorLog /opt/librenms/logs/error_log
  AllowEncodedSlashes NoDecode
  
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
  



設定防火牆開啟服務
firewall-cmd --permanent --add-service=http
firewall-cmd --reload

設定開機時自動啟動Httpd服務,重啟服務套用設定
systemctl enable httpd

systemctl start httpd



?

2017年12月29日 星期五

透過Postfix 以Gmail發信與 常用指令與設定

# 列出目前在 Mail Queue 中的信件
mailq

# 刪除所有在 Queue 中的郵件
postsuper -d ALL

# 刪除所有正在 deferred 佇列中的郵件 ( 刪除曾經發送失敗的信 )
postsuper -d ALL deferred

=================

relayhost = smtp.gmail.com:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/usr/local/etc/postfix/gmail_passwd
smtp_sasl_security_options =
smtp_use_tls = yes
====================

smtp.gmail.com:587 帳號@gmail.com:密碼
====
用以下指令製作 hash map:

# postmap /usr/local/etc/postfix/gmail_passwd




======================
1. 申請 Gmail 帳號

這理所當然是第一個程序,還沒有的話趕緊去申請一個吧,已經有了帳號就繼續下一個步驟。

2. 建立 SSL 憑證

為了方便管理,可以建立一個目錄來方便放置憑證,以 DR 為例:

# mkdir /etc/postfix/gmail

# cd /etc/postfix/gmail

然後使用以下指令建立憑證:

# openssl genrsa -out gmail.key 1024

# openssl req -new -key gmail.key -x509 -out gmail.crt

執行第二個指令時會要求填入資料(國家、地區、組織、信箱位址等),按著說明填入即可,這不會影響寄信功能。

3. 建立 Gmail 的密碼認證檔案

# vi /etc/postfix/sasl_passwd

然後寫入以下內容:

gmail-smtp.l.google.com username@gmail.com:password
smtp.gmail.com username@gmail.com:password

上頭的 username 和 password 就是要添入 Gmail 的帳號以及密碼,編輯完並儲存後,再執行下個指令去建立資料庫檔案:

# postmap hash:/etc/postfix/sasl_passwd

另外,由於該檔案裡頭存放了相當重要的帳號密碼資訊,DR 建議修改其存取權限,讓一般使用者無法瀏覽:

# chmod 600 /etc/postfix/sasl_passwd

# chmod 600 /etc/postfix/sasl_passwd.db

4. 設定 Postfix

# vi /etc/postfix/main.cf

寫入以下內容:

relayhost=[smtp.gmail.com]:587

smtp_sasl_auth_enable=yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tks_note_starttls_offer = yes
tls_random_source = dev:/dev/urandom
smtp_tls_scert_verifydepth = 5
smtp_tls_key_file=/etc/postfix/gmail/gmail.key
smtp_tls_cert_file=/etc/postfix/gmail/gmail.crt
smtpd_tls_ask_ccert = yes
smtpd_tls_req_ccert =no
smtp_tls_enforce_peername = no

儲存後重新啟動 Postfix:

# /etc/rc.d/init.d/postfix restart

smtp.gmail.com
Port for TLS/STARTTLS: 587

64.233.187.108

==============

account : ****@gmail.com
password : *****
=============

postfix 2.66

# inbound
smtpd_tls_security_level = may
smtpd_tls_protocols=!SSLv2,!SSLv3
smtpd_tls_mandatory_protocols=!SSLv2,!SSLv3
# outbound
smtp_tls_security_level = may
smtp_tls_protocols=!SSLv2,!SSLv3
smtp_tls_mandatory_protocols=!SSLv2,!SSLv3

smtp[d]_tls_security_level == "may": smtp[d]_tls_protocols is used
smtp[d]_tls_security_level == "encrypt": smtp[d]_tls_mandatory_protocols is used
smtp[d]_tls_security_level == "none": none of these two parameters is used
=============================
smtpd_tls_security_level = may
smtpd_tls_key_file = /etc/pki/tls/private/mail.example.com.key
smtpd_tls_cert_file = /etc/pki/tls/certs/mail.example.com.cert
# smtpd_tls_CAfile = /etc/pki/tls/root.crt
smtpd_tls_loglevel = 1
smtpd_tls_session_cache_timeout = 3600s
smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_tls_cache
tls_random_source = dev:/dev/urandom
tls_random_exchange_name = /var/lib/postfix/prng_exch
smtpd_tls_auth_only = yes
==
在 postfix 2.3 裡 'smtpd_tls_security_level = may' 取代舊有的 'smtpd_use_tls = yes' 並啟用 tls。我們註釋掉 smtpd_tls_CAfile 但在使用已簽署的憑證時卻須要利用該設定來指定發行機構的憑證。'smtpd_tls_loglevel = 1' 會將 tls 的工作階段記錄在 postfix 的郵件日誌(將它設為第 0 級停止記錄 TLS,而第 2 級對偵錯或許會有幫助)。smtpd_tls_session_cache 設定把 TLS 的工作階段金鑰暫存 1 小時,這個建議是出於重複地為每次連線協商 TLS 工作階段金鑰的代價相對昂貴。

最後那個設定,smtpd_tls_auth_only = yes,強迫 SASL 驗證採用 TLS 並禁止純文字驗證發生,除非已經建立了一個 TLS 工作階段。(在測試時註釋掉 smtpd_tls_auth_only = yes 也許會有用,好讓我們能測試 SSL/TLS 能否運作,但當 SSL/TLS 失效時仍有純文字 SASL 驗證作為後備)。
=============================
test
#telnet localhost 25
 Trying ::1...
 Trying 127.0.0.1...
 Connected to localhost.weithenn.org
 Escape character is '^]'.
 220 mail.weithenn.org ESMTP Postfix
 ehlo localhost                             //測試 TLS (此行為自行輸入)
 250-mail.weithenn.org
 250-PIPELINING
 250-SIZE 10240000
 250-VRFY
 250-ETRN
 250-STARTTLS                               //主機顯示 TLS 功能成功
 250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5
 250-AUTH=LOGIN PLAIN DIGEST-MD5 CRAM-MD5
 250-ENHANCEDSTATUSCODES
 250-8BITMIME
 250 DSN
 starttls    //查詢 TLS 功能是否啟動成功 (此行為自行輸入)
 220 2.0.0 Ready to start TLS               //系統回應 TLS 啟動成功
 quit                                       //離開 (此行為自行輸入)
 quit                                       //離開 (此行為自行輸入)
 Connection closed by foreign host.

ubuntu 14 install KVM

ubuntu install

安裝監控工具
apt-get install ssh
apt-get install vim

安裝RRD-tools
sudo apt-get install rrdtool
sudo apt-get install librrds-perl


安裝Webmin

sudo vim /etc/apt/sources.list

deb http://download.webmin.com/download/repository sarge contrib
wget http://www.webmin.com/jcameron-key.asc
sudo apt-key add jcameron-key.asc
sudo apt-get update
sudo apt-get install webmin

###
Webmin install complete. You can now login to
https://your_server_ip:10000 as root with your
root password, or as any user who can use `sudo`.
###
安裝硬碟監控套件
下載套件
https://sourceforge.net/projects/webminstats/files/Sysstats/

進入webmin>Webmin Configuration>modules >From uploaded files/Sysstats/

左邊欄位的System內會出現Historic System Statistics
###
安裝KVM

#確認CPU支援虛擬化
sudo apt-get install cpu-checker

$ kvm-ok
#INFO: /dev/kvm exists
#KVM acceleration can be used

#===
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils virt-manager

#查看group是否建立
egrep libvirtd /etc/group

#登出登入或reboot
sync;sync;shutdwon -r

#===
安裝完成
image位置

windows 0xc00035a

更新主機版BIOS後,開起VM出現錯誤0xc00035a

原因:主機板CPU VT-X 虛擬化支援選項被關閉。

2017年3月22日 星期三

Mysql 5.7.16 replication

#打#號之註解為原先已經有設定故註記起來。

[Master]

vim /etc/my.cnf
#======
[mysqld]
bind-address=10.10.0.1
server-id=1
binlog-ignore-db = "mysql"
binlog-format = mixed
log-bin=mysql-bin
#datadir=/var/lib/mysql
#innodb_flush_log_at_trx_commit=1
sync_binlog=1


#====
systemctl restart mysqld
#====

建立一個用作同步的帳號, 以下會建立帳號 replication, 密碼是 P@ssw0rd, Slave 的 ip 為10.10.0.2

CREATE USER replication@10.10.0.2;
GRANT REPLICATION SLAVE ON *.* TO replication@10.10.0.2 IDENTIFIED BY 'P@ssw0rd';

flush privileges;

SHOW MASTER STATUS;
exit;

#========================
然後要用 mysqldump 匯出資料庫的 .sql 檔, 要放到 Slave 匯入:

mysqldump –skip-lock-tables –all-databases –user=root –password –master-data > masterdatabase.sql

#========================
[Slave]
#=======
[mysqld]
server-id=2
binlog-format=mixed
log_bin=mysql-bin
relay-log=mysql-relay-bin
log-slave-updates=1
read-only=1
#====
systemctl restart mysqld
#====

用 root 登入 MySQL, 建立資料庫

create database database-name;
exit;

#============
設定SLAVE
#===========


MariaDB> CHANGE MASTER TO MASTER_HOST='10.10.0.1',MASTER_USER='replication',MASTER_PASSWORD='P@ssw0rd', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=500;
MariaDB> START SLAVE;
MariaDB> SHOW SLAVE STATUS \G;


現在 Slave 已經可以同步, 要查詢 Slave 的狀態, 可以登入 MySQL 用以下指令檢查:

START SLAVE;
SHOW SLAVE STATUS \G;

=====================