1. 程式人生 > >centos7 裝機後的基本配置

centos7 裝機後的基本配置

安裝完centos7.3後,做一些基本的操作

下面是我的環境的配置,你們可以根據自己的環境搭配相應的配置。修改下就可以了。



基本操作一:主機名
centos7有一個新的修改主機名的命令hostnatctl

# hostnamectl set-hostname --static feng.cluster.com ----修改主機名

# vim /etc/hosts --最後加上你的IP與主機名的繫結
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.21.250 feng.cluster.com feng ----其中最後的li是主機名的別名
172.16.13.250 feng.cluster.com feng

主機名:內網名字
域名:公網名字
主機名不能是localhost
繫結主機名就相當於內網的dns,非常重要。
繫結主機名的作用?




基本操作二:關閉iptables


# systemctl status firewalld.service
----檢視firewalld服務的狀態,active是啟動狀態,inactive是關閉狀態

# systemctl stop firewalld.service ----關閉此服務


# systemctl list-unit-files |grep firewalld --檢視firewalld是否開機自動啟動
firewalld.service enabled ----為自動啟動

# systemctl disable firewalld.service--類似以前的chkconfig xxx off,關閉開機自動啟動

# systemctl list-unit-files |grep firewalld

firewalld.service disabled ----不自啟動



基本操作三:關閉selinux(方法和以前一樣)

# sed -i 7s/enforcing/disabled/ /etc/selinux/config
--改完後,在後面重啟系統生效






基本操作四:網路配置
# systemctl stop NetworkManager
--停止服務
# systemctl status NetworkManager--檢視狀態,確認為關閉了
# systemctl disable NetworkManager --設定為開機不自動啟動


# vim /etc/sysconfig/network-scripts/ifcfg-enp2s0
--網絡卡名如果不一樣,找到對應的檔案就行

BOOTPROTO="static"
NAME="enp2s0"
DEVICE="enp2s0"
ONBOOT="yes"
IPADDR=172.16.13.X
NETMASK=255.255.255.0
GATEWAY=172.16.13.254
DNS1=114.114.114.114


# /etc/init.d/network restart --network服務這裡預設還是可以使用原來的管理方法
# chkconfig network on



基本操作五:yum配置

1,通過firefox訪問下面路徑,並下載centos7.3映象

wget http://172.16.21.250/CentOS-7-x86_64-DVD-1611.iso


# ll CentOS-7-x86_64-DVD-1611.iso--拷貝完後,確認大小一致
-rw-r--r--. 1 qemu qemu 4379901952 Apr 20 04:56 /share/CentOS-7-x86_64-DVD-1611.iso


# mkdir /yum
# mount /share/CentOS-7-x86_64-DVD-1611.iso /yum --我本地的映象在/share下,我把它掛載到/yum目錄

# echo "mount /share/CentOS-7-x86_64-DVD-1611.iso /yum" >> /etc/rc.local
# chmod a+x /etc/rc.d/rc.local
--centos7要把rc.local原檔案加執行許可權,開機才會自動執行

注意:步驟1只有物理機裝centos7系統的才需要做,虛擬機器直接掛載映象即可

2,配置本地yum源
# rm /etc/yum.repos.d/* -rf
--這裡我刪除了它所有的預設的配置(因為這些預設配置要連公網的源,速度太慢)

# vim /etc/yum.repos.d/local.repo --然後自建了本地yum源配置檔案
[local]
name=local
baseurl=file:///yum
enabled=1
gpgcheck=0




3,配置可選163的centos源
163centos源(其實就是centos官方的yum,使用163的國內速度更快)
配置方法兩種
a)直接公網連線網易163,優點:速度快,軟體包會定期更新

# cd /etc/yum.repos.d/
# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo


b)使用老師機器上的源(全部從163上下載而來),優點:區域網速度更快,但軟體包不能更新(因為我沒有寫定期去網上同步)

# vim /etc/yum.repos.d/cento163.repo


[centos163]
name=centos163
baseurl=http://172.16.21.250/centos163/
enabled=1
gpgcheck=0


3,配置可選epel源
配置方法兩種
a)直接公網連線epel,優點:速度快,軟體包會定期更新
# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm--此版本資訊會隨時間推移而變化
# rpm -ivh epel-release-7-10.noarch.rpm


b)使用老師機器上的源(全部從epel上下載而來),優點:區域網速度更快,但軟體包不能更新(因為我沒有寫定期去網上同步)

# vim /etc/yum.repos.d/epel.repo


[epel]
name=epel
baseurl=http://172.16.21.250/epel/
enabled=1
gpgcheck=0



配置完上面三個yum後
# yum clean all
# yum makecache fast

可能遇到的問題:

Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 146 M RSS (556 MB VSZ)
Started: Wed Aug 30 12:40:02 2017 - 20:22 ago
State : Sleeping, pid: 2247
原因:可能是系統自動升級正在執行,yum在鎖定狀態中。
已經有一個yum程序在運行了,但是使用kill幹不掉它。
解決方法:# rm -f /var/run/yum.pid






基本操作六:輸入法配置

預設只有拼音中文輸入法,我這裡需要使用極點五筆輸入法(如果不用五筆的話可以不安裝),安裝過程如下:
# yum -y install ibus ibus-table-chinese-wubi-jidian

安裝完後,需要右上角把使用者登出重登入

左上角applications--system tools -- settions -- Region & Language -- +或-你的輸入法就可以了

加完之後,使用super+space鍵進行切換






基本操作七:時間同步
# yum -y install ntp ntpdate
--安裝ntp時間同步相關軟體包
# vim /etc/ntp.conf --確認配置檔案裡有下列的時間同步源
server 0.rhel.pool.ntp.org iburst
server 1.rhel.pool.ntp.org iburst
server 2.rhel.pool.ntp.org iburst
server 3.rhel.pool.ntp.org iburst

# systemctl enable ntpd --設定開機自動啟動ntpd
# systemctl start ntpd--立即啟動ntpd服務
# date --確認時間與現在時間一致

# ntpdate 0.rhel.pool.ntp.org --如果還沒有同步成功,你可以用此命令手動同步一下



另外一個時間伺服器的搭建方法

# yum -y install xinetd -y
# vim /etc/xinet.d/time-dgram

disable = no (--yes改為no)

# vim /etc/xinetd.d/time-stream
disable = no (--yes改為no)

# systemctl restart xinetd
# systemctl status xinetd
# systemctl enable xinetd



客戶端同步時間的用法
# rdate -s 時間伺服器的ip



基本操作八:
有些命令的引數可以自動補全,如果不能補全,則安裝下面的命令(可能需要登出一下)
# yum -y install bash-completion




基本操作九:vnc的配置

# vncpasswd
--設定vcn連線的密碼
Password:
Verify:

# x0vncserver --PasswordFile=/root/.vnc/passwd --AlwaysShared=on --AcceptKeyEvents=off AcceptPointerEvents=off &> /dev/null &




基本操作十:桌面鎖屏

左上角applications--system tools -- settions -- Privacy 設定是否自動鎖屏

手動鎖屏
super+l



基本操作十一:圖形介面快捷鍵修改
左上角applications--system tools -- settions -- Keyboard -- Shortcuts 去修改自己習慣的快捷鍵



基本操作十二:設定預設啟動級別為圖形模式(相當於以前的5級別)

# systemctl get-default
--檢視當前的執行模式

# systemctl set-default graphical.target --設定圖形模式為預設模式