centos 安裝完之後的設定

來源:互聯網
上載者:User

  在 CentOS 安裝好之後,安全性以及對硬體的適應性方面,可能並不完全符合我們的實際情況。在這裡,對新的 CentOS 系統進行初始環境設定將以如下方面為原則:

  1,為了安全,盡最大可能將訪問限制限制到可能的最大程度;
  2,為了節省記憶體及 CPU 使用率(以及安全方面的考慮),盡最大可能將不需要的服務關閉;
  3,為了減少誤操作可能帶來的損失,平時通過 wheel 組使用者登入進行系統管理;
  4,為了讓系統變的更加輕便、快速,將核心中不需要的模組卸載;
  …………

CentOS 4.4 的安裝後初始環境設定

   安裝完畢重新啟動系統後,出現如下的狀態:

CentOS release 4.4 (Final)
Kernel 2.6.9-42.EL on an i686

sample login:   ← 根據安裝時網路設定的情況的不同,本站以“sample”,其位置顯示的是你設定好的主機名稱。

[1] 系統的登入與退出

sample login: root ← 用root使用者來登入系統,輸入使用者名稱root
Password: ← 在這裡輸入安裝時設定的root密碼,輸入時密碼不會被顯示

[root@sample ~]# ← root使用者登入成功,提示符為“#”。若一般使用者登入成功後,提示符為“$”

[root@sample ~]# exit ← 退出系統

sample login: ← 退出系統成功

[2] 一般使用者的建立與刪除

[root@sample ~]# useradd centospub ← 建立使用者名稱為 centospub 的一般使用者
[root@sample ~]# passwd centospub ← 為使用者 centospub 設定密碼
Changing password for user centospub.
New UNIX password:  ← 輸入密碼(密碼不會被顯示)
Retype new UNIX password:  ← 再次輸入密碼確認兩次密碼一致
passwd: all authentication tokens updated successfully. ← 密碼設定成功

[root@sample ~]# userdel -r centospub ← 刪除使用者名稱為 centospub 的一般使用者

[3] 通過一般使用者登入狀態root使用者

  因為root使用者對系統具有全權的操作許可權,為了避免一些失誤的操作,建議在一般情況下,以一般使用者登入系統,必要的時候需要root操作許可權時,再通過“su -”命令來登入狀態root使用者進行操作。

[centospub@sample ~]$  ← 提示符為“$”,說明目前狀態為一般使用者centospub登入在系統中

[centospub@sample ~]$ su -  ← 輸入登入狀態root使用者的命令
Password:   ← 輸入root密碼(密碼不會被顯示),斷行符號

[root@sample ~]# ← 成功登入狀態root使用者,提示符變為“#”

[root@sample ~]# exit ← 回到一般使用者的登入狀態

[centospub@sample ~]$ ← 提示符變為“$”,回到了一般使用者centospub登入系統的狀態

[4] 建立Administrator 群組內一般使用者

   在 一般情況下,一般使用者通過執行“su -”命令、輸入正確的root密碼,可以登入狀態root使用者來對系統進行管理員層級的配置。但是,為了更進一步加強系統的安全性,有必要建立一個管理員的 組,只允許這個組的使用者來執行“su -”命令登入狀態root使用者,而讓其他組的使用者即使執行“su -”、輸入了正確的root密碼,也無法登入狀態root使用者。在UNIX下,這個組的名稱通常為“wheel”。

[root@sample ~]# usermod -G wheel centospub  ← 將一般使用者 centospub 加在Administrator 群組wheel組中

[root@sample ~]# vi /etc/pam.d/su  ← 開啟這個設定檔

#auth required /lib/security/$ISA/pam_wheel.so use_uid   ← 找到此行,去掉行首的“#”
 ↓
auth required /lib/security/$ISA/pam_wheel.so use_uid  ← 變為此狀態(大約在第6行的位置)

[root@sample ~]# echo "SU_WHEEL_ONLY yes" >> /etc/login.defs ← 添加語句到行末

  以上操作完成後,可以再建立一個新使用者,然後用這個建立的使用者測試會發現,沒有加入到wheel組的使用者,執行“su -”命令,即使輸入了正確的root密碼,也無法登入狀態root使用者。

[5] 建立PPPoE串連(非xDSL接入方式的使用者可跳過此步驟)

[root@sample ~]# adsl-setup  ← 建立ADSL串連

Welcome to the ADSL client setup. First, I will run some checks on
your system to make sure the PPPoE client is installed properly...

LOGIN NAME

Enter your Login Name (default root): ← 填入ADSL串連的使用者名稱

INTERFACE

Enter the Ethernet interface connected to the ADSL modem
For Solaris, this is likely to be something like /dev/hme0.
For Linux, it will be ethX, where 'X' is a number.
(default eth0):  ← 指定網路接入裝置,一塊網卡的情況下,一般為預設eth0

Do you want the link to come up on demand, or stay up continuously?
If you want it to come up on demand, enter the idle time in seconds
after which the link should be dropped. If you want the link to
stay up permanently, enter 'no' (two letters, lower-case.)
NOTE: Demand-activated links do not interact well with dynamic IP
addresses. You may have some problems with demand-activated links.
Enter the demand value (default no):  ← 直接按斷行符號,接受預設設定

DNS

Please enter the IP address of your ISP's primary DNS server.
If your ISP claims that 'the server will provide dynamic DNS addresses',
enter 'server' (all lower-case) here.
If you just press enter, I will assume you know what you are
doing and not modify your DNS setup.
Enter the DNS information here:  ← 如果知道DNS伺服器的資訊在此填入。不知道的情況按斷行符號跳過

PASSWORD

Please enter your Password: ← 輸入ADSL的串連密碼
Please re-enter your Password: ← 再次確認輸入ADSL的串連密碼

USERCTRL

Please enter 'yes' (two letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes): no ← 填入no,不允許一般使用者控制PPPoE的串連

FIREWALLING

Please choose the firewall rules to use. Note that these rules are
very basic. You are strongly encouraged to use a more sophisticated
firewall setup; however, these will provide basic security. If you
are running any servers on your machine, you must choose 'NONE' and
set up firewalling yourself. Otherwise, the firewall rules will deny
access to all standard servers like Web, e-mail, ftp, etc. If you
are using SSH, the rules will block outgoing SSH connections which
allocate a privileged source port.

The firewall choices are:
0 - NONE: This script will not set any firewall rules. You are responsible
for ensuring the security of your machine. You are STRONGLY
recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
for a LAN
Choose a type of firewall (0-2): 0 ← 輸入0,不在這裡使用防火牆

Start this connection at boot time

Do you want to start this connection at boot time?
Please enter no or yes (default no): yes ← 填入yes,在系統啟動時自動連接ADSL

** Summary of what you entered **

Ethernet Interface: eth0
User name: caun870293@ca.dti.ne.jp
Activate-on-demand: No
DNS: Do not adjust
Firewalling: NONE
User Control: no
Accept these settings and adjust configuration files (y/n)? y ← 配置資訊確認無誤後,鍵入y同意設定
Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0
Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets
(But first backing it up to /etc/ppp/chap-secrets.bak)
(But first backing it up to /etc/ppp/pap-secrets.bak)

?

Congratulations, it should be all set up!

Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'
to bring it down.
Type '/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0'
to see the link status.

  然後,啟動ADSL串連。

[root@sample ~]# adsl-start  ← 啟動ADSL串連

[root@sample ~]#   ← 稍等片刻後若啟動成功後出現提示符(無任何提示即意味著串連成功)

  這時,通過“ifconfig”命令可以看到各網路介面的資訊(IP地址等等)。

[6] root郵件的轉送

  在系統出現錯誤或有重要通知發送郵件給root的時候,讓系統自動轉送到我們通常使用的郵箱中,這樣方便查閱相關報告和日誌。

[root@sample ~]# vi /etc/aliases   ← 編輯aliases,添加如下行到文尾

root: yourname@yourserver.com ← 加入自己的郵箱地址

[root@sample ~]# newaliases ← 重建aliasesdb
/etc/aliases: 79 aliases, longest 19 bytes, 825 bytes total

[root@sample ~]# echo test | mail root ← 發送測試郵件給root

  如果成功的話,會在剛剛填入的 yourname@yourserver.com 的郵箱中收到測試的郵件。

[7] locate命令用資料庫更新及自動更新設定

  locate命令是Linux下告訴搜尋檔案用的工具,它的原理和Windows下的“Google案頭搜尋”有點類似,是通過事先建立資料庫的方式,來達到高速尋找目標檔案的目的。

[root@sample ~]# vi /etc/updatedb.conf  ← 編輯locate資料庫更新設定檔

DAILY_UPDATE=no  ← 找到這一行,將“no”改為“yes”
 ↓
DAILY_UPDATE=yes  ← 變為此狀態後,儲存、退出

[root@sample ~]# updatedb  ← 運行locate資料庫更新命令,稍等片刻…更新成功後出現提示符

[8] 定義yum的非官方庫

  在伺服器構建的過程中,我們將要用到的一些工具不存在於CentOS中yum的官方庫中,所以需要定義yum的非官方庫檔案,讓一些必需的工具通過yum也能夠安裝。

[root@sample ~]# vi /etc/yum.repos.d/dag.repo  ← 建立dag.repo,定義非官方庫

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

[root@sample ~]# rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt  ← 匯入非官方庫的GPG

[9] 停止列印服務

  如果不準備提供列印服務,停止預設被設定為自動啟動的列印服務。

[root@sample ~]# /etc/rc.d/init.d/cups stop  ← 停止列印服務
Stopping cups:            [ OK ]    ← 停止服務成功,出現“OK”

[root@sample ~]# chkconfig cups off  ← 禁止列印服務自動啟動

[root@sample ~]# chkconfig --list cups  ← 確認列印服務自啟動設定狀態
cups 0:off 1:off 2:off 3:off 4:off 5:off 6:off  ← 0-6都為off的狀態就OK(當前列印服務自啟動被禁止中)

[10] 停止ipv6

  在CentOS預設的狀態下,ipv6是被啟用的狀態。因為我們不使用ipv6,所以,停止ipv6,以最大限度保證安全和快速。

  首先再次確認一下ipv6功能是不是被啟動的狀態。

[root@sample ~]# ifconfig -a ← 列出全部網路介面資訊

eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:16:A3
inet addr:192.168.0.13 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feb6:16a3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:84 errors:0 dropped:0 overruns:0 frame:0
TX packets:93 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10288 (10.0 KiB) TX bytes:9337 (9.1 KiB)
Interrupt:185 Base address:0x1400

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:952 (952.0 b) TX bytes:952 (952.0 b)

sit0 Link encap:IPv6-in-IPv4 ← 確認ipv6是被啟動的狀態
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

  然後修改相應設定檔,停止ipv6。

[root@sample ~]# vi /etc/modprobe.conf ← 修改相應設定檔,添加如下行到文尾:

alias net-pf-10 off
alias ipv6 off

[root@sample ~]# shutdown -r now  ← 重新啟動系統,使設定生效

  最後確認ipv6的功能已經被關閉。

[root@sample ~]# ifconfig -a ← 列出全部網路介面資訊

eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:16:A3
inet addr:192.168.0.13 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feb6:16a3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:84 errors:0 dropped:0 overruns:0 frame:0
TX packets:93 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10288 (10.0 KiB) TX bytes:9337 (9.1 KiB)
Interrupt:185 Base address:0x1400 lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:952 (952.0 b) TX bytes:952 (952.0 b)

(確認ipv6的相關資訊沒有被列出,說明ipv6功能已被關閉。)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.