CentOS 6.8(32)相关操作

来源:互联网 发布:lacie setup 软件下载 编辑:程序博客网 时间:2024/05/29 16:28
CentOS6.8(32)
=======================
查看Linux内核版本命令 cat /proc/version
查看Linux系统版本的命令 lsb_release -a
查看linux机器是32位还是64位的方法:file /bin/ls


0. Linux 启动模式,text/graphics








如果想开机直接进入“命令行模式”,可编辑 /etc/inittab 文件,设置为 id:3:initdefault:
如果想直接进入“窗口模式”,则设置为 id:5:initdefault:



1. linux 用户管理



groupadd hadoop

useradd -g hadoop -G adm,root hadoop

passwd  hadoop








暂时修改:
hostname
hostnmae 主机名
永久修改:
1)通过配置文件/etc/sysconfig/network修改。
# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
2)
更改/etc下的hosts文件,在提示符下输入vi /etc/hosts,
然后将localhost.localdomain改为想要设置的主机名。


"not in the sudoers file"
/etc/sudoers ,
找到 Allow root to ruan any commands anywhere这一行
在root  ALL=(ALL)  ALL 下面另起一行,输入“xx ALL=(ALL)  ALL”(xx表示你的用户名),然后保存退出

groups
usermod -G adm,root liugf
useradd -d /home/hadoop -m hadoop
passwd username

2. Linux 网络管理






网络信息查看:
cat /etc/sysconfig/network-scripts/ifcfg-eth0 

(1) 配置eth0的IP地址, 同时激活该设备
sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
(2) 添加默认网关
sudo route add default gw 192.168.1.1
(3) 配置DNS
$ sudo vi /etc/resolv.conf  [5.0 时代]
   
#激活设备
ifconfig eth0 up
#禁用设备
ifconfig eth0 down

route -n 查看下路由表

临时修改方案,重启后失效:

#ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up

永久修改方案:



1. 修改网络配置文件:/etc/sysconfig/network-scripts/ifcfg-eth0

动态IP配置:

DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:03:47:2C:D5:40
ONBOOT=yes
TYPE=Ethernet

静态IP配置:

DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.223

NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=202.96.128.86
DOMAIN=202.96.128.166
HWADDR=00:03:47:2C:D5:40
ONBOOT=yes
TYPE=Ethernet

2. 重启服务生效:service network restart



3. SSH


ssh面密码登陆:


配置问题

  1. 检查配置文件/etc/ssh/sshd_config是否开启了AuthorizedKeysFile选项
  1. 检查AuthorizedKeysFile选项指定的文件是否存在并内容正常
  1. ~权限设置为700
  1. ~/.ssh权限设置为700
  1. ~/.ssh/authorized_keys的权限设置为600

/etc/ssh/sshd_config

找到以下内容,并去掉注释符”#“

  RSAAuthentication yes

  PubkeyAuthentication yes

  AuthorizedKeysFile      .ssh/authorized_keys

修改了配置文件需要重启sshd服务

  $ service sshd restart


#mkdir .ssh

#cd .ssh

#ssh-keygen -t rsa -P '' -f id_rsa

#cat id_rsa.pub >> authorized_keys


目录权限问题



重启 ssh:sudo service sshd restart





在打开的终端页面,输入如下代码:
ssh user@hostname
注:上边代码为固定格式,其中
       user 为 linux 服务器的管理员名称
       hostname 为 linux 服务器的IP
       
 利用ssh传输文件:
       1、从服务器上下载文件
scp username@servername:/path/filename /var/www/local_dir(本地目录)


例如scp root@192.168.0.101:/var/www/test.txt  
把192.168.0.101上的/var/www/test.txt 的文件下载到/var/www/local_dir(本地目录)




2、上传本地文件到服务器
scp /path/filename username@servername:/path   

例如scp /var/www/test.php  root@192.168.0.101:/var/www/  
把本机/var/www/目录下的test.php文件上传到192.168.0.101这台服务器上的/var/www/目录中
 
3、从服务器下载整个目录
scp -r username@servername:/var/www/remote_dir/(远程目录) /var/www/local_dir(本地目录)

例如:scp -r root@192.168.0.101:/var/www/test  /var/www/  

4、上传目录到服务器
scp  -r local_dir username@servername:remote_dir
例如:scp -r test  root@192.168.0.101:/var/www/   
把当前目录下的test目录上传到服务器的/var/www/ 目录
       
       5.查看目录或文件:
ssh user@host command ls "/path/*.tgz"


3.Linux 源修改:

第一步:备份你的原镜像文件,以免出错后可以恢复。
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup


第二步:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo 
yum clean all

yum makecache


4.Linux 终端颜色


~/.bashrc
export LS_COLORS=$LS_COLORS:'di=1;33:' ; 

Some nice color choices (in this case 0;35 it is purple) are:
Blue = 34
Green = 32
Light Green = 1;32
Cyan = 36
Red = 31
Purple = 35
Brown = 33
Yellow = 1;33
white = 1;37
Light Grey = 0;37
Black = 30
Dark Grey= 1;30
The first number is the style (1=bold), 
followed by a semicolon, and then the actual number of the color,
possible styles are:
 
 
0   = default colour
1   = bold
4   = underlined
5   = flashing text
7   = reverse field
40  = black background
41  = red background
42  = green background
43  = orange background
44  = blue background
45  = purple background
46  = cyan background
47  = grey background
100 = dark grey background
101 = light red background
102 = light green background
103 = yellow background
104 = light blue background
105 = light purple background
106 = turquoise background


All possible colors:


31  = red
32  = green
33  = orange
34  = blue
35  = purple
36  = cyan
37  = grey
90  = dark grey
91  = light red
92  = light green
93  = yellow
94  = light blue
95  = light purple
96  = turquoise

di=1;4;31;42
in your LS_COLORS variable would make directories appear 
in bold underlined red text with a green background!


ou can also change other kinds of files when using the ls command by defining each kind with:
di = directory
fi = file
ln = symbolic link
pi = fifo file
so = socket file
bd = block (buffered) special file
cd = character (unbuffered) special file
or = symbolic link pointing to a non-existent file (orphan)
mi = non-existent file pointed to by a symbolic link (visible when you type ls -l)
ex = file which is executable (ie. has 'x' set in permissions).
*.rpm = files with the ending .rpm

5. 禁用防火墙


centos 7:
systemctl stop firewalld.service #停止
systemctl disable firewalld.service #禁用
之前的版本:
service iptables stop #停止
chkconfig iptables off #禁用





6.  tree ,

  1.  yum install tree




0 0