2019年12月27日 星期五

ubuntu 使用 timedatectl 更改 Timezone 時區以及

在 ubuntu 裡內建了時間同步指令 timedatectl 及 timesyncd,來取代 ntp 和 ntpdate ,達到系統時間網路同步。
可以用 date 命令查看系統的當前時區:
date
或在 /etc/timezone 文件中查找當前時區。
cat /etc/timezone
若想更改時區,可先用以下指俴取得 timezone 列表:
timedatectl list-timezones
但 Timezone 列表十分長, 用 grep 過濾會較方便, 以下只會印出亞洲區的時區:
timedatectl list-timezones | grep Asia
找到要設定的時區後,便可以設定: 台北時區:
timedatectl set-timezone Asia/Taipei
香港時區:
timedatectl set-timezone Asia/Hong_Kong
設定好後, 可以用 timedatectl 指令檢查時區是否設定正確,時鐘是否與網際網路同步。只需運行:
timedatectl
如你所見,timedatectl 命令顯示本地時間、世界時、時區以及系統時鐘是否與網際網路伺服器同步,以及 systemd-timesyncd.service 是處於活動還是非活動狀態,等等。
如果 System clock synchronized: no 則表示時鐘不同步,那麼 timesyncd 服務可能處於非活動狀態。因此,只需重啟服務並看下是否正常。

sudo systemctl restart systemd-timesyncd.service
然後檢查 timesyncd 服務狀態:
sudo systemctl status systemd-timesyncd.service
如果此服務已啟用並處於活動狀態,那麼系統時鐘應與網際網路時間伺服器同步。 你可以使用命令驗證是否啟用了時間同步:
timedatectl
如果仍然不起作用,請運行以下命令以啟用時間同步:
sudo timedatectl set-ntp true

Ubuntu 開啟開放 root 登入 ssh

基於安全理由,Ubuntu 預設不能使用 root 登入 ssh,但如果是內部測試的主機,為了方便使用,可以用以下方法修改解除 root 登入限制:

首先要重新設定 Ubuntu 的 root 密碼, 輸入以下指令:

sudo passwd root
修改了 root 密碼後,開啟 sshd 的設定檔:
nano /etc/ssh/sshd_config
找到以下一行:
PermitRootLogin prohibit-password
改為:
PermitRootLogin yes

重新啟動 sshd:
sudo systemctl restart sshd
重新啟動 sshd 後,便可以用 root 帳號發入 ssh。

*注意:如果有設定防火牆,記得把 SSH port:22/TCP (限定叢集中所有節點與管理者連線來源 IP)打開。

ubuntu 19.1 安裝 mysql 8 服務

一如往常,先更新 apt-get
sudo apt-get update
安裝 MySQL 8.0
sudo apt-get install mysql-server
這邊使用 netstat 指令來查看, netstat 的功用是顯示通訊協定統計資料以及目前的TCP/IP 網路連線,所以要使用它來查看已安裝好的 MySQL 是否有連線監聽。此指令要另外安裝,安裝指令如下:
sudo apt-get install net-tools
安裝完成後就能透過 netstat 指令來查看 MySQL 是否安裝成功:
sudo netstat -tap | grep mysql
設置 MySQL 允許遠端訪問
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir  = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address  = 127.0.0.1 <== 註解起來
#
# * Fine Tuning
#
key_buffer_size  = 16M
# max_allowed_packet = 64M
# thread_stack  = 256K
進入 MySQL 服務,一開始密碼為空值
mysql -u root -p
CREATE USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678';

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';

CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '12345678';

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '12345678';

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

FLUSH PRIVILEGES;
其他相關

ubuntu mysql 8 的資料庫預設路徑為 /var/lib/mysql
若變更或掛載了新路徑, 記得要改權限
chmod -R 700 /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
查詢mysql資料庫檔案的存放位置
在mysql資料庫中,有時候並不是很容易找出mysql資料庫檔案data的存放位置,這時就可以使用mysql的命令列工具進行查詢.
show variables like '%datadir%';

2019年12月26日 星期四

Proxmox VE 節點的重要連接埠記錄


WebGUI: 8006/TCP (限定管理者連線來源 IP)
SSH: 22/TCP (限定叢集中所有節點與管理者連線來源 IP)
DNS: 預設使用的TCP和UDP連接埠為53 (netstat -tulnp | grep named)
SPICE: 3128/TCP (若有使用此功能)
Corosync: 5404~5405/UDP (叢集溝通使用,廣播,必開)
rpcbind: 111/TCP (若有做為 NFS Server)

2019年12月24日 星期二

Ubuntu19.1 安裝 LEMP(Linux+Nginx+PHP)環境建立


Step 1 : 安裝 Nginx Web Server

sudo apt-get update

sudo apt-get install nginx

在瀏覽器輸入 http://server_ip 出現下圖,即表示安裝成功

Step 2 : 安裝php及設定php.ini
sudo apt-get install php-fpm php-mysql php-mbstring php7.3-gd php-curl

2. 修改php.ini (Modifying php.ini file) :
sudo nano /etc/php/7.3/fpm/php.ini

找到
;cgi.fix_pathinfo=1
改成
cgi.fix_pathinfo=0

存檔並重啟 php 服務
sudo service php7.3-fpm restart

然後要設定讓nginx能夠執行PHP腳本 輸入以下指令修改nginx設定
sudo nano /etc/nginx/sites-available/default

我們將其改成如下 (紅色表示變動部分)
server {
    listen 80 default_server;
    listen [::]:80 default_server;
 
    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;
 
    server_name _;
 
    location / {
        try_files $uri $uri/ =404;
    }
 
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }
 
    location ~ /\.ht {
        deny all;
    }
}

修改完後儲存 並輸入以下指令檢查設定檔格式是否沒有錯誤
sudo nginx -t

檢查沒有錯誤就輸入指令重新載入nginx設定
sudo systemctl reload nginx

如何在 Blogger 顯示程式碼 - 使用 Google Code Prettify

Blogger 本身沒有內建的貼code語法,
可使用 Google Code Prettify,原本 Google Code Prettify 是放在 Google Code,但後來釋出放在 Github 上,

在 Blogger 後台 > 版面配置 > 新增小工具 裡



















新增 HTML/JavaScript

























<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

就完成了

使用方式
<pre class="prettyprint">
程式碼...
</pre>

<code class="prettyprint">
程式碼...
</code>

*如果code有使用到<或是>之類的符號必須要先經過HTML轉碼

有四種主題可選擇
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=desert"></script>

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=sunburst"></script>

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=sons-of-obsidian"></script>

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=doxy"></script>

Ubuntu 19.1 安裝 samba 並使用 SMBv2 版本

1. 安裝samba服務
sudo apt-get update

sudo apt-get install samba
2. 修改samba設定檔
nano /etc/samba/smb.conf
[global]

## Browsing/Identification ###

# Change this to the workgroup/NT-domain name your Samba server will part of
   workgroup = WORKGROUP
security = user 
# 最小支援的SMBv2版本
min protocol = SMB2
# server string is the equivalent of the NT Description field
   server string = %h server (Samba, Ubuntu)

#### Networking ####

# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
;   interfaces = 127.0.0.0/8 eth0
interfaces = 127.0.0.0/8 192.168.0.0/16
# Cap the size of the individual log files (in KiB).
;   max log size = 1000
max log size = 100
#======================= Share Definitions =======================
[root]
   comment = Root Directories
   path = /
   writeable = yes
   browseable = yes
   valid users = root

[www]
   comment = www
   path = /var/www
   writeable = yes
   browseable = yes
   valid users = root

# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username

並把以下註解掉
;[printers]
;   comment = All Printers
;   browseable = no
;   path = /var/spool/samba
;   printable = yes
;   guest ok = no
;   read only = yes
;   create mask = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
;[print$]
;   comment = Printer Drivers
;   path = /var/lib/samba/printers
;   browseable = yes
;   read only = yes
;   guest ok = no
3. 重啟 samba 服務
sudo systemctl restart smbd nmbd
4. 建立 Samba 使用者
sudo smbpasswd -a root
其他相關用法

若有修改設定檔 smb.conf,讓 samba 重新載入設定檔,可以使用以下指令,不需重啟 samba 服務
sudo systemctl reload smbd nmbd
檢查設定檔是否有誤
testparm
查看 samba 連線狀態
sudo smbstatus

2019年12月23日 星期一

使用 ntp 取代 ntpdate

安裝 ntp 服務
sudo apt-get update

sudo apt-get install ntp -y

可像 ntpdate 一樣,修正系統時間
要先關閉服務,不然會出現錯誤
service ntp stop

ntpd -q tick.stdtime.gov.tw 或使用 ntpd -q time.google.com



更新完後,再打開服務
service ntp start

可使用 ntpq -p 來確認目前時間同步的狀況, 其中包含 delay, offset, jitter 的相關資訊.

root@pve1:~# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
*122-116-140-147 17.253.116.125   2 u  821 1024  377    4.249    1.304   1.156
-static.home.twn 133.243.238.243  2 u  551 1024  377   10.986    6.636   4.284
+t1.time.tw1.yah 119.160.254.155  2 u  914 1024  377    3.517    1.079   0.816
+220-133-209-83. 62.161.56.158    3 u  916 1024  377    3.721    1.132   0.742
-t2.time.tw1.yah 119.160.254.155  2 u  632 1024  377    2.606    0.475   0.417
-bbr.cxs.pw      242.71.143.169   2 u 1028 1024  377    5.625   -0.063   0.511

PROXMOX RRDC update error 解決方法

一直出現以下錯誤訊息
Dec 23 19:49:41 pve pmxcfs[1209]: [status] notice: RRDC update error /var/lib/rrdcached/db/pve2-node/pve: -1
Dec 23 19:49:41 pve pmxcfs[1209]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-node/pve: /var/lib/rrdcached/db/pve2-node/pve: illegal attempt to update using time 1577101781 when last update time is 1577113269 (minimum one second step)
Dec 23 19:49:41 pve pmxcfs[1209]: [status] notice: RRDC update error /var/lib/rrdcached/db/pve2-storage/pve/local-zfs: -1
Dec 23 19:49:41 pve pmxcfs[1209]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/pve/local-zfs: /var/lib/rrdcached/db/pve2-storage/pve/local-zfs: illegal attempt to update using time 1577101781 when last update time is 1577113209 (minimum one second step)
Dec 23 19:49:41 pve pmxcfs[1209]: [status] notice: RRDC update error /var/lib/rrdcached/db/pve2-storage/pve/local: -1
Dec 23 19:49:41 pve pmxcfs[1209]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/pve/local: /var/lib/rrdcached/db/pve2-storage/pve/local: illegal attempt to update using time 1577101781 when last update time is 1577113209 (minimum one second step)
Dec 23 19:49:51 pve pmxcfs[1209]: [status] notice: RRDC update error /var/lib/rrdcached/db/pve2-node/pve: -1
Dec 23 19:49:51 pve pmxcfs[1209]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-node/pve: /var/lib/rrdcached/db/pve2-node/pve: illegal attempt to update using time 1577101791 when last update time is 1577113269 (minimum one second step)
Dec 23 19:49:52 pve pmxcfs[1209]: [status] notice: RRDC update error /var/lib/rrdcached/db/pve2-storage/pve/local-zfs: -1
Dec 23 19:49:52 pve pmxcfs[1209]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/pve/local-zfs: /var/lib/rrdcached/db/pve2-storage/pve/local-zfs: illegal attempt to update using time 1577101791 when last update time is 1577113209 (minimum one second step)
Dec 23 19:49:52 pve pmxcfs[1209]: [status] notice: RRDC update error /var/lib/rrdcached/db/pve2-storage/pve/local: -1
Dec 23 19:49:52 pve pmxcfs[1209]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/pve/local: /var/lib/rrdcached/db/pve2-storage/pve/local: illegal attempt to update using time 1577101791 when last update time is 1577113209 (minimum one second step)

解決方法
service rrdcached stop
rm -rf /var/lib/rrdcached
service rrdcached start

確認結果
service rrdcached status

顯示訊息


proxmox 6 apt No-Subscription

這個情況,是因為預設安裝完成的 PVE 是連接到 Enterprise Repository 的更新來源,而您沒有付費取得授權金鑰因此無法更新。

解決辦法容易,可以將 PVE 的更新來源切換為 No-Subscription Repository 或 Test Repository,即可順利更新。

開啟 /etc/apt/sources.list
新增一行
deb http://download.proxmox.com/debian/pve buster pve-no-subscription
deb http://download.proxmox.com/debian/pve buster pve-no-subscription

deb http://ftp.tw.debian.org/debian buster main contrib

deb http://ftp.tw.debian.org/debian buster-updates main contrib

# security updates
deb http://security.debian.org buster/updates main contrib


開啟 /etc/apt/sources.list.d/pve-enterprise.list
註解掉 #deb https://enterprise.proxmox.com/debian/pve buster pve-enterprise
#deb https://enterprise.proxmox.com/debian/pve buster pve-enterprise

取消Enterprise Repository 更新來源

參考

https://pve.proxmox.com/wiki/Package_Repositories
http://blog.jason.tools/2019/02/pve-subscription.html