1. 程式人生 > >Linux基礎命令複習-叢集常用命令詳解

Linux基礎命令複習-叢集常用命令詳解

1.ifconfig/ip a
[[email protected] ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:C3:C5:49  
          inet addr:192.168.48.10  Bcast:192.168.48.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fec3:c549/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5484354 errors:0 dropped:0 overruns:0 frame:0
          TX packets:768709 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:7696445437 (7.1 GiB)  TX bytes:214070030 (204.1 MiB)


2.yum install -y openssh-clients


3.ssh免金鑰登陸
[[email protected] httpd]# ssh-keygen -t rsa
一路回車
[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]
如果報錯:-bash: ssh-copy-id: command not found,執行yum安裝命令。
[[email protected] ~]# yum install -y openssh-clients


4.hostname
[
[email protected]
httpd]# hostname
controller


5.crontab
crontab任務配置基本格式:
*   *  *  *  *  command
分鐘(0-59) 小時(0-23) 日期(1-31) 月份(1-12) 星期(0-6,0代表星期天)  命令
列子:

0 1 * * * /home/testuser/test.sh
每天晚上1點呼叫/home/testuser/test.sh

*/10 * * * * /home/testuser/test.sh
每10鐘調用一次/home/testuser/test.sh

30 21 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每晚的21:30重啟apache。

45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每月1、10、22日的4 : 45重啟apache。

10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每週六、週日的1 : 10重啟apache。

0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示在每天18 : 00至23 : 00之間每隔30分鐘重啟apache。

0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每星期六的11 : 00 pm重啟apache。

* */1 * * * /usr/local/etc/rc.d/lighttpd restart
每一小時重啟apache

* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
晚上11點到早上7點之間,每隔一小時重啟apache

0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
每月的4號與每週一到週三的11點重啟apache

0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
一月一號的4點重啟apache

*/30 * * * * /usr/sbin/ntpdate 210.72.145.44
每半小時同步一下時間


6.scp
[[email protected] ~]# scp scptest [email protected]:$PWD
scptest                                                      100%    4     0.0KB/s   00:00    
[[email protected] ~]# 


7.fdisk
[[email protected] ~]# fdisk

Usage:
 fdisk [options] <disk>    change partition table
 fdisk [options] -l <disk> list partition table(s)
 fdisk -s <partition>      give partition size(s) in blocks

Options:
 -b <size>                 sector size (512, 1024, 2048 or 4096)
 -c                        switch off DOS-compatible mode
 -h                        print help
 -u <size>                 give sizes in sectors instead of cylinders
 -v                        print version
 -C <number>               specify the number of cylinders
 -H <number>               specify the number of heads
 -S <number>               specify the number of sectors per track

8.shell
#!/bin/bash
# 上面中的 #! 是一種約定標記, 它可以告訴系統這個指令碼需要什麼樣的直譯器來執行;

echo "Hello, world!"

[[email protected] ~]# ./hello.sh
-bash: ./hello.sh: Permission denied
[[email protected] ~]# chmod +x hello.sh 
[[email protected] ~]# ls
anaconda-ks.cfg                hello.sh     install.log.syslog  XianDian-IaaS-v1.4.iso
CentOS-6.5-x86_64-bin_DVD.iso  install.log  scptest


9.iptables
service iptables stop/start/restart/status
chkconfig iptables off


10.selinux
selinux三種狀態介紹:
enforcing-是強制模式系統,它受selinux保護。就是違反了策略你就無法繼續操作下去。
permissive-是提示模式系統不會受到selinux保護,只是收到警告資訊。permissive就是selinux有效,但disabled-禁用selinux是即使你違反了策略的話它讓你繼續操作,但是把你違反的內容記錄下來(警告資訊)
disabled-禁用selinux

selinux的全稱是Security Enhance Linux,就是安全加強的Linux。
Selinux會對我們後續使用的httpd服務進行保護,導致無法訪問到頁面,因此需要將selinux設定為permissive或者disabled。
[[email protected] ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive

11.新增主機名與IP對映
[[email protected] ~]# vi /etc/hosts
192.168.48.10   controller
192.168.48.20   compute

12.常用系統關機命令:
halt ,init 0 ,poweroff ,shutdown -h now ,shutdown -h 10

13.常用系統重啟命令:
reboot , shutdown -r now , init 1