centos7剛安裝需要的一些基礎優化


基本操作一:更改主機名

centos7有一個新的修改主機名的命令hostnamectl
# hostnamectl set-hostname --static benjamin
# vim /etc/hosts    --最后加上你的IP與主機名的綁定
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.8  benjamin

 



基本操作二:關閉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-eth0    --網卡名如果不一樣,找到對應的文件就行
BOOTPROTO="static"
NAME="eth0"
DEVICE="eth0"
ONBOOT="yes"
IPADDR=10.0.0.8
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=114.114.114.114
# /etc/init.d/network restart        --network服務這里默認還是可以使用原來的管理方法
# chkconfig network on

 



基本操作五:yum配置
#配置本地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

配置可選163的centos源
163centos源(其實就是centos官方的yum,使用163的國內速度更快)
配置方法兩種
a)直接公網連接網易163,優點:速度快,軟件包會定期更新
# cd /etc/yum.repos.d/
# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

b)自己編寫
# vim /etc/yum.repos.d/cento163.repo
[centos163]
name=centos163
baseurl=http://mirrors.163.com/centos/7.4.1708/os/x86_64/ #這個會根據版本迭代適時變化
enabled=1
gpgcheck=0

配置可選epel源
配置方法兩種
a)直接公網連接epel,優點:速度快,軟件包會定期更新
# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm   --此版本信息會隨時間推移而變化
# rpm -ivh epel-release-7-10.noarch.rpm
b)自己編寫
# vim /etc/yum.repos.d/epel.repo
[epel]
name=epel
baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64
enabled=1
gpgcheck=0

 


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

 


基本操作六:配置國內pip源
國外網站的pip源速度慢且不穩定,經常出現下載到一半就斷開了很是蛋疼!
# yum install python-pip
# vim ~/.pip/pip.conf

  [global]  

  index-url = http://pypi.douban.com/simple  

  trusted-host = pypi.douban.com  


安裝完后,需要右上角把用戶注銷重登錄
左上角applications--system tools -- settions -- Region & Language -- +或-你的輸入法就可以了
加完之后,使用super+space鍵進行切換

基本操作七:時間同步
# yum 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    --如果還沒有同步成功,你可以用此命令手動同步一下
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #更改時區為上海

 



另外一個時間服務器的搭建方法
# yum 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 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    --設置圖形模式為默認模式
# systemctl set-default multi-user.target       --設置命令行模式為默認模式

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM