code-test

2013年5月8日 星期三

【MySQL】變更root 密碼

MySQL Change root Password

【MySQL】MySQL root 密碼 Recover

Recover MySQL root Password

by NIXCRAFT on APRIL 18, 2006 · 249 COMMENTS· LAST UPDATED AUGUST 4, 2010

【Vyatta】netflow 設定

 

vyatta@R1:~$ configure
vyatta@R1# set system flow-accounting netflow version 5
vyatta@R1# set system flow-accounting netflow server 192.168.5.97
vyatta@R1# set system flow-accounting netflow server 192.168.5.97 port 2055
vyatta@R1# commit

vyatta@R1# save

查看 netflow 是否正常

vyatta@R1:~$ show flow-accounting interface eth0
flow-accounting for [eth0]
Src Addr        Dst Addr        Sport Dport Proto    Packets      Bytes   Flows
10.1.0.14       224.0.0.18      0     0      vrrp        233       9320       1
69.59.150.135   10.1.0.90       123   123     udp         12        912       2
76.74.103.45    10.1.0.90       0     0      icmp          2        168       1
10.0.0.30       10.1.0.90       53    40089   udp          1        133       1
10.0.0.30       10.1.0.90       53    36641   udp          1        133       1
10.0.0.30       10.1.0.90       53    51363   udp          1        106       1

Total entries: 6
Total flows  : 7
Total pkts   : 250
Total bytes  : 10,772

打完收工

2013年5月7日 星期二

[VMWare] vmware 使用的port

VMware vCenter Server 系統必須能夠將資料發送到每個受管主機,並且從每個 vSphere Client 接收資料。對於受管主機間的遷移和置備活動,源主機和目標主機必須能夠彼此接收資料。
 
有關 Windows 上的 vCenter Server 所需埠的資訊,請參見vCenter Server 所需的埠。
VMware 使用指定的埠進行通信。此外,受管主機將在指定的埠上監控來自於 vCenter Server 系統的資料。vCenter Server Appliance 已進行了預配置,以使用在vCenter Server Appliance 所需的埠中列出的埠。對於自訂防火牆,必須手動打開所需埠。如果在兩台受管主機之間有防火牆,並且您要在源主機或目標主機上執行活動,例如遷移或克隆,則必須配置一種方式,以便受管主機接收資料。
443 port902 port,443 port主要負責資料訊息的傳遞,而902 port主要負責遠端console畫面的傳遞
vCenter Server Appliance 所需的埠
描述
80 vCenter Server 需要埠 80 用於直接 HTTP 連接。埠 80 會將請求重定向到 HTTPS 埠 443。如果意外使用了 http://server 而不是 https://server,此重定向將非常有用。
443 vCenter Server 系統用於偵聽來自 vSphere Client 的連接的默認埠。要使 vCenter Server 從 vSphere Client 接收資料,請在防火牆中打開 443 埠。
vCenter Server 系統還使用埠 443 監控從 SDK 用戶端傳輸的資料。
如果對 HTTPS 使用另一個埠號,則登錄 vCenter Server 系統時必須使用ip-address:port。
902 vCenter Server 系統用於將資料發送到受管主機的預設埠。受管主機也會通過 UDP 埠 902 定期向 vCenter Server 系統發送檢測信號。伺服器和主機之間或各個主機之間的防火牆不得阻止此埠。
不得在 vSphere Client 和主機之間阻塞埠 902。vSphere Client 使用此埠顯示虛擬機器控制台。
8080 Web 服務 HTTP。用於 VMware VirtualCenter Management WebServices。
8443 Web 服務 HTTPS。用於 VMware VirtualCenter Management WebServices。
10080 vCenter Inventory Service HTTP。
10443 vCenter Inventory Service HTTPS。
10109 vCenter Inventory Service 資料庫。
514 vSphere Syslog Collector 伺服器。
1514 vSphere Syslog Collector 伺服器 (SSL)。
6500 網路 coredump 伺服器 (UDP)。
6501 Auto Deploy 服務。
6502 Auto Deploy 管理。
9090 vSphere Web Client HTTP。
9443 vSphere Web Client HTTPS。
5480 vCenter Server Appliance Web 使用者介面 HTTPS。
5489 vCenter Server Appliance Web 使用者介面 CIM 服務。
22 SSHD 的系統埠。

[Freebsd] DNS架設

Chapter 2 DNS 架設 - 使用 bind 9-9.3. 4.1

Chapter 2-1  安裝 Bind 9-9.2.

實際上的應用,若所有的Services都在一台Server上,是不需要有特定一台的DNS Server的,在此僅以模擬其他Service是在Test Host上為主。(使用BIND 9.X之優點:多執行緒多CPU的支援、多了A6 offset的功能、反解有三種方法,簡單且對IPv6的特性更容易處理、支援多種不同資料庫等等)。

安裝Bind 9-9.2.2以上:

# cd /usr/ports/dns/bind99

make

make install clean

設定 forwarders

forwarders {
        //127.0.0.1;
    168.95.1.1;
};

設定 zone file

 

zone "testlab.com.tw" { // 宣告網域名稱
        type master;
        file "zone.fwd.testlab";
};

// [Rev] 反解網域設定區,
// 宣告反解的IP區段,Class C。
zone "0.1.168.192.in-addr.arpa" {
        type master;
        file "zone.rev";
};

內容為:

更新 /etc/rc.conf檔案

Command: vi /etc/rc.conf

Context:

named_enable="YES" //加入

完成以上步驟後,啟動DNS

Command: /etc/rc.d/named start

2013年5月2日 星期四

【FreeBSD】網路流量統計 RRDTool + Cacti 統計

 

     

RRDtool 是原 MRTG 作者另外開發的套件,它可將系統吐出來的資料做 logging 並繪製成圖表

而系統所吐出來的資料是 based on SNMP ( Simple Network Management Protocol ),所以只要是支援 SNMP 的設備都可以用 RRDtool 來做記錄與分析

不過仔細看了一下 RRDtool 操作的語法算小複雜,因此本篇教學會再搭配 Cacti 來協助控制 RRDtool 繪製報表

我的安裝環境如下

[ 安裝所需套件 ]

首先我們先安裝 RRDtool

# cd /usr/ports/databases/rrdtool
# make install clean

pkg_add -r gobject-introspection

接下來安裝 Net-SNMP

# cd /usr/ports/net-mgmt/net-snmp
# make install clean

[ ] AX_SOCKONLY

[ ] DMALLOC

不選

3 安裝 Cacti

# cd /usr/ports/net-mgmt/cacti
# make install clean

=======================================================================
Cacti is now installed. If you intall it for the first time,
you may have to follow this steps to make it work correctly:

1. Create the MySQL database:
# mysqladmin --user=root create cacti
2. Create a mysql user/password for cacti:
   (change user and/or password if required)
# echo "GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'; FLUSH PRIVILEGES;" | mysql
3. Import the default cacti database:
# mysql cacti < /usr/local/share/cacti/cacti.sql
4. Edit /usr/local/share/cacti/include/config.php.
5. Add the line to cron jobs with the command:
# crontab -u cacti -e
*/5 * * * * /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1
6. Add alias in apache config for the cacti dir:
Alias /cacti "/usr/local/share/cacti/"
7. Be sure apache gives an access to the directory ('Allow from' keywords).
8. Open a cacti login page in your web browser and login with admin/admin.

If you update cacti, open a login page, an updating process
will start automatically.
=======================================================================

上述三個套件安裝完之後,就可以開始來設定囉!

[ 設定 SNMP ]

首先先來設定 SNMP 的部份

# cd /usr/local/share/snmp
# vi snmpd.conf

snmpd.conf 內容如下

rocommunity public  // 設定 SNMP Read-Only 的 Community
syslocation MyOffice-at-work  // 系統所在地
syscontact oscarxxx.xxx@gmail.com  // 管理者 E-mail

rocommunity public
syslocation MyOffice-at-work
syscontact oscarxxx.xxx@gmail.com

另外請在 /etc/rc.conf 加入一行 snmpd_enable="YES"

# echo snmpd_enable=”yes” >> /etc/rc.conf

加好了之後就來啟動 SNMP 吧

# /usr/local/etc/rc.d/snmpd start

[ 設定 Cacti ]

設定 Cacti 這部份看個人習慣,如果您已經有 phpMyAdmin 的話可以在裡面操作,或是透過指令方式來新建

原則上我們需要新建一個 Database、User 讓 Cacti 可以存放相關資料

指令操作如下,新增一個 Database 名稱為 cacti

# mysqladmin -u root -p create cacti
Enter password: 輸入 Root 的密碼

新增一個 User 名叫 cacti 讓它可以存取 cacti 這個 Database,密碼設定為 cactiuser

[root@fb91-lab /usr/ports/net-mgmt/cacti]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'cactiuser';
Query OK, 0 rows affected (0.02 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

接下來我們要倒入 Database 相關的 Schema

# mysql -u cacti -p cacti < /usr/local/share/cacti/cacti.sql
Enter password: 以本教學為例輸入 justforcacti

Database 的 Schema 建好之後,接下來我們來去設定程式的部份

# cd /usr/local/share/cacti/include/
# vi /usr/local/share/cacti/include/config.php

config.php 內容如下,原則上要改的地方就只有 username 跟 password 而已

/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cactiuser";
$database_port = "3306";
/* Default session name - Session name must contain alpha characters */
#$cacti_session_name = "Cacti";

接下來新增排程設定,固定每 5 分鐘讓 Cacti 去取得資料

# crontab -u cacti -e

加入這一行即可

*/5 * * * * /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1

接下來我們要在 Apache 裡面設定 Cacti 的路徑

# vi /usr/local/etc/apache22/httpd.conf

在 httpd.conf 加入下面這幾行

Alias /cacti "/usr/local/share/cacti/"
<Directory "/usr/local/share/cacti/">
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

/usr/local/share/cacti/

Allow from 127.0.0.1 192.168.0.0/16 .example.comss

好了之後要重新啟動 Apache 讓它生效

# /usr/local/etc/rc.d/apache22 restart

[ 初始化 Cacti ]

網址列請打入 http://您的 IP or Domain/cacti

FreeBSD 中文字型

# cd /usr/ports/chinese/font-std
# make install clean

Cacti 還有一些外掛 可以使用

FreeBSD 安裝 phpmyadmin

 

安裝完FAMP後 接下來使用網頁管理 mysql 的部分 所以通常我的都是使用 phpmyadmin來做管理

 

# cd /usr/ports/databases/phpmyadmin/

# vmake install clean

 

****************************************************************************

===> Adjusting file ownership in /usr/local/www/phpMyAdmin

phpMyAdmin-suphp-3.5.3 has been installed into:

    /usr/local/www/phpMyAdmin

Please edit config.inc.php to suit your needs.

To make phpMyAdmin available through your web site, I suggest
that you add something like the following to httpd.conf:

    Alias /phpmyadmin/ "/usr/local/www/phpMyAdmin/"

    <Directory "/usr/local/www/phpMyAdmin/">
        Options none
        AllowOverride Limit

        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1 192.168.0.0/16 .example.com
    </Directory>

****************************************************************************

修改apache 設定檔

# vi /usr/local/etc/apache22/httpd.conf

Alias /phpmyadmin/ "/usr/local/www/phpMyAdmin/"

<Directory "/usr/local/www/phpMyAdmin/">
Options none
AllowOverride Limit

Order Deny,Allow
Deny from all
Allow from 127.0.0.1 192.168.0.0/16 .example.com
</Directory>

重新啟動 apache22

/usr/local/etc/rc.d/apache22 restart

連接你的主機

http://your.ip.address/phpmyadmin

打開網頁 就可以看到管理程式頁面

[雜記]更新

 

這個部落格擱置很久了 希望現在開始可以持續更新

Vyatta router 設定 DNS

 

利用 vyatta router 做簡單的DNS 設定


建立 record
set system static-host-mapping host-name mail.internal.lan
set system static-host-mapping host-name mail.internal.lan inet 192.168.1.250

刪除 record
delete system static-host-mapping host-name mail.internal.lan
delete system static-host-mapping host-name mail.internal.lan inet 192.168.1.250

這樣就可以解析出 mail.internal.lan 這個名稱

【FreeBSD9.1】用 Ports 安裝 Apache + PHP + MySQL

===================================
1. 安裝 MySQL
===================================
# cd /usr/ports/databases/mysql55-server
# make install clean
安裝好之後
複製 MySQL 的系統設定檔到 /etc 下
# cp /usr/local/share/mysql/my-midden.cnf /etc/my.cnf
設定 MySQL 資料庫權限,並且啟動它
# chown -R mysql:mysql /var/db/mysql
# echo “mysql_enable=yes” >> /etc/rc.conf
# /usr/local/etc/rc.d/mysql-server start

設定 MySQL Root 的密碼
# mysqladmin -u root password 新密碼

最後我們可以測試登入一下 MySQL,有出現以下畫面就 OK
# mysql -u root -p
Enter password: (請輸入密碼)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.60-log FreeBSD port: mysql-server-5.1.60
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Mysql 安裝完成

===================================
2. 安裝 Apache
===================================
# cd /usr/ports/www/apache22
# make install clean
===================================
3. 安裝 PHP
===================================
# cd /usr/ports/lang/php5
# make config install clean
記得要勾選此選項喔,不然 Apache 會不認得 PHP
APACHE     Build Apache module
再安裝 PHP Extensions
# cd /usr/ports/lang/php5-extensions
# make config install clean
建議加勾選 GD、MYSQL、MySQLI、MBSTRING、ZIP 和 ZLIB
===================================
4. 修改設定檔
===================================
首先設定 PHP 的設定檔,以後就是設定 php.ini 這檔
# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
修改 Apache 的設定
# vi /usr/local/etc/apache22/httpd.conf
在最上面加入
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
找到
DirectoryIndex index.html
把它變成
DirectoryIndex index.php index.html index.htm
設定一開機啟動 Apache & MySQL
# vi /etc/rc.conf
加入這三行
apache22_enable="YES"
apache22_http_accept_enable="YES"
mysql_enable="YES"
在 /usr/local/www/apache22/data 裡新增一個檔案叫 index.php,內容如下
<?php phpinfo(); ?>
重開機,大功告成!

Freebsd91-安裝 mysql+apache+php+phpmyadmin