คำสั่งพื้นฐาน CentOS 7

ทำ user ให้เป็น root

user ที่จะใช้คำสั่ง sudo ได้ ต้องอยู่ใน sudoers file ก่อน ด้วยคำสั่ง wheel (แทนค่า “username” ด้วย user ที่ต้องการ)

$ usermod -aG wheel username

เสร็จแล้วตรวจสอบด้วยคำสั่ง whoami ถ้าได้ root ก็เป็นอันเสร็จ

$ sudo whoami

โปรแกรมน่าติดตั้ง

$ sudo yum install net-tools
$ sudo yum install wget
$ sudo yum install tree
$ sudo yum install nano

ถ้าจะ uninstall package ใช้คำสั่ง

sudo yum remove package_name 

เรื่องของ yum.repos.d

พาท /etc/yum.repos.d/

ตัวอย่างการเพิ่มด้วย curl

sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo

หรือ

sudo curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo

ตัวอย่างการเพิ่มด้วย sh

sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'

จะได้

$ cat /etc/yum.repos.d/vscode.repo
[code]
name=Visual Studio Code
baseurl=https://packages.microsoft.com/yumrepos/vscode
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc

ดู repository ทั้งหมด

yum repolist all | grep mysql

ดู repository เฉพาะที่ enabled

yum repolist enabled | grep mysql

ifconfig

ifconfig equivalent

ip addr

ติดตั้ง net-tools เพื่อใช้คำสั่ง ifconfig

yum install net-tools

แล้วก็ใช้ netstat

netstat -antp

update

sudo yum update

ถ้ามี error during download metadata for repository ให้แก้ไขโดยเปิดไฟล์ /etc/sysconfig/network-scripts/ifcfg-eth0 แล้วให้ค่า ONBOOT=yes (Ref)

View All the Host Names

hostnamectl

หรือ

hostnamectl status

Set All the Host Names

# hostnamectl set-hostname name

Configure Static IP Address

เดิมค่า BOOTPROTO=dhcp เปลี่ยนเป็น BOOTPROTO=static แล้วเพิ่ม IPADDR และ NETMASK

# vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
BOOTPROTO=static
IPADDR=192.168.56.2
NETMASK=255.255.255.0
ONBOOT=yes

Restart the network services 

sudo service network restart

To verify the IP address

$ ip -br a

ไฟล์ ifcfg-enp0s8 หาย!!!

หาค่า UUID

$  nmcli con show
NAME                UUID                                  TYPE      DEVICE
Wired connection 1  bdcfff16-3517-32ef-8bbe-67ea15cb8bce  ethernet  enp0s8
virbr0              7c1d8308-5525-4ca9-8e1f-33d282de91fd  bridge    virbr0
enp0s3              6f0e07f5-2060-45ad-b7c0-b180974c04c5  ethernet  --

สร้างไฟล์ /etc/sysconfig/network-scripts/ifcfg-enp0s8 แล้วกำหนดค่าต่างๆ

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.56.105
NETMASK=255.255.255.0
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s8
UUID=bdcfff16-3517-32ef-8bbe-67ea15cb8bce
DEVICE=enp0s8
ONBOOT=yes

Restart the network services 

sudo service network restart

ติดตั้ง Git

Install Git with Yum

sudo yum install git
$ git --version
git version 1.8.3.1

Set Up Git

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --list