Difference between revisions of "Basic"

From AlphaBook
Jump to: navigation, search
(apt-get)
(Network)
 
(37 intermediate revisions by the same user not shown)
Line 1: Line 1:
== apt-get ==
+
== Partition ==
* Update the Package Index
+
* /boot
** sudo apt-get update
+
* /
* Upgrade Packages
+
* swap
** sudo apt upgrade
+
 
* Install a Package
+
== Hostname ==
** sudo apt-get install net-tools
+
* hostnamectl
** sudo apt-get install vim
+
* hostnamectl set-hostname Linux001
* Remove a Package
 
** sudo apt-get remove net-tools
 
* Source list
 
** sudo vim /etc/apt/sources.list
 
  
 
== Network ==
 
== Network ==
 +
* ip address
 +
* vi /etc/sysconfig/network-scripts/ifcfg-eth0
 +
* BOOTPROTO=static
 +
* ONBOOT=yes
 +
* IPADDR=192.168.200.10
 +
* NETMASK=255.255.255.0
 +
* GATEWAY=192.168.200.1
 +
* DNS1=114.114.114.114
 +
* DOMAIN=corp.alphabook.cn
 +
* systemctl restart network
 +
* CentOS 7 NetworkManager Keeps Overwriting /etc/resolv.conf
 +
** Check DNS related configuration in /etc/sysconfig/network-scripts/ifcfg-ens32
 +
* ifdown eth0
 +
* ifup eth0
 +
* More [[bond]]
  
* List network adaptors
+
== Time ==
** ip a
+
* timedatectl
 +
* timedatectl list-timezones | grep Asia
 +
* timedatectl set-timezones Asia/Shanghai
 +
* cat /etc/chrony.conf
 +
* Or ntp
 +
* systemctl stop chronyd.service
 +
* systemctl disable chronyd.service
 +
* yum install ntp
 +
* systemctl start ntpd.service
 +
* systemctl enable ntpd.service
  
* sudo vim /etc/netplan/01-network-manager-all.yaml
+
== Service ==
: network:
+
* systemctl status ssh
:: version: 2
+
* systemctl start ssh
:: renderer: NetworkManager
+
* systemctl stop ssh
:: ethernets:
+
* systemctl restart ssh
::: ens33:
+
* systemctl reload ssh
:::: addresses: [192.168.200.55/24]
+
* systemctl enable ssh
:::: gateway4: 192.168.200.1
+
* systemctl disable ssh
 +
* systemctl is-enabled ssh
 +
* systemctl is-active ssh
 +
* systemctl show ssh
  
* sudo netplan apply
+
== Disk ==
* /etc/resolv.conf
+
* df -h
** name server 114.114.114
+
* fdisk -l
** search corp.alphabook.cn
+
* fdisk -l /dev/sda
 +
* more about [http://www.alphabook.cn/index.php?title=Advanced#fdisk fdisk]
  
* Command 'ifconfig' not found, but can be installed with:
+
== Firewall ==
** sudo apt install net-tools
+
* systemctl status firewalld
 +
* firewall-cmd --get-default-zone
 +
* firewall-cmd --set-default-zone=internal
 +
* firewall-cmd --get-services
 +
* firewall-cmd --permanent --add-service=http
 +
* firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.100 service name=mysql accept'
 +
* firewall-cmd --reload
 +
* firewall-cmd --list-services
 +
* firewall-cmd --list-all
  
== SSH ==
+
== SELinux ==
* sudo apt-get install openssh-server
+
* sestatus
* sudo vim /etc/ssh/sshd_config
+
* getenforce
* sudo service ssh restart
+
* setenforce
 +
* vi /etc/selinux/config
 +
* semanage port -a -t mysqld_port_t -p tch 3306
 +
* semanage port -l |grep mysqld
  
== Service ==
+
== Mount ==
* sudo systemctl status ssh
+
* mount /dev/cdrom /media
* sudo systemctl start ssh
+
* mount -o loop xxx.iso /media
* sudo systemctl stop ssh
+
* mount -t nfs filer01.corp.alphabook.cn:/Department /Department
* sudo systemctl restart ssh
+
* vi /etc/fstab
* sudo systemctl reload ssh
+
* filer01:/Department /Department nfs4 rsize=65536,wsize=65536,hard,tcp 0 0
* sudo systemctl enable ssh
+
* [http://www.alphabook.cn/index.php?title=Advanced#autofs autofs]
* sudo systemctl disable ssh
 
* sudo systemctl is-enabled ssh
 
* sudo systemctl is-active ssh
 
* sudo systemctl show ssh
 
  
== Process ==
+
== Permission ==
* top
+
* r=read=4 w=write=2 x=execute=1
* ps -aux | grep programname | grep -v grep
+
* u=user g=group o=other
* kill -9 pidnumber
+
* chmod 755 file01
 +
* chmod go+x file01
 +
* chown User01.Group01 file01
 +
* chgrp Group01 file01
  
== Firewall ==
+
== rpm & yum ==
 +
* rpm -ivh packagename-version-arch.rpm
 +
* rpm -qa
 +
* yum info samba
 +
* yum install samba
 +
* yum update samba
 +
* yum remove samba
 +
* yum update
 +
* yum group list
 +
* yum group info "Basic Web Server"
 +
* yum group install "Basic Web Server"
 +
* yum provides mysql
 +
* yum install epel-release
 +
* Change yum repository
 +
** yum install wget
 +
** cd /etc/yum.repos.d
 +
** mv CentOS-Base.repo CentOS-Base_bk
 +
** wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
 +
** yum makecache
 +
** yum update -y
  
== User and Group ==
+
== crontabs ==
 +
* yum install crontabs
 +
* systemctl status crond
 +
* systemctl enable crond
 +
* systemctl is-enabled crond
 +
* cat /etc/crontab
 +
* # Example of job definition:
 +
* # .---------------- minute (0 - 59)
 +
* # |  .------------- hour (0 - 23)
 +
* # |  |  .---------- day of month (1 - 31)
 +
* # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
 +
* # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
 +
* # |  |  |  |  |
 +
* # *  *  *  *  * user-name  command to be executed
 +
* Examples:
 +
** 0 3 * * * root /root/scripts/dailybackup.sh
 +
** */30 * * * root /root/scripts/dailybackup.sh
 +
* crontab /etc/crontab
 +
* crontab -l
 +
* chmod u+x /root/scripts/dailybackup.sh
 +
* ls -l /root/scripts/dailybackup.sh
 +
* cat /var/spool/mail/root
  
 +
== Advanced ==
 +
* [[Advanced]]
  
== Error: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable) ==
+
== Basic Ubuntu ==
* sudo rm /var/lib/apt/lists/lock
+
* [[Basic-Ubuntu]]
* sudo rm /var/cache/apt/archives/lock
 
* sudo rm /var/lib/dpkg/lock
 
* sudo dpkg --configure -a
 

Latest revision as of 14:06, 14 March 2019

Partition

  • /boot
  • /
  • swap

Hostname

  • hostnamectl
  • hostnamectl set-hostname Linux001

Network

  • ip address
  • vi /etc/sysconfig/network-scripts/ifcfg-eth0
  • BOOTPROTO=static
  • ONBOOT=yes
  • IPADDR=192.168.200.10
  • NETMASK=255.255.255.0
  • GATEWAY=192.168.200.1
  • DNS1=114.114.114.114
  • DOMAIN=corp.alphabook.cn
  • systemctl restart network
  • CentOS 7 NetworkManager Keeps Overwriting /etc/resolv.conf
    • Check DNS related configuration in /etc/sysconfig/network-scripts/ifcfg-ens32
  • ifdown eth0
  • ifup eth0
  • More bond

Time

  • timedatectl
  • timedatectl list-timezones | grep Asia
  • timedatectl set-timezones Asia/Shanghai
  • cat /etc/chrony.conf
  • Or ntp
  • systemctl stop chronyd.service
  • systemctl disable chronyd.service
  • yum install ntp
  • systemctl start ntpd.service
  • systemctl enable ntpd.service

Service

  • systemctl status ssh
  • systemctl start ssh
  • systemctl stop ssh
  • systemctl restart ssh
  • systemctl reload ssh
  • systemctl enable ssh
  • systemctl disable ssh
  • systemctl is-enabled ssh
  • systemctl is-active ssh
  • systemctl show ssh

Disk

  • df -h
  • fdisk -l
  • fdisk -l /dev/sda
  • more about fdisk

Firewall

  • systemctl status firewalld
  • firewall-cmd --get-default-zone
  • firewall-cmd --set-default-zone=internal
  • firewall-cmd --get-services
  • firewall-cmd --permanent --add-service=http
  • firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.100 service name=mysql accept'
  • firewall-cmd --reload
  • firewall-cmd --list-services
  • firewall-cmd --list-all

SELinux

  • sestatus
  • getenforce
  • setenforce
  • vi /etc/selinux/config
  • semanage port -a -t mysqld_port_t -p tch 3306
  • semanage port -l |grep mysqld

Mount

  • mount /dev/cdrom /media
  • mount -o loop xxx.iso /media
  • mount -t nfs filer01.corp.alphabook.cn:/Department /Department
  • vi /etc/fstab
  • filer01:/Department /Department nfs4 rsize=65536,wsize=65536,hard,tcp 0 0
  • autofs

Permission

  • r=read=4 w=write=2 x=execute=1
  • u=user g=group o=other
  • chmod 755 file01
  • chmod go+x file01
  • chown User01.Group01 file01
  • chgrp Group01 file01

rpm & yum

  • rpm -ivh packagename-version-arch.rpm
  • rpm -qa
  • yum info samba
  • yum install samba
  • yum update samba
  • yum remove samba
  • yum update
  • yum group list
  • yum group info "Basic Web Server"
  • yum group install "Basic Web Server"
  • yum provides mysql
  • yum install epel-release
  • Change yum repository

crontabs

  • yum install crontabs
  • systemctl status crond
  • systemctl enable crond
  • systemctl is-enabled crond
  • cat /etc/crontab
  • # Example of job definition:
  • # .---------------- minute (0 - 59)
  • # | .------------- hour (0 - 23)
  • # | | .---------- day of month (1 - 31)
  • # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
  • # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
  • # | | | | |
  • # * * * * * user-name command to be executed
  • Examples:
    • 0 3 * * * root /root/scripts/dailybackup.sh
    • */30 * * * root /root/scripts/dailybackup.sh
  • crontab /etc/crontab
  • crontab -l
  • chmod u+x /root/scripts/dailybackup.sh
  • ls -l /root/scripts/dailybackup.sh
  • cat /var/spool/mail/root

Advanced

Basic Ubuntu