All work in the Linux command line, in other words, work in the Linux console is done either directly from the keyboard or through remote access to the server via SSH, by the way, to connect to the server remotely via SSH through Putty, I have written a detailed instruction: Instructions for Putty and PSCP
This article lists the most common console commands, grouped by category:
pinfo bash - A convenient info replacement.
chmod -R 741 /var/www/files Change the permissions recursively throughout the files folder to rwx r-----x, where: 4 read (r), 2 write (w), 1 execute (x).
find /usr/bin -type f -mtime -10 - Find all the files in '/usr/binCreated or modified within the last 10 days.
find /usr/uplifto \( -name *.htm -o -name '*.html' \) -exec enconv -V --convert-to=UTF-8 {} \; Convert the found files to the correct encoding.
Setting up
~/.bashrc Global setting (alias pya='ping -c4 ya.ru') and running programs at the initial entrance, and each time you open the console.
~/.bash_profile - Applies only when logging in, auto-run user applications.
~/.bash_logout - Executing scripts on exit.
Hot keys.
«Esc+.» Insert the last argument of the previous team (life simplifies). "Alt+." Same thing.
«Shift+PgUP» - View the output beyond the screen.
«Ctrl+Z» Transfer the current task to the background $ fg x return the process (where x=1-...), and $ xxx & run the program in the background.
«Ctrl+R» Search history, to search click several times "Ctrl+N" - in the opposite direction.
«Ctrl-U» - Cuts everything to the left of the cursor, and "CTRL+Y" inserts.
«Ctrl-K» - Removes everything to the right of the cursor.
«ALT-B» Go back to the word and forward to ALT-F.
Scripting.
'' - Strong quotation marks, convey an uninterpreted value.
` - Reverse quote, perform the contents of brackets, the same as $().
” Double quotation marks, substitution of variables and prevention of word break-up.
ping -c1 ya.ru ; echo "host" - Ping ya.ru, then just post a message.
ping ya.ru || echo «bad host» - Ping ya.ru, in case of failure to output the message.
ping ya.ru && echo «ok host» - Ping ya.ru, if successful, output a message.
& - (Ampersand)
| - Straight line.
> - Redirect output to file.
>> - Fill it at the end of the falter.
&> - Both outputs in the same file.
2> - Putting only errors into the file.
echo $? View the command output status (not 0 = error).
$! PID of the last running process in the background.
$1, $2, $3 - Direct, second and aunt arguments transmitted to the program.
$@ Each of the arguments given to the program.
$# - Number of arguments.
Working with a hard drive
Hard disk performance is limited by the “average access time” usually 8 ms, and the performance limit is considered P=1000/8*0.85=106 disk calls if the system overstates this parameter, creates a queue to the disk, and the performance of the disk subsystem begins to fall exponentially. See iostat, tps column. Read speed: RAID10 = RAID5 NxP > RAID0 = RAID1 NxP> HDD, where N is the number of disks. 3x106=318 > 2x106=212 > 106 Write speed: RAID0 NxP > RAID10 N/2xP > RAID1 = HDD = RAID5.
/boot The kernel file is stored here – usually named vmlinuz (usually configured by grub and deleted from the kernel file). /etc/fstab)
/bin Minimum system performance programs;
/lib - library C;
/opt - support programmes;
/proc - images of the processes being carried out;
/root - the initial root catalog;
/mnt - replaceable media are mounted here (floppy, cd-rom, flash, etc.);
/dev - a catalog of devices;
/etc Catalog of configuration files
/tmp - a catalog of temporary files;
/usr a directory of most standard programs and components;
/var - catalog of log storage, buffer directories;
/var/log - Logic.
/home - a catalog of home directories of users.
Status of the disk subsystem
df -h - Shows the employment of all disks (including mounted).
du -smc --exclude={proc,sys,dev} /* | sort -g We get a sorted list of the heaviest directories in megabytes.
du -hs /xxx - Determine the space occupied by the file / folder on the hard disk.
du -hs /var/* - And so you can quickly find the culprit of the crowded disk (I would be glad if you tell me a more elegant way):
hdparm -tT /dev/sda Testing the performance of the disk, it can also fine-tune the performance (usually not necessary, because. modern systems correctly determine the parameters, if you really want to, then on Opennet.ru
dd if=/dev/sdx of=/dev/null bs=1m - It's kind of like detecting disc problems.
hddtemp /dev/sd[a-z] - Hard disk temperature in the system (lab.<60°C)
Disk markup
Disk markup is essentially a record (at the very beginning of the disk) about where and what partitions are physically located on the disk. Ie. By editing the partition table, the data (located on the hard disk) remains intact.
sfdisk -uM -l /dev/sda Disk partition information (-uM) in megabytes.
partprobe - Informs the axis about changes in the partition table.
cat /proc/partitions Table of partitions with which the kernel works.
mkfs.ext3 -L fsroot /dev/sda6 - Create ext3 section with the "fsroot" libel.
tune2fs -L fsroot /dev/sda6 Assign a "fsroot" disk libel, for ease of mounting or e2label /dev/sda6 fsroot.
blkid - Displays attributes (libel) of block devices.
mount LABEL=fsroot /mnt/data - Label montage.
sfdisk -d /dev/sda | sfdisk /dev/sdb Copying the partition table from sda to sdb.
sfdisk -d /dev/sda > sda.mbr.bak Copy mbr into a file (file can be edited).
sfdisk /dev/sda < sda.mbr.bak - Recovering mbr from the file.
dd if=/dev/sda of=/root/sda.mbr.img bs=512 count=1 Copying mbr into a file is the most reliable way.
dd if=/dev/zero of=/dev/hda bs=512 count=1 - Clean the mbr (carefully!). If there is no partition table, then bs = 446
Swap
Create a swap file instead of a partition. Provides flexibility in disk resources management (LVM, RAID, XEN). Usually a swap is equal to the amount of RAM, after 2GB it is not relevant. First, create a file filled with zeros of the required size (we have 1 GB), mark the file as a swap, turn on:
dd if=/dev/zero of=/swapfile bs=1024 count=1048576 mkswap /swapfile swapon /swapfile
Checking:
free -m total used free sharedbuffers cached Mem: 520510 10 0 1372 -/+ buffers/cache:136384 Swap: 1023 0 1023
Where is 1023 volume of swap available to the system. Thus, you can add another swap file, the volume of which will be added to the current one, or disable (swapoff). All you have to do is add a line to the file. /etc/fstab:
/swapfile swap swap defaults 0 0
Disc image
Bit copying partition with subsequent packaging, I use for backup of freshly configured systems:
dd if=/dev/sda2 conv=sync,noerror bs=16M | gzip -c > /mnt/bak/sda1.img.gz
Mounting
mount -t cifs //192.168.0.122/data /mnt/amigoglobal/data -o user=USER,pass=PASSWORD -mounting of wind sections
mount -o loop /mnt/bak/disk/LiveCD/newcd/live.iso /mnt/cdrom/
mount.nfs 192.168.0.1:/mnt/raid0/date5 $BAKTARGET -n -o ro
mount -a - Mount everything from fstab, when adding resources, e.g.
cat /proc/mounts - Detailed information about the installed devices. Elsy needs a short, then df -h.
fuser -v /opt - Find out who's borrowing the resource. For example, if it does not allow to unmount.
fuser -km /opt - Forced removal of the section.
mount -o remount,rw /dev/sda1 / - Rewire it. For example, when changing options.
umount -l /dev/sdb1 - Unmount when the resource is free.
LVM
pvcreate /dev/md1 - Let's label the disc as a physical volume.
vgcreate -s 128M VG /dev/md1 - We're setting up a tome group.
lvcreate -l 100%FREE -n bak VG Create a logical volume for all available space.
mkfs.ext3 /dev/VG/bak - We're building a file system.
lvresize -L +10G /dev/VG/date1 - Adds 10 GB to the logical volume, if they are present in a physical volume.
resize2fs /dev/VG/date1 Expand the location section to all available space (for ext3).
Disc image
dd if=/dev/zero of=/null bs=1024 ; rm -f /null clog free space on the disk with zeros so that dd garbage does not save, and immediately remove.
dd if=/dev/sda2 bs=16M | gzip -c > /mnt/bak/sda2.img.gz where bs=16M is the size of the hard drive. Bit copying of the partition with subsequent packaging, I use for backup of freshly configured systems (copy together with file debris, but reliably).
gunzip /mnt/bak/sda2.img.gz | dd of=/dev/sda2 bs=16M - Recovery from the compressed image.
dd if=/dev/hda bs=64K | gzip -c | ssh user@hostname "dd of=hda.img.gz bs=64k"
dd if=hda.img.gz | ssh -c blowfish user@deadhost "gunzip -c | dd of=/dev/hda1 bs=64k"
RAID
For starters, we implement RAID 1, i.e. a disk subsystem with 100% redundancy and double the read speed, for SOHO you can not think of better.
Installation
It is better to implement at the installation stage of the system, if the system is already functioning, then here you go. We take two screws, preferably the same, but not critically, it is more important to create the same partitions on them. During the installation of the system, we create (attention!) a primary sda1 ext2 partition with a volume of 100 MB (more than enough), then create a RAID partition for the 4000 MB system usually enough, on the remaining disk we also create a RAID partition. We do the same for the second screw (if it is Fedora 9, then pressing the RAID button has a markup cloning function). We get two screws with the same marking of this type:
100M 4GB54Gb
sda1 sda1 sda2
sda[-ext2-|----RAID----|----------RAID----------]
sdb1 sdb1 sdb2
sdb[-ext2-|----RAID----|----------RAID----------]
Next, create RAID devices: md0 = sda1+sdb1 > RAID1 > ext3 > / (root file system) and md1 = sda2+sdb2 > RAID1 > ext3 > /mnt/foo Install on all this good we need the system (recommend CentOS in a minimum configuration without X-s, the necessary then deliver). After the first download, edit grub and generally everything that lies in /bootAnd we make a copy on the second hard drive:
dd if=/dev/sda1 of=/dev/sdb1
Copy the MBR with the command:
dd if=/dev/sda of=/dev/sdb bs=512 count=1
All right, we got a fail-safe system.
Testing
Checking. Without turning off the PC, turn off power (not date cable, harm is possible) sdb. We see that everything is working as if nothing had happened. Reboot, load bios, MBR, /bootRAID 1 (half-dead), system. In this mode, the system can work for a long time, but the safety of information is no longer guaranteed.
Reconstruction
The sacred meaning of RAID recovery is to connect the missing sdb1 (partition equal in size to sda1) to md0. Turn off the PC (without a reboot, no new hard drive will be determined), connect a new hard drive, turn on, create the desired partition as RAID. Start the recovery process and observe (perhaps for a very long time):
mdadm -a /dev/md0 /dev/sdb1 watch cat /proc/mdstat
Theoretically, you can work with the system in the process of recovery, but it is not desirable (it is drowsy). After completion, you can work calmly.
System system
Filework
tar -cjvf /root/etc_`date '+%Y-%m-%d'`.tar.bz2 /etc - (c)Pack in the (f)tar archive and (j)compress the bzip2 folder /etc c the current date in the file name, with (v) a detailed output.
tar-xzvf /home/user/Downloads/centerim-4.22.6.tar.gz -S. /opt/ (x) Unpack the (z)gzip archive in /opt
cat /etc/c-icap.conf | grep -v "#" | sed -e '/^ *$/d' - Show the file without comments and empty lines.
chattr +Sai (S)Add attributes to the file, synchronously change all data to the disk, without caching; (a) only the addition of data, deletion and renaming is prohibited; (i) deletion, alteration or renaming is prohibited;
ls -f1 /var/log/packages/ | wc -l - Put out the number of lines.
diff -y httpd.conf httpd.con.new - Two-column comparison.
diff -u httpd.conf httpd.con.new Unified comparison (in one column, but readable). I recommend colordiff.
Programme management
0-59 20,22 * * 1-5 root bak.sh - Enter in. /etc/crontab This means that bak.sh will be performed every minute from 20:00 to 20:59 and from 22:00 to 22:59 every day from Monday to Friday.
yum install xxx -y - Installation of the program from the repository.
yum list - Output of all packages (checking the operability of the repository).
yum search foo - Looks for the specified line in the name of the package and its description.
yum check-update - View available updates.
yum update foo fi - Update only the foo and fi packages.
rpm -iv xxx - The package setup.
yum whatprovides /usr/sbin/epstopdf - search for a poket name, file by file.
yum localinstall foo Installing a package from a file, not a repository Dependencies are resolved from the repository.
User management
adduser -r munin - Add a system user.
vipw - The editor blocks the file. /etc/passwdSo that other teams don’t try to modify it at the same time.
Networks.
Protocol stack level Protocols Heading 3
Applied DHCP, SSH, SMTP, HTTP, FTP, DNS line 1, cell 3
Transportation TCP (segment), UDP, RTP, SCTP, DCCP line 2, cell 3
Internetwork (network) For TCP/IP, it is IP (IPv6) (assistant protocols like ICMP and IGMP run over IP but are part of the network layer). ARP does not work over IP) line 2, cell 3
Channel (access level) Ethernet (frame), Token ring, PPP, IEEE 802.11 Wi-Fi, ISDN line 2, cell 3
Physically Physical environment and principles of information coding, electricity, radio, laser line 2, cell 3
Installation
neat-tui - Text wizard installation network RHEL-like (recommended).
system-config-network-tui - It's him.
ethtool ethX - Network card information/setting (speed and connection type)
ifconfig ethX hw ether xx:xx:xx:xx - Changing the Mac Address of a Network Card (Before Rebooting)
Configuration files
RedHat and its clones:
/etc/sysctl.conf For packet routing in net.ipv4.ip_forward = 1
/etc/sysconfig/networking/devices/ifcfg-eth0 - Interface configuration file (/etc/sysconfig/network-scripts/ifcfg-eth0 - a rigid reference to the same)
/etc/resolv.conf DNS server provider (you can also specify in the config above DNS{1,2}=ddress>, it is a priority).
/etc/network - Prescribe the name of the car.
/etc/sysconfig/network-scripts/route-eth0 - Static routing file, with syntax: 192.168.124.0/24 via 192.168.0.220 dev eth0 or:
ADDRESS0=192.168.124.0 NETMASK0=255.255.255.0 GATEWAY0=192.168.0.220
Debian and its clones:
/etc/hostname - Prescribe the name of the car.
/etc/network/interfaces - Network settings file
Local interface:
auto lo iface lo inet loopback
Network card with static IP:
auto eth0
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
The network card receives IP by dhcp:
auto eth1 iface eth1 inet dhcp
Monitoring
ifconfig - Output of all network configurations.
netstat -nnnl - Lists open sockets (ports) in the local system.
netstat -ta - List of established connections.
lsof -i -n List of open ports and connections.
arp - Output of the arp table (necessary to find out physical availability in the network, or find out the MAC address of a neighbor). Kosher ip neigh (or ip n).
tcpdump -vvvnnni eth0 not port ssh and not 3389 and not 80 and not 5191 and not 443 and not 53 and not 2222 and not 5223 and not udp port 5001 - Looking for unfamiliar traffic on the network.
ip route add 192.168.124.0/24 via 192.168.0.220 - Add a route (before rebooting).
ip addr add 192.168.0.100/24 dev eth0 Add the IP address to the interface (before rebooting).
tracert -i eth3 ya.ru Track through a specific interface (to debug the route).
Network services
rdesktop 192.168.0.1 -u admin -p 'pass' -fzPa8 -k ru - Connecting a c-RDP server with compression, caching, full screen, with Russian layout. Exit from the terminal
ssh -L5555:192.168.0.10:80 [email protected] After the connection is established, local port 5555 will be dropped at 192.168.0.10:80
pdsh -w root@host-0[1-7,10] uptime Execute the command uptime on hosts 1 to 7 and 10. The ssh key entry must be pre-configured.
pdcp -w root@host-0[1-7,10],root@otherhost /home/user/.vimrc /root/ Copy the local .vimrc file into a folder /root on remote hosts. The pdsh must be installed on all hosts.
Testing
Run a server in UDP with output once per second, on port 65005:
iperf -us -i1 -p 65005
Testing UDP with a length of 100b with a bandwidth of 20k for 180 seconds:
iperf -uc 83.239.146.78 -l100 -b20k -t180
Send 10 megabytes to port 65005:
iperf -n 10m -p 65005 -c 192.168.0.254
I was with you. Sergey Lazarenko
Take a break from work and watch a useful SEO video - How blog links work:




comment