2019年4月11日 星期四

在 CentOS 7 上禁用 Transparent Huge Pages(THP)


因為資料庫的工作負載通常在THP上表現不佳,所以應該禁用THP,確保MongoDB能獲得最佳的效能。

建立init.d script
vi /etc/init.d/disable-transparent-hugepages
#!/bin/bash
### BEGIN INIT INFO
# Provides:          disable-transparent-hugepages
# Required-Start:    $local_fs
# Required-Stop:
# X-Start-Before:    mongod mongodb-mms-automation-agent
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description:       Disable Linux transparent huge pages, to improve
#                    database performance.
### END INIT INFO

case $1 in
  start)
    if [ -d /sys/kernel/mm/transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/transparent_hugepage
    elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/redhat_transparent_hugepage
    else
      return 0
    fi

    echo 'never' > ${thp_path}/enabled
    echo 'never' > ${thp_path}/defrag

    re='^[0-1]+$'
    if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]]
    then
      # RHEL 7
      echo 0  > ${thp_path}/khugepaged/defrag
    else
      # RHEL 6
      echo 'no' > ${thp_path}/khugepaged/defrag
    fi

    unset re
    unset thp_path
    ;;
esac

script可執行
sudo chmod 755 /etc/init.d/disable-transparent-hugepages

 設置成作業系統啟動時能自動執行
sudo chkconfig --add disable-transparent-hugepages

使用tunedktune
建立新的profile
sudo mkdir /etc/tuned/no-thp
編輯tuned.conf
vi /etc/tuned/no-thp/tuned.conf
  [main]
  include=virtual-guest

  [vm]
  transparent_hugepages=never
啟動新的profile
sudo tuned-adm profile no-thp
測試變更後結果
重新開機後執行下列指令
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/defrag
執行後的結果應該顯示為
always madvise [never]




2019年4月10日 星期三

在 CentOS 7 上禁用 SELinux


就安全性考量,SELinux是要開啟的,但在安裝一些軟體的過程中,軟體官方文件都建議將SELinux關閉,避免造成出乎意料的問題。


vi /etc/selinux/config

SELINUX=enforcing

改為

SELINUX=disabled

存檔後重新開機。

2019年3月22日 星期五

在 CentOS 7 上安裝 Grafana 6.0.2


新增Grafana Repository

vi /etc/yum.repos.d/grafana.repo

[grafana]
name = grafana
baseurl = https://packages.grafana.com/oss/rpm
repo_gpgcheck = 1
enabled = 1
gpgcheck = 1
gpgkey = http://packages.grafana.com/gpg.key
sslverify = 1
sslcacert = /etc/pki/tls/certs/ca-bundle.crt

安裝Grafana

yum install grafana

啟動grafana服務

systemctl daemon-reload

systemctl start grafana-server

查詢grafana服務狀態

systemctl status grafana-server

設定開機時自動啟動grafana服務

systemctl enable grafana-server.service

接著就能開啟瀏覽器輸入http://<IP_Address>:3000登入,預設的帳號密碼都是admin

在 CentOS 7 上安裝 Telegraf 1.10


新增Telegraf Repository

跟新增InfluxDB Repository一樣

安裝Telegraf 1.10

yum install telegraf

啟動telegraf服務

systemctl start telegraf

查詢telegraf服務狀態

systemctl status telegraf

設定開機時自動啟動telegraf服務

systemctl enable telegraf


使用默認的輸出入插件建立配置文件

telegraf config > telegraf.conf

建立具有特定輸入和輸入的配置文件

telegraf --input-filter <pluginname>[:<pluginname>] --output-filter <outputname>[:<outpurname>] config > telegraf.conf

舉例:

telegraf --input-filter cpu:mem:net:swap --output-filter influxdb:kafka config > telegraf.conf






在 CentOS 7 上安裝 InfluxDB 1.7


安裝InfluxDB需要使用root或其他有管理員權限的帳號


預設InfluxDB會使用到兩個網路Port

  • TCP Port 8086Client-Server透過InfluxDB HTTP API進行溝通
  • TCP Port 8088:透過RPC服務執行備份及還原的操作

除了上述兩個Port,有些Plugin會需要使用到自定義的端口,可以透過配置文件修改所有端口映射。配置文件位於/etc/influxdb/influxdb.conf


設定NTP服務,不管什麼在安裝什麼系統,這都是一定要的,避免各系統時間不同步時,會有些異常


新增InfluxDB Repository

vi /etc/yum.repos.d/influxdb.repo

[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key

安裝InfluxDB 1.7

yum install influxdb -y

啟動influxdb服務

systemctl start influxdb

查詢influxdb服務狀態

systemctl status influxdb

設定開機時自動啟動influxdb服務

systemctl enable influxdb


建立資料庫

influx -precision rfc3339

CREATE DATABASE <DB_NAME>

顯示所有的資料庫

SHOW DATABASES

指定資料竹行InfluxQL語句

USE <DB_NAME>
接下來所有的SQL語句都會針對<DB_NAME>這個資料庫運行





在 CentOS 7 上安裝設定 NTP


在安裝伺服器時,尤其是分散式系統,非常需要使用NTP來校時,避免各伺服器上的時間不同步
設定NTP
yum install ntp
編輯/etc/ntp.conf

將原有的NTP伺服器註解,並加入下列伺服器
server      tock.stdtime.gov.tw
server      time.stdtime.gov.tw
server      tick.stdtime.gov.tw
server      watch.stdtime.gov.tw
server      clock.stdtime.gov.tw

如果要指向公司內部的Time Server(底下IP為舉例說明)
restrict    192.168.1.2
server      192.168.1.2

啟動ntpd服務

systemctl start ntpd
檢查ntpd服務的狀態
systemctl status ntpd
設定開機自動啟動ntpd服務
systemctl enable ntpd
更新校正時間後,可以透過下列指令將時間寫入BIOS
hwclock -w




2019年2月19日 星期二

Proxmox 的套件升級


因為Proxmox是基於Debrian,所以可以使用apt指令做套件的升級或安裝。

Proxmox提供了三種不同的套件Repository

    • Proxmox VE Enterprise Repository
      這是預設的Repository,提供穩定的套件供訂閱者使用。在生產環境中使用Proxmox,建議使用這Repository更新。也因為是預設的Repository,所以初次使用的使用者在執行更新指令時,會遇上無法更新的狀態。這時候就要改使用第二種非訂閱者使用的Repository,並且將/etc/apt/sources.list.d/pve-enterprise.list中的deb https://enterprise.proxmox.com/debian/pve stretch pve-enterprise這行敘述前面加上#,讓執行apt-get update時不去讀取。
      編輯 /etc/apt/sources.list
      deb http://ftp.debian.org/debian stretch main contrib
      deb http://security.debian.org stretch/updates main contrib


    • Proxmox VE No-Subscription Repository
      這是提供給非訂閱者的Repository,不建議在生產環境中運行,因為這些套件並未經過大量的測試跟驗證。
      編輯 /etc/apt/sources.list
      deb http://ftp.debian.org/debian stretch main contrib
      deb http://download.proxmox.com/debian/pve stretch pve-no-subscription
      deb http://security.debian.org stretch/updates main contrib
    • Proxmox VE Test Repository
      這個測試用的Repository,提供了最新的套件供開發人員測試新功能
      編輯 /etc/apt/sources.list
      deb http://download.proxmox.com/debian/pve stretch pvetest

確認要使用的Repository後就可以執行下列指令進行套件更新

apt-get update
apt-get dist-upgrade





2019年2月14日 星期四

安裝 Proxmox 5.3


下載Promox的映像檔

使用PassMark ImageUSBProxmox映像檔燒錄到隨身碟中

透過隨身碟開機,進行安裝Proxmox

安裝前先設定NTP


進入到歡迎頁面後會有四個選項,分別是

Install Proxmox VE

Install Proxmox VE (Debug mode)

Rescue Boot

Test memory

因為是要安裝Proxmox,所以選擇"Install Proxmox VE"


Porxmox Virtualization EnvironmentPVE)頁面

Target Harddisk:選擇要安裝Proxmox的硬碟

Option:可以選擇Filesystem的格式,Proxmox有提供ext3ext4xfszfsRAID0)、zfsRAID1)、zfsRAID10)、zfsRAIDZ-1)、zfsRAIDZ-2)、zfsRAIDZ-3)等格式。

備註:預設是使用ext4。如果選擇ext3ext4xfs作為Filesystem,安裝程序將使用LVM,並提供額外的選項來限制LVM的使用空間。


Location and Time Zone selection頁面

Country:輸入Taiwan

Time zone:選擇Asia/Taipei

Keyboard Layout:選擇U.S. English


Administration Password and E-Mail頁面

Password:輸入root帳號的密碼,至少要五個字元。Proxmox建議密碼長度最少為12~14個字元,並且包含大小寫字母、數字及符號。

Confirm:再輸入一次並確認root帳號的密碼。

E-Mail:設定可以接收警告訊息的E-Mail帳號。


Management Network Configuration頁面

所有的訊息都會自動帶出,但可根據自己的需求設定

Management Interface:選擇管理用的網卡

HostnameFQDN):輸入主機的FQDN名稱

IP Address:輸入主機的IP位址

Netmask:輸入主機的網路遮罩

Gateway:輸入主機的匣道器

DNS Server:輸入主機的DNS伺服器

接者就等Proxmox安裝完成

完成後重新開機

接著在使用者端電腦上,打開瀏覽器,並輸入https://<ip_address>:8006

開啟Proxmox的管理介面會要求輸入帳號密碼,只要把一開始安裝時的密碼輸入即可,在這同時也可以設定管理介面的語系









2019年1月17日 星期四

在 CentOS 7 上安裝 PHP 7.3


新增Remi repository
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install epel-release yum-utils
開啟PHP 7.3
yum-config-manager --enable remi-php73
安裝PHP 7.3

yum install php

驗證

php -v

安裝PHP 7.3擴充功能

yum install php-<extension-name>

例如:php-mysql


                                                                                                                                                                                                   



參考資料:

How to Install PHP 7.3 on CentOS 7 / Fedora

CentOS 7 安裝 PHP 7.3

2019年1月11日 星期五

2019年1月3日 星期四

MariaDB 10.1.x 升級到 MariaDB 10.3.x


備份my.cnf

mv /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.old

編輯Repository

vi /etc/yum.repo.d/Mariadb.repo

baseurl = https://yum.mariadb.org/10.1/centos7-amd64
改成
baseurl = https://yum.mariadb.org/10.3/centos7-amd64

停用MariaDB

systemctl stop mariadb

移除舊的MariaDB

yum remove mariadb-server

更新套件

yum update

安裝新的MariaDB

yum install mariadb-server

啟動MariaDB服務

systemctl start mariadb

檢查Tabe與現有的資料庫版本是否匹配,並嘗試修復所有發現的問題

mysql_upgrade -u root

驗證

mysql –V

還原my.cnf

mv /etc/my.cnf.d/server.cnf.old /etc/my.cnf.d/server.cnf






在 Kali Linux 上安裝 OpenVAS


硬體:樹莓派2
Kali Linux官方網站下載樹莓派的映像檔,並燒錄至SD卡,接著把SD卡放到樹莓派中接上電源,這樣就完成了Kali Linux的安裝
安裝完作業系統後的第一步,就是把所有套件都更新
apt-get update
apt-get upgrade
apt-get dist-upgrade
升級套件後,可用下列指令清除cache或是舊套件
apt-get autoclean
apt-get autoremove
預設的時區是UTC,所以要先修改成自己當地的時區,操作步驟請參考這篇
安裝OpenVAS
apt-get install openvas
設定OpenVAS
openvas-setup
備註:這部份會安裝非常久,外出吃個飯回來都還在裝,請妥善安排時間。
設定完後,系統會自動開啟網頁
2019-01-04_112815
點選Advanced –> Add Exception
2019-01-04_112829
點選Confirm Security Exception
2019-01-04_112853
輸入UsernamePassword
預設的Usernameadmin
預設的Password則是在剛才執行openvas-setup之後的最後一行,請參閱下圖
2019-01-04_112118
重新設定密碼
取得現在的使用者帳號
openvasmd --get-users
指定使用者帳號及密碼(以admin帳號為例)
openvasmd --user=admin --new-password=<your_password>
也可以新建一個使用者帳號
openvasmd --create-user=<your_username>
當然也可以用剛才系統產生的那個非常難記的密碼登入OpenVAS後,再透過系統裡面的設定變更密碼或新增使用者










2019年1月2日 星期三

Ubuntu 變更時區


執行下列指令

sudo dpkg-reconfigure tzdata

選擇自己所屬的地區,這裡我是選擇Asia/Taipei

可透過timedatectl指令查看時區及時間是否正確