新聞中心
在Linux系統(tǒng)中,使用機(jī)器名是非常重要的一件事情,在網(wǎng)絡(luò)環(huán)境中可以通過(guò)機(jī)器名來(lái)識(shí)別不同的主機(jī),也可以方便地進(jìn)行文件共享和遠(yuǎn)程訪問(wèn)等操作。但是,一些Linux系統(tǒng)在安裝時(shí)并沒(méi)有為用戶分配一個(gè)默認(rèn)的機(jī)器名,造成一些不必要的困擾。因此,在使用Linux系統(tǒng)時(shí),添加機(jī)器名是必須的一步。

華龍網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)公司!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)公司成立與2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)公司。
本文將介紹,包括以下幾個(gè)方面:
1. 查看當(dāng)前機(jī)器名
2. 修改 /etc/hostname 文件
3. 更新 /etc/hosts 文件
4. 重啟 Linux 系統(tǒng)
1. 查看當(dāng)前機(jī)器名
我們需要確定當(dāng)前系統(tǒng)正在使用的機(jī)器名,可以通過(guò)打開(kāi)終端并使用以下命令來(lái)查看:
“`
hostnamectl
“`
該命令將顯示當(dāng)前正在使用的機(jī)器名。
2. 修改 /etc/hostname 文件
接下來(lái),我們需要編輯 /etc/hostname 文件以添加新的機(jī)器名。該文件存儲(chǔ)了系統(tǒng)當(dāng)前正在使用的機(jī)器名,通過(guò)以下命令打開(kāi)該文件進(jìn)行編輯:
“`
sudo nano /etc/hostname
“`
在該文件中,可以找到當(dāng)前正在使用的機(jī)器名,并用新的機(jī)器名替換它。替換后,保存并關(guān)閉文件。
3. 更新 /etc/hosts 文件
確保你在 /etc/hosts 文件中將舊的機(jī)器名都更新為新的機(jī)器名。打開(kāi)該文件以進(jìn)行編輯:
“`
sudo nano /etc/hosts
“`
在該文件中,可以找到一些與機(jī)器名相關(guān)的行。確保將這些行上的舊機(jī)器名都替換為新機(jī)器名,并且保存并關(guān)閉文件。
4. 重啟 Linux 系統(tǒng)
要想新機(jī)器名生效,需要重新啟動(dòng) Linux 系統(tǒng)。使用以下命令重啟系統(tǒng):
“`
sudo reboot
“`
重啟后,你就可以看到新的機(jī)器名正在使用。
在Linux系統(tǒng)中,添加機(jī)器名是非常重要的一步,能夠方便地進(jìn)行文件共享和遠(yuǎn)程訪問(wèn)等操作。在本文中,我們介紹了如何在Linux中添加新的機(jī)器名。具體來(lái)說(shuō),包括查看當(dāng)前機(jī)器名、修改 /etc/hostname 文件、更新 /etc/hosts 文件和重啟系統(tǒng)等步驟。如果你正在使用Linux系統(tǒng)并需要添加新的機(jī)器名,可以根據(jù)上述步驟來(lái)進(jìn)行操作。
相關(guān)問(wèn)題拓展閱讀:
- 虛擬機(jī)Linux上部署DB2pureScale過(guò)程
- 修改linux的網(wǎng)絡(luò)配置方式有哪些?步驟?
虛擬機(jī)Linux上部署DB2pureScale過(guò)程
在Linux 操作系統(tǒng) 中,可在虛擬機(jī)上搭建DB2 pureScale,那么搭建的步驟是怎么樣的呢?DB2 pureScale又有什么用呢?下面隨我一起來(lái)了解下Linux系統(tǒng)如何在虛擬機(jī)上部署DB2 pureScale。
在虛擬機(jī)Linux上部署DB2pureScale實(shí)踐過(guò)程
、環(huán)境準(zhǔn)備
硬件環(huán)境:3 臺(tái) x86-64虛擬機(jī),內(nèi)存要求 1.5G 或以上(主要針對(duì)虛擬機(jī),內(nèi)存過(guò)低會(huì)造成數(shù)據(jù)庫(kù)實(shí)例啟動(dòng)失敗)
操作系統(tǒng):Suse Linux Enterprise Server 11.3
DB2 版本:DB2 v10.5
機(jī)器名:node01 node02 node03
IP:192.168.18..168.18..168.18.203
網(wǎng)關(guān):192.168.18.2
利用iscsi服務(wù)來(lái)做共享存儲(chǔ)功能,其中node01 作為 iscsi 的 Server,node01、node02和 node03 作為 iscsi Client,這樣三臺(tái)虛擬機(jī)上都能看到相同的磁盤(pán)了(按照developer workers上的 文章 :非 InfiniBand 環(huán)境下搭建 DB2 pureScale,我用DB2 v10.5時(shí)啟動(dòng)實(shí)例失敗,可能10.5做了限制,CF與member在同一臺(tái)機(jī)器啟動(dòng)失敗,幫多了一臺(tái)虛擬機(jī))。
、操作系統(tǒng)安裝:
Node01預(yù)留出一塊分區(qū),不進(jìn)行格式化(文件類型為0x83 Linux)做為 pureScale 集群的 Sharing Disk 使用,Node02與Node03跟node01 其帆戚它 相同就可,
安裝必要的包:
libstdc++(32 位和 64 位庫(kù))
glibc(32 位和 64 位庫(kù))
cpp
差轎手gcc
gcc-c++
kernel-source
binutils
ksh-93u-0.8.1
openssh
ntp
完成SUSE 11 SP3的安裝。
驗(yàn)證:檢查/lib/modules/3.0.76-0.11-default/build/include/linux有無(wú)autoconf.h,如果沒(méi)有autoconf.h,安裝DB2時(shí)會(huì)報(bào)Compiling GPL :…….Failure錯(cuò)誤。
解決 方法 :cp –v /usr/src/linux-3.0.76-0.11-obj/x86_64/default/include/generated /lib/modules/3.0.76-0.11-default/build/include/linux
、添加用戶和用戶組
三臺(tái)機(jī)器全部執(zhí)行如下命令(如果虛嫌不做特殊說(shuō)明,以#表示root身份登錄,以$表示db2inst1身份,以下相同)。
#groupadd -g 1001 db2fadm1
#groupadd -g 1002 db2iadm1
#useradd -g db2fadm1 -um -d /home/db2fenc1 -p db2fenc1 db2fenc1
#useradd -g db2iadm1 -um -d /home/db2inst1 -p db2inst1 db2inst1
#mkdir /root/.ssh
# su – db2inst1 -c “mkdir -p /home/db2inst1/.ssh”
、配置ssh 信任連接
ssh信任通俗的說(shuō)就是直接ssh不用輸入密碼
在/etc/hosts添加另外兩臺(tái)機(jī)器的IP地址及機(jī)器名(確保3臺(tái)機(jī)器名與ip地址全部出現(xiàn)在hosts文件中)
例如我的機(jī)器hosts如下:
.0.0.1 localhost
.168.18.201 node01.site node01
.168.18.202 node02.site node02
.168.18.203 node03.site node03
node01執(zhí)行如下命令:
#ssh-keygen -t rsa
#cp -v /root/.ssh/id_rsa.pub /root/.ssh/id01
#scp /root/.ssh/id01 node02:/root/.ssh
#scp /root/.ssh/id01 node03:/root/.ssh
#su – db2inst1
$ssh-keygen -t rsa
$cp -v /home/db2inst1/.ssh/id_rsa.pub /home/db2inst1/.ssh/id01
$scp /home/db2inst1/.ssh/id01 node02:/home/db2inst1/.ssh
$scp /home/db2inst1/.ssh/id01 node03:/home/db2inst1/.ssh
node02執(zhí)行如下命令:
#ssh-keygen -t rsa
#cp -v /root/.ssh/id_rsa.pub /root/.ssh/id02
#scp /root/.ssh/id02 node01:/root/.ssh/
#scp /root/.ssh/id02 node03:/root/.ssh/
#su – db2inst1
$ssh-keygen -t rsa
$cp -v /home/db2inst1/.ssh/id_rsa.pub /home/db2inst1/.ssh/id02
$scp /home/db2inst1/.ssh/id02 node01:/home/db2inst1/.ssh/
$scp /home/db2inst1/.ssh/id02 node03:/home/db2inst1/.ssh/
node03執(zhí)行如下命令:
#ssh-keygen -t rsa
#cp -v /root/.ssh/id_rsa.pub /root/.ssh/id03
#scp /root/.ssh/id03 node01:/root/.ssh
#scp /root/.ssh/id03 node02:/root/.ssh
#su – db2inst1
$ssh-keygen -t rsa
$cp -v /home/db2inst1/.ssh/id_rsa.pub /home/db2inst1/.ssh/id03
$scp /home/db2inst1/.ssh/id03 node01:/home/db2inst1/.ssh/
$scp /home/db2inst1/.ssh/id03 node02:/home/db2inst1/.ssh/
分別在node01、node02、node03執(zhí)行如下命令
#cd /root/.ssh
#cat id01 id02 id03 > authorized_keys
#chmod 600 authorized_keys
#su – db2inst1
$cd /home/db2inst1/.ssh
$ cat id01 id02 id03 > authorized_keys
測(cè)試是否配置成功
臺(tái)機(jī)器分別以root與db2inst1執(zhí)行:
#ssh node01 ls
#ssh node02 ls
#ssh node03 ls
#su – db2inst1
$ssh node01 ls
$ssh node02 ls
$ssh node03 ls
確保不用輸入密碼,則配置成功。
、ISCSI 共享存儲(chǔ)配置
Iscsi server端配置(node01上執(zhí)行):
修改/etc/ietd.conf,添加如下內(nèi)容:
Target iqn..node01.site:scsidisk01
Lun 0 Path=/dev/sda4,Type=fileio
注意:我的未分區(qū)硬盤(pán)為/dev/sda4,你的可能不一樣的@_@~~~~
添加自啟動(dòng)
#chkconfig -a iscsitarget
檢查是否成功
#chkconfig -l iscsitarget
結(jié)果:iscsitarget 0:off 1:off 2:off 3:on 4:off 5:on 6:off
重啟iscsitarget服務(wù)
# /etc/init.d/iscsitarget restart
iscsi client端配置(node01、node02、node03執(zhí)行,):
iscsitarget文件內(nèi)容如下:
#! /bin/sh
### BEGIN INIT INFO
# Provides: iscsiclsetup
#node02與node03上如果未裝iscsitarget需將下下行的$iscsitarget
# Required-Start: $network $syslog $iscsitarget $remote_fs artd
# Required-Stop:
# Default-Start: 3 5
# Default-Stop:
# Description: ISCSI client setup
### END INIT INFO
case “$1” in start)
iscsiadm –mode discoverydb –type sendtargets –portal 192.168.18.201 –discover
iscsiadm –m node –targetname iqn..node01.site:scsidisk01 –portal 192.168.18.201:login
;;
stop)
iscsiadm -m node -T iqn..node01.site:scsidisk01 -p 192.168.18.201 –logout
;;
restart) ## Stop the service and regardless of whether it was ## running or not, start it again.
$0 stop
$0 start
;;
*)
Esac
保存后執(zhí)行:#/etc/init.d/iscsiclient restart
驗(yàn)證iscsiclient是否啟動(dòng)成功:
#fdisk -l
檢查有無(wú)/dev/sdb出現(xiàn)
、配置Linux環(huán)境變量
/etc/profie.local添加內(nèi)容
alias sl=’tail -f /var/log/messages’
alias fc=’fcslogrpt /var/log/messages’
export PATH=/root/bin:/usr/in/rsct/bin:/opt/ibm/db2/v10.5/bin:$PATH
export PATH=/usr/lpp/mmfs/bin:$PATH
export DB2USENONIB=TRUE
export DB2_CFS_GPFS_NO_REFRESH_DATA=true
然后執(zhí)行# . /etc/profile.local,完成后你就可以安裝purescale了,我猜測(cè)應(yīng)該是設(shè)置了變量DB2USENONIB,使purescale不再要求你強(qiáng)制InfiniBand或萬(wàn)兆網(wǎng)卡,使我等窮人可以有機(jī)會(huì)玩這種高檔、洋氣、上檔次的數(shù)據(jù)庫(kù)。。。
、DB2 V10.5 的安裝:
node01:~/server_t # ./db2_install
DBI1324W Support of the db2_install command is deprecated. For
more information, see the DB2 Information Center.
Default directory for installation of products – /opt/ibm/db2/V10.5
***********************************************************
Install into default directory (/opt/ibm/db2/V10.5) ?
yes
Specify one of the following keywords to install DB2 products.
SERVER
CONSV
EXP
CLIENT
RTCL
Enter “help” to redisplay product names.
Enter “quit” to exit.
***********************************************************
server
***********************************************************
Do you want to install the DB2 pureScale Feature?
Yes
曾經(jīng)出現(xiàn)的錯(cuò)誤:
ERROR: An error occurred while compiling IBM General Parallel File System
(GPFS) Portability Layer (GPL) on host “node01”. Return code “2”. GPL
compilation log file location “/tmp/compileGPL.log.000”. The GPFS file system
cannot be mounted properly until the GPL module is successfully compiled on
this host. For details, see the specified GPL compilation log. After fixing
the problems shown in the log file, re-run the DB2 installer. For information
regarding the GPFS GPL module compile, see DB2 Information Center.
Compiling GPL :…….Failure
ERROR: A major error occurred while installing “DB2 Server Edition ” on this
computer.
解決方案:
查看錯(cuò)誤日志:compileGPL.log.000,為以下內(nèi)容:
cd /usr/lpp/mmfs/src/config; ./configure –genenvonly; if ; then /usr/bin/cpp -P def.mk.proto > ./def.mk; exit $? || exit 1; else exit $?; fi
手工執(zhí)行時(shí)會(huì)發(fā)現(xiàn)在./configure –genenvonly; 這一步報(bào)找不到
/usr/bin/diff: /lib/modules/3.0.76-0.11-default/build/include/linux/autoconf.h: No such file or directory
Kernel source tree does not have the correct autoconf.h file.
See /usr/lpp/mmfs/src/README for further information
手工拷唄一下autoconf.h文件即可
#cp –v /usr/src/linux-3.0.76-0.11-obj/x86_64/default/include/generated/autoconf.h /lib/modules/3.0.76-0.11-default/build/include/linux/
GPFS 文件系統(tǒng)配置與掛載
方法1:使用db2cluster_prepare
node01上執(zhí)行:
#/opt/ibm/db2/v10.5/instance/db2cluster_prepare -instance_shared_dev /dev/sdb
DBI1446I The db2cluster_prepare command is running.
DB2 installation is being initialized.
Total number of tasks to be performed: 1
Total estimated time for all tasks to be performed: 60 second(s)
Task #1 start
Description: Creating IBM General Parallel File System (GPFS) Cluster and Filesystem
Estimated time 60 second(s)
Task #1 end
The execution completed successfully.
For more information see the DB2 installation log at
”/tmp/db2cluster_prepare.log”.
DBI1070I Program db2cluster_prepare completed successfully.
此時(shí)df -l查看一下會(huì)發(fā)現(xiàn)多了一個(gè)掛載點(diǎn)
node01:/opt/ibm/db2/V10.5/instance # df -l
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda44% /
udev8568 1% /dev
tmpfs612 1% /dev/shm
/dev/sda% /home
/dev/db2fs% /db2sd_
曾經(jīng)出現(xiàn)報(bào)錯(cuò):
DBI20232E The DB2 installer detected that the variable record “GPFS_CLUSTER” is
defined in the global registry. However, the GPFS cluster does not exist on
host “node01”.
Creating IBM General Parallel File System (GPFS) Cluster and Filesystem :…….Failure
查看/tmp/ibm.db2.cluster.GuOypP發(fā)現(xiàn)有如下內(nèi)容報(bào)錯(cuò):
1-10.26.12.358494+480 I5385E400 LEVEL: Warning
PID : 7469 TID :12 PROC : db2cluster
INSTANCE: NODE : 000
HOSTNAME: node01
FUNCTION: DB2 UDB, oper system services, sqloMessage, probe:1
MESSAGE : Cannot obtain registry variables
DATA #1 : Hexdump, 4 bytes
x00007FFF: B400 0F87
解決方案:由于此前我在此機(jī)器上試過(guò)N次db2cluster_prepare,包括V9.8、V10.1,V10.5安裝,導(dǎo)致全局注冊(cè)表變量沒(méi)有刪除干凈,使用db2greg -dump
V,GPFS_CLUSTER,NAME,db2cluster_.site,-,DB2_CREATED將其刪除。
#cp -v /var/db2/global.reg /var/db2/global.reg_
#db2delgreg -delvarrec service= GPFS_CLUSTER
總結(jié) :db2cluster_prepare這個(gè)命令失敗時(shí)
檢查iscsi client是否準(zhǔn)備好,fdisk -l查看一下是否有/dev/sdb
全局注冊(cè)表變量是否未刪除干凈 ,db2greg -dump查看
檢查一下是否tsa的domain存在,lsrpdomain,使用rmrpdomain將其刪掉,如果其node為活動(dòng)需先將其node停掉。具體參考tsa相關(guān)命令,
檢查一下gpfs cluster domain是否未清理干凈,如果未清理干凈,需要使用將fs、nsd、node清理掉,具體命令參考gpfs信息中心。
方法2:手工掛載GPFS
遇到過(guò)使用db2cluster_prepare時(shí)無(wú)法成功,手工安裝(不確定是否遇到了 傳說(shuō) 中的bug)。
創(chuàng)建cluster,不加-filesystem -disk選項(xiàng):
node01:
#db2cluster -cfs -create -domain mydomain -host node01
#db2cluster -cfs -add -host node02
# db2cluster -cfs -add -host node03
說(shuō)明:上面如果不出故障當(dāng)然可以加上-filesystem –disk參數(shù),當(dāng)然也可以用mmaddnode –N XXX來(lái)添加節(jié)點(diǎn)
添加許可協(xié)議:
提供兩種方法
#mmchlicense server –accept -N node01,node02,node03
#/opt/ibm/db2/v10.5/bin/db2cluster -cfs -add -license
創(chuàng)建nsd:任意node執(zhí)行
編寫(xiě)newNSD文件內(nèi)容如下
%nsd:
device=/dev/sdb
nsd=nsd1
usage=dataAndMetadata
#mmcrnsd -F /tmp/newNSD (-v no)
如果報(bào)mmcrnsd: Disk device sdb refers to an existing NSD,而使用mmlsnsd 又查找不到相應(yīng)的nsd,添加-v no可以跳過(guò)此驗(yàn)證。
#mmlsnsd 查看創(chuàng)建的nsd名稱,記下,在第3步時(shí)需要用到.
創(chuàng)建Cluster File System并掛載
啟動(dòng)所有node,任意node執(zhí)行
#mmstartup -a
#mmgetstate -a
確保所有node全部啟動(dòng)成功為active
# mmcrfs -T /db2sd_db2sd_nsd1(此處的nsd1為第2步的nsd名稱)
#mmmount all -a
曾經(jīng)出現(xiàn)的錯(cuò)誤:mmstartup -a無(wú)響應(yīng)
,查看日志/var/adm/ras/mmfs.log.previous
Tue Apr 1 22:02:11 CST 2023: runmmfs starting
Removing old /var/adm/ras/mmfs.log.* files:
Unloading modules from /lib/modules/3.0.76-0.11-default/extra
runmmfs: The /lib/modules/3.0.76-0.11-default/extra/mmfslinux.ko kernel extension does not exist.
runmmfs: Unable to verify kernel/module configuration.
Loading modules from /lib/modules/3.0.76-0.11-default/extra
runmmfs: The /lib/modules/3.0.76-0.11-default/extra/mmfslinux.ko kernel extension does not exist.
runmmfs: Unable to verify kernel/module configuration.
Tue Apr 1 22:02:11 CST 2023 runmmfs: error in loading or unloading the mmfs kernel extension
Tue Apr 1 22:02:11 CST 2023 runmmfs: stopping GPFS
解決方案:重新編譯一下gpfs的源碼,因?yàn)槭止ば遁dgpfs。
/usr/lpp/mmfs/src/README有詳細(xì)的編譯方法:主要命令方法如下:
#cd /usr/lpp/mmfs/src
#make Autoconfig
#make InstallImages
make InstallImages會(huì)在/lib/modules/`uname -r`/extra目錄生成3個(gè)文件,大功告成.
創(chuàng)建實(shí)例
創(chuàng)建實(shí)例前:
node02#/opt/ibm/db2/V10.5/instance/db2icrt -cf node01 -cfnet node01
m node02 -mnet node02 -instance_shared_dir /db2sd_
tbdev 192.168.18.2 -u db2fenc1 db2inst1
tbdev 官方解釋為:Specifies a shared device path for a device that will act as a tiebreaker in the DB2 pureScale environment to ensure that the integrity of the data is maintained. 通俗的講就是在member出現(xiàn)故障時(shí),判斷哪個(gè)member可以恢復(fù)服務(wù),窮絲們就用網(wǎng)關(guān)IP來(lái)代替了,只要能 ping 通即可判斷為可用。
此時(shí)執(zhí)行:# db2instance -instance db2inst1 -list可以查看
node01:/opt/ibm/db2/V10.5/instance # mmlscluster
GPFS cluster information
========================
GPFS cluster name: db2cluster_.site
GPFS cluster id:235332
GPFS UID domain: db2cluster_.site
Remote shell command: /var/db2/db2ssh/db2locssh
Remote file copy command: /var/db2/db2ssh/db2scp
GPFS cluster configuration servers:
Primary server: node01.site
Secondary server: node02.site
Node Daemon node name IP address Admin node name Designation
——
node01.site 192.168.18.201 node01.site quorum-manager
node02.site 192.168.18.202 node02.site quorum-manager
曾經(jīng)出現(xiàn)報(bào)錯(cuò):
錯(cuò)誤1、報(bào)、,此類錯(cuò)誤為創(chuàng)建tsa domain時(shí)的錯(cuò)誤,原因在于虛擬機(jī)是拷貝的,不是重新安裝的。
解決方法:#/usr/in/rsct/install/bin/recfgct
啟動(dòng)實(shí)例
node01:$/home/db2inst1/sqllib/adm/db2start
怎么樣,報(bào)錯(cuò)了吧,應(yīng)該是SQL1721N
SQL1721N Starting the DB2 database manager failed because of a problem with a configuration file that is needed by RDMA.受打擊吧。
你裝完了實(shí)例啟動(dòng)不了,沒(méi)關(guān)系,這么高檔的玩意怎么能讓你這么快啟動(dòng)啊。
你得設(shè)置兩個(gè)注冊(cè)表變量才能用普通網(wǎng)絡(luò).
$db2set DB2_SD_SOCKETS_RESTRICTIONS=false
$db2set DB2_CA_TRANSPORT_METHOD=SOCKETS
使用如下命令可以查看CF與member的狀態(tài)。
#db2instance -instance db2inst1 -list
node01:/home/db2inst1 # db2instance -instance db2inst1 -list
ID TYPE STATE HOME_HOST CURRENT_HOST ALERT PARTITION_NUMBER LOGICAL_PORT NETNAME
—
MEMBER STARTED node02 node02 NO 0 0 node02
CF PRIMARY node01 node01 NO – 0 node01
HOSTNAME STATE INSTANCE_STOPPED ALERT
–
node01 ACTIVE NO NO
node02 ACTIVE NO NO
此時(shí)你可以使用lssam查看tsa的兩個(gè)節(jié)點(diǎn)的狀態(tài)。
#lssam
添加成員
將node03添加為另一個(gè)member,如果實(shí)例沒(méi)有啟動(dòng)會(huì)自動(dòng)啟動(dòng)實(shí)例,所以預(yù)先將上一步的兩臺(tái)機(jī)器上的db2set執(zhí)行完畢先。
node01:
#/opt/ibm/db2/v10.5/instance/db2iupdt -d -add -m node03 –mnet node03 db2inst1
#su – db2inst1 -c “db2start member 1”
開(kāi)啟你的purescale之旅
#db2sampl
修改linux的網(wǎng)絡(luò)配置方式有哪些?步驟?
圖形界面就不說(shuō)了 說(shuō)下shell
—修改ip地址—
即時(shí)生效:
# ifconfig eth0 192.168.1.155 netmask 255.255.255.0
重啟生效:
修改/etc/sysconfig/network-scripts/ifcfg-eth0
—修改default gateway—
即時(shí)生效:
# route add default gw 192.168.1.1
重啟生效:
修改/etc/sysconfig/network-scripts/ifcfg-eth0
—修改dns—
修改/etc/基含resolv.conf
修改后即時(shí)生效,重啟同樣有效
—修改host name—
即時(shí)生效好鋒旦:
# hostname test1
重啟生效:
修改友擾/etc/sysconfig/network
在實(shí)際配置時(shí),可以采用四種方法:
其一,基于控制面板法;
其二,基于X的linuxconf法;
三,基于Web瀏覽器的linuxconf法;
其四,手工使用命令法。
二、基于控制面板法
Linux的控制面板中的Network Configuration提供了易于掌握的集成化配置環(huán)境。首先檢查在安裝Red Hat Linux時(shí)是否安裝了控制面板。
# rpm –ga grep control
如果安裝了控制面板,則屏幕上顯示:contrl –panel-3.7-7
如果未安裝這個(gè)軟件包,則鍵入如下命令:
# rpm –i /mnt/cdrom/Red Hat /rpms /usercfg-3.5-6.i386.rpm
單擊控制面板窗口中的Network Configuration按鈕,出現(xiàn)網(wǎng)絡(luò)配置器窗口(如圖1所示)。
1)Names標(biāo)簽
該標(biāo)簽提供了四個(gè)方面的信息:
(1) Hostname(主機(jī)名)
包括機(jī)器名和機(jī)器所在的完整域名。格式為:localhost.local domain,例如,
www.jbxue.com
,其中www為本地機(jī)主名字,jbxue.com為本機(jī)所在域名。
(2) Domain(域名)
機(jī)器所在的完整域名,即為主機(jī)名中的“?!焙竺娌糠帧_@里輸入:linux.net
(3) Search for hostnames in additional domains(在其它域名中尋找主機(jī)名)
該項(xiàng)可不填。
(4) Nameservers(名字服務(wù)器)
即 DNS,這項(xiàng)列出了向網(wǎng)絡(luò)提供域名服務(wù)的計(jì)算機(jī)名單,每行一個(gè)。若要提供名字服務(wù)器清單,則應(yīng)給出ISP服務(wù)商提供的域名服務(wù)器的IP地址。例如:163.1.1.4、10.55.0.33 。
2) Hosts標(biāo)簽
該標(biāo)簽提供計(jì)算機(jī)的主機(jī)表,主機(jī)表放在/etc/host文件中。單擊Hosts標(biāo)簽,并單擊“Add”按鈕,彈出對(duì)話框(圖2)。
主機(jī)表文件包含機(jī)器名,IP地址及計(jì)算機(jī)替換名字。如果在小型網(wǎng)中,沒(méi)有域名服務(wù)器,則主機(jī)表應(yīng)包含所在網(wǎng)絡(luò)中所有機(jī)器的名字和各自的IP地址。在連網(wǎng)的機(jī)器上緩槐至少有IP和name兩項(xiàng)。對(duì)該表的操作包括增加(Add),編輯(edit),刪除(remove)等操作。
首先編輯本地機(jī)項(xiàng)目,在IP欄輸入163.1.5.125,Name欄輸入
www.jbxue.com
,在nickname 欄中,可以
3)Interfaces標(biāo)簽
這是一個(gè)網(wǎng)絡(luò)接口的配置標(biāo)簽。在缺省情況,該表中提供一個(gè)lo項(xiàng)目(本地回環(huán)設(shè)備),該項(xiàng)目不要?jiǎng)h除,它是Linux網(wǎng)絡(luò)工作時(shí)必需具備的一個(gè)項(xiàng)目,對(duì)應(yīng)的IP地址為127.0.0.1。
如果用戶現(xiàn)欲通過(guò)以太網(wǎng)卡接入Internet時(shí),請(qǐng)選中表中eth0項(xiàng)目(注:之一個(gè)網(wǎng)卡設(shè)備名為 eth0, 第二個(gè)為eth1,依次類推)。單擊“Remove”按鈕,刪除掉,然后單擊“Add”按鈕,彈出接口類型對(duì)話框(圖3)。
請(qǐng)選中“Ethernet”單選項(xiàng),單擊“OK”按鈕,出現(xiàn)edit Ethernet/Bus interface對(duì)話框。該對(duì)讓猛話框包含以下內(nèi)容:
(1) IP段 輸入網(wǎng)卡物理地址,即本機(jī)IP地址。如163.1.5.125。
(2) Netmask字段 輸入子網(wǎng)掩碼,如255.255.0.0。
(3) Network字段 自動(dòng)給出163.1.5.0。
(4) Broadcast字段 自動(dòng)給出
(5) Activate interface at boot time單選項(xiàng) 在每次啟動(dòng)時(shí),激活接口,以便使用網(wǎng)絡(luò),建議選擇該項(xiàng)。
(6) Allow any user to (de)activate interface選項(xiàng) 允許任一用戶激活或關(guān)閉網(wǎng)絡(luò)接口。對(duì)于PPP之類的撥號(hào)接口中,每個(gè)用戶都要建立網(wǎng)絡(luò)連接,因此可以選擇該項(xiàng)。對(duì)于以太網(wǎng)連接的用戶,則不必選擇該項(xiàng)。
(7) Interface configuration protocol選項(xiàng) 接口配置協(xié)議。指定服務(wù)器向工作站提供網(wǎng)絡(luò)操作所需信息??勺尡緳C(jī)在每次激活接口時(shí)從服務(wù)器取得配置。它有none,BOOT和DHCP三個(gè)選項(xiàng)。一般選擇“none”。
4)Routing標(biāo)簽
該標(biāo)簽用于配置路由。告訴計(jì)算機(jī)如何把某些數(shù)據(jù)傳到網(wǎng)絡(luò)上的目標(biāo)主機(jī)。如果網(wǎng)絡(luò)使用缺省網(wǎng)關(guān),則只要指出缺省網(wǎng)關(guān)IP地址以及本機(jī)網(wǎng)卡etho。
對(duì)以上四個(gè)標(biāo)簽操作完成后,單擊網(wǎng)絡(luò)配置器窗口中的“save”按鈕,存盤(pán)退出。
三、基于X的linuxconf法
首先由root用戶登錄Linux系統(tǒng),在Gnome環(huán)境中,單擊腳印按鈕,指向“system”,選擇“control-panel”子項(xiàng),以便啟動(dòng)控制面板,然后單擊System Configuration圖標(biāo)。或者單擊腳印按鈕,指向“system”選項(xiàng),選擇linuxconf選項(xiàng)),出現(xiàn)linuxconf在xterm中的工作界面(見(jiàn)圖4)。
⑴打開(kāi)“Networking / Client tasks / Basic host Information”分支,選擇Host name標(biāo)簽,輸入主機(jī)名字;選擇Adaptor 1標(biāo)簽,選中“enable”選項(xiàng),表示能夠使用之一個(gè)網(wǎng)卡;選擇配置方式為Manual;然后分別填寫(xiě):Primary name + domain(主機(jī)名。域名,如:lgx.linux.net)、IP address(主機(jī)的IP地址,如:163.1.5.125)、Net mask(子網(wǎng)掩碼,如:255.255.0.0)、Net device(網(wǎng)絡(luò)設(shè)備名eth0)、Kernel module(內(nèi)核模塊,如果是ne2023的網(wǎng)卡,那么應(yīng)輸入ne)、 I/O port(I/O端口地址,如0x300)、Irq>(中斷號(hào),如3)等選項(xiàng)。
⑵打開(kāi)“Networking / Client tasks / Name Server Specification(DNS)”分支,彈出Resolve configuration對(duì)話框,選中“DNS is required for normal operation”;然后填寫(xiě):Default domain (缺省域名)和Nameserver1(之一個(gè)DNS服務(wù)器的IP地址,如:163.1.1.4;在下一行,還可填寫(xiě)第二個(gè)DNS服務(wù)器的IP地址,如10.55.0.33)選項(xiàng)。
⑶打開(kāi)“Config / Networking / Routing and gateways”選項(xiàng),彈出的Defaults對(duì)話框,在Default gateway字段填寫(xiě)缺省的網(wǎng)關(guān)IP值,如:163.1.1.254,并選中“enable routing”選項(xiàng)。
⑷接受以上寫(xiě)入值,激活并退出。
注:在提示符“#”下,若執(zhí)行l(wèi)inuxconf,則在xterm終端下配置方法與之相類似。
四、基于Web的Linuxconf法
在Red Hat Linux 6.0中,linuxconf也可工作在Web瀏覽器環(huán)境,操作方法是:
⑴在gnome-linuxconf對(duì)話框中,打開(kāi)“Config / Networking / Misc / Linuxconf network access”分支。
⑵在對(duì)話框中輸入任何允許使用Linuxconf的計(jì)算機(jī)的主機(jī)名,包括用戶主機(jī)名字。
⑶選擇“Accept”按鈕,并按空格鍵,單擊“Quit”按鈕。
⑷啟動(dòng)Netscape瀏覽器,在URL欄鍵入:
其中,必選項(xiàng)hostname應(yīng)換成用戶計(jì)算機(jī)的主機(jī)名。
⑸選擇瀏覽器頁(yè)面底部的“Start”按鈕,在彈出的口令驗(yàn)證框中,分別輸入root和相應(yīng)的口令,如果口令正確,
則進(jìn)入如圖5所示的Linuxconf工作環(huán)境。
⑹點(diǎn)擊config框下的“Networking”選項(xiàng),彈出Network Configurator頁(yè)面,在其中的Client tasks框內(nèi),點(diǎn)擊“Basic host information”、“Name server specification(DNS)”、“Routing and gateways”,分別輸入主機(jī)信息、名字服務(wù)器及路由和網(wǎng)關(guān)等信息。
⑺操作完成后,存盤(pán)退出。
五、手工使用命令法
手工使用命令法是基于以太網(wǎng)卡已裝入的情況下,編輯配置文件來(lái)配置網(wǎng)絡(luò)的方法。具體步驟如下:
⑴ 編輯/etc/rc.d/rc.local文件
在該文件中加入類似下列各行:
#配置之一個(gè)以太網(wǎng)卡eth0的IP地址,子網(wǎng)掩碼,UP起激活作用
/in/ifconfig,etho 163.1.5.125 netmask 255.255.0.0 UP
#配置并激活回環(huán)設(shè)備lo
/in/ifconfig lo 127.0.0.1 UP
/in/route add –host 127.0.0.1 lo
#讓Linux將本地網(wǎng)的信息發(fā)送到eth0接口
/in/route add –net 163.1.5.125 netmask 255.255.0.0 eth0
#指定訪問(wèn)遠(yuǎn)程網(wǎng)絡(luò)的缺省網(wǎng)關(guān),假定缺省網(wǎng)關(guān)的IP地址為163.1.1.254
/in/route default gw 163.1.1.254 eth0
⑵ 編輯/etc/resdv.conf文件
該文件作用是設(shè)置名稱服務(wù)器??杉尤胂铝袃?nèi)容。
#指定本機(jī)域名為jbxue.com。
Domain jbxue. com
#域名稱服務(wù)器(DNS),可以是本地網(wǎng),也可以是遠(yuǎn)程網(wǎng)上的。按nameserver的順序#逐一查找。若未找到,則Linux放棄尋找。
Nameserver 163.1.1.4
Nameserver 10.55.0.33
⑶ 編輯/etc/hosts.conf文件
設(shè)置主機(jī)文件表??杉尤肴缦滦校?/p>
order hosts,bind
multi on
163.1.5.125
www.jbxue.com
www
之一行表示:查找名稱時(shí),首先檢查本地主機(jī)文件(hosts),然后按/etc/resolv.conf所指定的Nameservers順序查找。
第三行列出主機(jī)IP地址、主機(jī)名和別名。
對(duì)/etc/rc.d/rc.local,/etc/hosts.conf,/etc/resolv.conf三個(gè)文件編輯后,必須重新啟動(dòng)機(jī)器。
五、結(jié)束語(yǔ)
綜上所述,只要采用其中的任意一種方法,定義主機(jī)名字、主機(jī)表、網(wǎng)絡(luò)接口設(shè)備及路由等參數(shù),配置好Linux以太網(wǎng),就能接入Internet,享受Internet提供的服務(wù)。
linux添加機(jī)器名的介紹就聊到這里吧,感謝你花時(shí)間閱讀本站內(nèi)容,更多關(guān)于linux添加機(jī)器名,如何在Linux中添加機(jī)器名,虛擬機(jī)Linux上部署DB2pureScale過(guò)程,修改linux的網(wǎng)絡(luò)配置方式有哪些?步驟?的信息別忘了在本站進(jìn)行查找喔。
成都創(chuàng)新互聯(lián)科技有限公司,是一家專注于互聯(lián)網(wǎng)、IDC服務(wù)、應(yīng)用軟件開(kāi)發(fā)、網(wǎng)站建設(shè)推廣的公司,為客戶提供互聯(lián)網(wǎng)基礎(chǔ)服務(wù)!
創(chuàng)新互聯(lián)(www.cdcxhl.com)提供簡(jiǎn)單好用,價(jià)格厚道的香港/美國(guó)云服務(wù)器和獨(dú)立服務(wù)器。創(chuàng)新互聯(lián)——四川成都IDC機(jī)房服務(wù)器托管/機(jī)柜租用。為您精選優(yōu)質(zhì)idc數(shù)據(jù)中心機(jī)房租用、服務(wù)器托管、機(jī)柜租賃、大帶寬租用,高電服務(wù)器托管,算力服務(wù)器租用,可選線路電信、移動(dòng)、聯(lián)通機(jī)房等。
分享文章:如何在Linux中添加機(jī)器名(linux添加機(jī)器名)
文章出自:http://fisionsoft.com.cn/article/dhhoieg.html


咨詢
建站咨詢
