轉到正文

老夫的胡說八道

公車照片,政治亂談,資訊技術分享及其它雜七雜八

彙整

標籤: 鳥哥

安裝MRTG其實花了我不少時間去摸索,因為網路太多資訊跟現在版本有差異.
參考:鳥哥
鳥哥討論區
工頭的家
資安論壇
Steven’s Linux Note – Articles
—————————————以下開始—————————————————
檢查各種必須的套件有無安裝
———————————————————————-
rpm -qa | grep perl
rpm -qa | grep zlib
rpm -qa | grep gd
rpm -qa | grep libpng
rpm -qa | grep net-snmp #鳥哥上介紹的ucd-snmp已無人用,改用此套
rpm -qa | grep mrtg
———————————————————————-
#先下指令重新安裝以上套件吧
———————————————————————-
yum -y install gcc perl gd libpng zilb
———————————————————————-
#net-snmp因為沒有裝,因此去下載,我是下載需重新編譯的版本,其實也比較好,因為重新編譯它會以現在環境去做調整
#net-snmp 可由 http://www.net-snmp.org/download.html 下載
#下載至/tmp裡
cd /tmp
tar zxvf net-snmp-5.5.tar.gz #解壓縮
cd net-snmp-5.5
./configure –prefix=/usr/local/net-snmp #設定 net-snmp 安裝路徑
會出現以下網址裡的畫面,請依此修改
http://www.l-penguin.idv.tw/article/snmp_mrtg.htm
make
make install #開始安裝
cd /usr/local/net-snmp/
./bin/snmpconf -i
以下為 snmpconf 的設定過程,請依此修改
http://www.l-penguin.idv.tw/article/snmp_mrtg.htm
/usr/local/net-snmp/sbin/snmpd #啟動
netstat -ntulp | grep :161 #監看是有有啟動
/usr/local/net-snmp/bin/snmpwalk -v 2c -c public 192.168.0.251 #使用 snmpwalk 開始對 snmp 要求取出偵測字串
/usr/local/net-snmp/bin/snmpwalk -v 2c -c public 192.168.0.249 #使用 snmpwalk 開始對 snmp 要求取出偵測字串
netstat -ntulp | grep mrtg #監看mrtg服務
locate mrtg #看mrtg安裝至哪個目錄
cd /opt
#未裝mrtg請用以下指令抓
————————————————————————-
wget wget http://mrtg.cs.pu.edu.tw/pub/mrtg.tar.gz
————————————————————————-
–2010-03-31 17:04:15– http://wget/
正在查找主機 wget… 失敗: 未知的名稱或服務。
wget: unable to resolve host address `wget’
–2010-03-31 17:04:15– http://mrtg.cs.pu.edu.tw/pub/mrtg.tar.gz
正在查找主機 mrtg.cs.pu.edu.tw… 140.128.9.18
正在連接 mrtg.cs.pu.edu.tw|140.128.9.18|:80… 連上了。
已送出 HTTP 要求,正在等候回應… 200 OK
長度: 1082444 (1.0M) [application/x-gzip]
Saving to: `mrtg.tar.gz.1′

100%[========================================================================================================================================>] 1,082,444 5.05M/s in 0.2s

2010-03-31 17:04:20 (5.05 MB/s) — 已儲存 ‘mrtg.tar.gz.1’ [1082444/1082444])

FINISHED –2010-03-31 17:04:20–
Downloaded: 1 files, 1.0M in 0.2s (5.05 MB/s)
————————————————————————————–

cd mrtg-2.16.3/
./configure –prefix=/usr/local/mrtg
make
make install
——————————————————
/usr/local/mrtg/bin/cfgmaker –output=/var/www/mrtg/192.168.0.249-net.mrtg.cfg public@192.168.0.249
/usr/local/mrtg/bin/cfgmaker –output=/var/www/mrtg/192.168.0.251-net.mrtg.cfg public@192.168.0.251
#以上兩行是將cfgmaker加到Apache的安裝目錄下的mrtg
——————————————————-
vi /var/www/mrtg/192.168.0.249-net.mrtg.cfg 請依照以下修改
———————————————————————–
# Created by
# /usr/local/mrtg/bin/cfgmaker –output=/var/www/mrtg/192.168.0.249-net.mrtg.cfg public@192.168.0.249

### Global Config Options

# for UNIX
WorkDir: /var/www/mrtg
Refresh: 300
Interval: 5
Language: big5
Options[_]: growright
# or for NT
# WorkDir: c:\mrtgdata

### Global Defaults

# to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits

EnableIPv6: no
…………………………………以下省略………………………………
—————————————————————————-
#mrtg 執行時會參考先前所紀錄的數值,因為第一次沒有可以參考的數值,所以會有錯誤參生,此時請再重覆執行二、三次之後,錯誤就不會出現了。

env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/192.168.0.249-net.mrtg.cfg
env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/192.168.0.251-net.mrtg.cfg
—————————————————————————–

#產生MRTG首頁
—————————————————————————–
/usr/local/mrtg/bin/indexmaker –output=/var/www/mrtg/index.html /var/www/mrtg/192.168.0.249-net.mrtg.cfg /var/www/mrtg/192.168.0.251-net.mrtg.cfg
—————————————————————————–

#設定每5分鐘更新,鳥哥及很多的教學都是舊版設定,新版有變動,否則會向我覺得很奇怪為什麼都沒更新.
#舊版設定如下
——————————————————————————
crontab -e
*/5 * * * * (LANG=C /usr/local/mrtg/bin/mrtg /application/apps/traffic/mrtg/192.168.1.131-net.mrtg.cfg) > /dev/null 2>&1
——————————————————————————

#新版的設定如下
——————————————————————————
vi /etc/cron.d/mrtg
——————————
*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg –lock-file /var/lock/mrtg/mrtg_l –confcache-file /var/lib/mrtg/mrtg.ok
*/5 * * * * root (env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/192.168.0.249-net.mrtg.cfg) > /dev/null 2>&1
*/5 * * * * root (env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/192.168.0.251-net.mrtg.cfg) > /dev/null 2>&1
#第一行我覺得不需刪除也沒關係
——————————

Apache部分也須注意
———————————————————–
vi /etc/httpd/conf/httpd.conf
————————————————————-修改以下部分—————-
DocumentRoot 『/var/www/html』
Directory 『/var/www/html』 #連同上面一行兩者目錄要一致
AddDefaultCharset big5 #編碼為big5
—————————————————————————————-
service httpd restart #重新啟動

#若是連進192.168.0.212/mrtg出現403Forbidden,請照以下步驟執行
vi /etc/httpd/conf.d/mrtg.conf 修改成以下部分
————————————————————
#
# This configuration file maps the mrtg output (generated daily)
# into the URL space. By default these results are only accessible
# from the local host.
#
Alias /mrtg /var/www/mrtg


Order deny,allow
# Deny from all
Allow from 192.168.0.*
Allow from ::1
# Allow from .example.com

——————————————————————–

#snmp啟動常駐
vi /etc/rc.d/rc.local #照以下修改
———————————————–
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don’t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/local/sbin/snmpd
————————————————

以192.168.0.212作修改

主要參考鳥哥Samba教學
國網中心 & 青草湖社區大學

————————————————————-以下開始——————————-
locate lmhosts
————————————————————-
/etc/samba/lmhosts
/usr/share/man/man5/lmhosts.5.gz
————————————————————-

vi /etc/samba/lmhosts #這步驟我覺得其實有無無所謂
————————————————————-
127.0.0.1 localhost
192.168.0.248 XXXXX #以下幾行是我多打的
192.168.0.247 XXXX
————————————————————-

vi /etc/samba/smb.conf #請修改成以下的設定
————————————————————-
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# For a step to step guide on installing, configuring and using samba,
# read the Samba-HOWTO-Collection. This may be obtained from:
# http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# Many working examples of smb.conf files can be found in the
# Samba-Guide which is generated daily and can be downloaded from:
# http://www.samba.org/samba/docs/Samba-Guide.pdf
#
# Any line which starts with a ; (semi-colon) or a # (hash)
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command 『testparm』
# to check that you have not made any basic syntactic errors.
#
#—————
# SELINUX NOTES:
#
# If you want to use the useradd/groupadd family of binaries please run:
# setsebool -P samba_domain_controller on
#
# If you want to share home directories via samba please run:
# setsebool -P samba_enable_home_dirs on
#
# If you create a new directory you want to share you should mark it as
# 『samba-share_t』 so that selinux will let you write into it.
# Make sure not to do that on system directories as they may already have
# been marked with othe SELinux labels.
#
# Use ls -ldZ /path to see which context a directory has
#
# Set labels only on directories you created!
# To set a label use the following: chcon -t samba_share_t /path
#
# If you need to share a system created directory you can use one of the
# following (read-only/read-write):
# setsebool -P samba_export_all_ro on
# or
# setsebool -P samba_export_all_rw on
#
# If you want to run scripts (preexec/root prexec/print command/…) please
# put them into the /var/lib/samba/scripts directory so that smbd will be
# allowed to run them.
# Make sure you COPY them and not MOVE them so that the right SELinux context
# is applied, to check all is ok use restorecon -R -v /var/lib/samba/scripts
#
#————–
#
#======================= Global Settings =====================================

[global]
#client code page = 950 鳥哥的設定會有這行,可是現在版本不支援,會出現錯誤訊息,不用輸入.
encrypt passwords = yes
unix charset = utf8
display charset = utf8
dos charset = cp950
smb passwd file = /usr/bin/smbpasswd #此檔位置請用locate smbpasswd去找

# ———————– Network Related Options ————————-
#
# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
#
# server string is the equivalent of the NT Description field
#
# netbios name can be used to specify a server name not tied to the hostname
#
# Interfaces lets you configure Samba to use multiple interfaces
# If you have multiple network interfaces then you can list the ones
# you want to listen on (never omit localhost)
#
# Hosts Allow/Hosts Deny lets you restrict who can connect, and you can
# specifiy it as a per share option as well
#
workgroup = MSHOME #此行請依照自己M$的網路群組名設定
server string = Samba Server Version %v

; netbios name = BACKUPSERVER

; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
; hosts allow = 127. 192.168.0.93 192.168.0.248 192.168.0.247 #此行是限定只有哪幾台主機才能連

# ————————— Logging Options —————————–
#
# Log File let you specify where to put logs and how to split them up.
#
# Max Log Size let you specify the max size log files should reach

# logs split per machine
; log file = /var/log/samba/%m.log
# max 50KB per log file, then rotate
; max log size = 50

# ———————– Standalone Server Options ————————
#
# Security can be set to user, share(deprecated) or server(deprecated)
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.

security = user
passdb backend = tdbsam

# ———————– Domain Members Options ————————
#
# Security must be set to domain or ads
#
# Use the realm option only with security = ads
# Specifies the Active Directory realm the host is part of
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.
#
# Use password server option only with security = server or if you can’t
# use the DNS to locate Domain Controllers
# The argument list may include:
# password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]
# or to auto-locate the domain controller/s
# password server = *

; security = domain
; passdb backend = tdbsam
; realm = MY_REALM

; password server =

# ———————– Domain Controller Options ————————
#
# Security must be set to user for domain controllers
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.
#
# Domain Master specifies Samba to be the Domain Master Browser. This
# allows Samba to collate browse lists between subnets. Don’t use this
# if you already have a Windows NT domain controller doing this job
#
# Domain Logons let Samba be a domain logon server for Windows workstations.
#
# Logon Scrpit let yuou specify a script to be run at login time on the client
# You need to provide it in a share called NETLOGON
#
# Logon Path let you specify where user profiles are stored (UNC path)
#
# Various scripts can be used on a domain controller or stand-alone
# machine to add or delete corresponding unix accounts
#
; security = user
; passdb backend = tdbsam

; domain master = yes
; domain logons = yes

# the login script name depends on the machine name
; logon script = %m.bat
# the login script name depends on the unix user used
; logon script = %u.bat
; logon path = \\%L\Profiles\%u
# disables profiles support by specifing an empty path
; logon path =

; add user script = /usr/sbin/useradd 『%u』 -n -g users
; add group script = /usr/sbin/groupadd 『%g』
; add machine script = /usr/sbin/useradd -n -c 『Workstation (%u)』 -M -d /nohome -s /bin/false 『%u』
; delete user script = /usr/sbin/userdel 『%u』
; delete user from group script = /usr/sbin/userdel 『%u』 『%g』
; delete group script = /usr/sbin/groupdel 『%g』

# ———————– Browser Control Options —————————-
#
# set local master to no if you don’t want Samba to become a master
# browser on your network. Otherwise the normal election rules apply
#
# OS Level determines the precedence of this server in master browser
# elections. The default value should be reasonable
#
# Preferred Master causes Samba to force a local browser election on startup
# and gives it a slightly higher chance of winning the election
; local master = no
; os level = 33
; preferred master = yes

#—————————– Name Resolution ——————————-
# Windows Internet Name Serving Support Section:
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
#
# – WINS Support: Tells the NMBD component of Samba to enable it’s WINS Server
#
# – WINS Server: Tells the NMBD components of Samba to be a WINS Client
#
# – WINS Proxy: Tells Samba to answer name resolution queries on
# behalf of a non WINS capable client, for this to work there must be
# at least one WINS Server on the network. The default is NO.
#
# DNS Proxy – tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups.

; wins support = yes
; wins server = w.x.y.z
; wins proxy = yes

; dns proxy = yes

# ————————— Printing Options —————————–
#
# Load Printers let you load automatically the list of printers rather
# than setting them up individually
#
# Cups Options let you pass the cups libs custom options, setting it to raw
# for example will let you use drivers on your Windows clients
#
# Printcap Name let you specify an alternative printcap file
#
# You can choose a non default printing system using the Printing option

load printers = yes
cups options = raw

; printcap name = /etc/printcap
#obtain list of printers automatically on SystemV
; printcap name = lpstat
; printing = cups

# ————————— Filesystem Options —————————
#
# The following options can be uncommented if the filesystem supports
# Extended Attributes and they are enabled (usually by the mount option
# user_xattr). Thess options will let the admin store the DOS attributes
# in an EA and make samba not mess with the permission bits.
#
# Note: these options can also be set just per share, setting them in global
# makes them the default for all shares

; map archive = no
; map hidden = no
; map read only = no
; map system = no
; store dos attributes = yes

#============================ Share Definitions ==============================

#[home] 此部分疑似被我改壞,若是測試出現此folder warning,就到此行將此部分全部註解起來.
# comment = Home Directories
# browseable = no
# writable = yes
#; valid users = %S
#; valid users = MYDOMAIN\%S

[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes

[backup] #此folder照我要備份目錄增加
comment = backup
path = /backup
public = yes
browseable = yes
writable = yes
write list = +staff
# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
; comment = Network Logon Service
; path = /var/lib/samba/netlogon
; guest ok = yes
; writable = no
; share modes = no
此檔大部分都不變動
——————————————————————————–

testparm #測試是否可分享,正常不會出現warning
——————————————————————————-
Load smb config files from /etc/samba/smb.conf
Processing section 『[printers]』
Processing section 『[backup]』
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
dos charset = cp950
unix charset = utf8
display charset = utf8
workgroup = MSHOME
server string = Samba Server Version %v
smb passwd file = /usr/bin/smbpasswd
passdb backend = tdbsam
cups options = raw

[printers]
comment = All Printers
path = /var/spool/samba
printable = Yes
browseable = No

[backup]
comment = backup
path = /backup
write list = +staff
read only = No
guest ok = Yes
—————————————————————————

# Un-comment the following to provide a specific roving profile share
# the default is to use the user’s home directory
; [Profiles]
; path = /var/lib/samba/profiles
; browseable = no
; guest ok = yes

# A publicly accessible directory, but read only, except for people in
# the 『staff』 group
; [public] #這是預設的,不需改.
; comment = Public Stuff
; path = /home/samba
; public = yes
; writable = yes
; printable = no
; write list = +staff
—————————————————————————

chmod 700 /usr/bin/smbpasswd #將此檔改成可執行且只能由root修改
adduser -M administrator #先在系統裡增加使用者,使Samba可用, -M是不增加user的家目錄,另外,鳥哥的設定缺此一步驟,會發生smbpasswd -a administrator出現無法增加的錯誤,不知是否為版本問題.
會出現輸入密碼的提示,輸入完密碼後.

smbpasswd -a administrator #Samba裡增加使用者,一樣輸入密碼.
/etc/rc.d/init.d/smb restart #smb重新啟動
nmblookup MSHOME #找尋MSHOME裡有分享的電腦
接下來到192.168.0.248 開始->執行->\\192.168.0.212->Enter, 再輸入administrator及密碼後就可以看到了.
最好是做成網路磁碟機的方式.