BenjaminYang In solitude, where we are least alone

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       --设置命令行模式为默认模式

 

 
posted @ 2018-02-26 14:36  benjamin杨  阅读(1934)  评论(0编辑  收藏  举报