Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux basic Operation instruction Manual-Unix/Linux Technical document (1)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Finally, I have time to sort out my own technology in Unix/Linux for many years. Today, I send a Linux basic operation document, which is the second half of the previous Linux installation instruction manual. It is also a training document for the company. By the way, it is also sent to the blog to share with you, in return for the guidance and promotion of previous teachers and seniors. Like you, I will always share all of myself and realize your ideals. Our common ideal.

Disclaimer: this document is for reference only, please operate according to the actual environment, the author and this document are not responsible for any consequences.

I. explanation

1. Operating system: CentOS-5.6-x86_64

2. It is the second half of the previous Linux installation manual.

II. Basic operation of Linux

1. View the system version

[root@ctcdb01] # lsb_release-a LSB Version:: core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 5.6 (Final) Release: 5.6 Codename: Final 2, View cpu information to view CPU model [root@ctcdb01 ~] # less / proc/cpuinfo | grep "model name" model name: Intel (R) Core (TM) i3 CPU 530 @ 2.93GHz model name: Intel (R) Core (TM) i3 CPU 530 @ 2.93GHz for more information about CPU [root@ctcdb01 ~] # more / proc/cpuinfo processor: 0 vendor_id: GenuineIntel model name: Intel (R) Core (TM) i3 CPU 530 @ 2.93GHz stepping: 5 cpu MHz : 2926.059 cache size: 4096 KB physical id: 0 flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc nonstop_tsc arat pni ssse3 cx16 sse4_1 sse4_2 popcnt lahf_lm

Processor will count from 0 and continue to count multiple cpu.

To judge the number of physical CPU, you can check the value of physical id, and the same is the same physical CPU.

Flags supports hyper-threading technology if there is ht.

3. View and set the system language

(1) View the system language

[root@localhost ~] # cat / etc/sysconfig/i18n LANG= "zh_CN.UTF-8" (2), set the system language # cp / etc/sysconfig/i18n $HOME/.i18n to modify the $HOME/.i18n file, such as LANG= "en_US" # xwindow will display the English interface. LANG= "zh_CN.GB18030" # xwindow will display the Chinese interface. 4. View and set IP address information (1), View IP information [root@ctcdb01 ~] # ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:BD:BE:80 inet addr:172.18.2.60 Bcast:172.18.2.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:3903 errors:0 dropped:0 overruns:0 frame:0 TX packets:1260 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:374577 (365.7 KiB) TX bytes: 1126921 (1.0 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:1326 errors:0 dropped:0 overruns:0 frame:0 TX packets:1326 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2389027 (2.2 MiB) TX bytes:2389027 (2.2 MiB) (2), Set (modify) IP address # / etc/sysconfig/network-scripts/ifcfg-eth0 # modify IP address # service network restart # restart network service 5, view and set computer name (1), view computer name [root@ctcdb01 ~] # hostname ctcdb01 (2), set (modify) computer name modify the following two files. # cat / etc/sysconfig/network # modify HOSTNAME one behavior HOSTNAME= wants the computer name NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=ctcdb01 GATEWAY=172.18.2.1 # cat / etc/hosts 127.0.0.1 localhost.localdomain localhost # this is 127.0.0.1 special IP, cancel the computer name before "localhost.localdomain localhost" 172.18.2.60 ctcdb01 # add this line 6, modify DNS

Modify the corresponding IP of / etc/resolv.conf file to [root@ctcdb01 ~] # cat / etc/resolv.conf nameserver 172.18.2.124 nameserver 202.96.209.57, modify the gateway

Modify the corresponding IP of / etc/sysconfig/network file to [root@ctcdb01 ~] # cat / etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=ctcdb01 GATEWAY=172.18.2.1

8. View and monitor the utilization of hard disk partitions

(1) View the hard disk partition. [root@ctcdb01] # fdisk-l Disk / dev/sda: 42.9 GB, 42949672960 bytes 255heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System / dev/sda1 * 1 13 104391 83 Linux / dev/sda2 145221 41833260 8e Linux LVM see the hard disk information of this system is as follows: 1. A 40G SCSI hard disk is roughly described by 42.9GB. The hard disk capacity generally seen here will be reduced, that is, the hard disk manufacturer changes the capacity conversion unit 1M=1024K to 1M=1000M 2 for convenience. The hard disk is divided into 2 zones / dev/sda1 is Linux partition and the mount point is / boot You can use the df-h command to view / dev/sda2 for Linux LVM management (2), Check hard disk space utilization [root@ctcdb01] # df-h File system capacity available available mount point / dev/mapper/VG00-LV00 20g 3.1g 16G 17% / / dev/mapper/VG00-LV02 18G 173m 17G 1% / home / dev/sda1 99m 13m 82m 14% / boot tmpfs 501m 0501m 0% / dev/shm / dev/sda2 partition creates a volume group called VG00 Three more LV are divided on VG00: LV00~03 LV01 is the swap partition swap The system starts and mounts by default. You can view / etc/fstab file [root@ctcdb01 ~] # cat / etc/fstab / dev/VG00/LV00 / ext3 defaults 1 1 / dev/VG00/LV02 / home ext3 defaults 12 LABEL=/boot / boot ext3 defaults 12 tmpfs / dev/shm tmpfs defaults 00 devpts / dev/pts devpts gid=5,mode=620 00 sysfs / sys sysfs defaults 00 proc / proc proc defaults 00 / dev/VG00/LV01 swap swap defaults 00 9, view memory and swap

(1) View memory $grep MemTotal / proc/meminfo MemTotal: 1047188 kB $grep SwapTotal / proc/meminfo SwapTotal: 1572856 kB (2), View available memory and Swap: view memory under Linux We usually use the free command, free-m is displayed in MB, and the readability is better [[root@ctcdb01 ~] # free-m total used free shared buffers cached Mem: 1001 435566 027 294-/ + buffers/cache: 112889 Swap: 1535 1535

10. Use Top command to monitor system load

The statistics for the first five lines of [root@ctcdb01 ~] # top # are as follows: top-01:06:48 up 1:22, 1 user, load average: 0.06,0.60,0.48 Tasks: 29 total, 1 running, 28 sleeping, 0 stopped, 0 zombie Cpu (s): 0.3% us, 1.0% sy, 0.0% ni, 98.7% id, 0.0% wa, 0.00% hi, 0.00% st Mem: 1025944k total, 444872k used, 581072k free, 27832k buffers Swap: 1572856k total, 0k used 1572856k free, 301976k cached top commands are commonly used performance analysis tools under Linux. It can display the resource consumption of each process in the system in real time, similar to the task manager of Windows. How to use it is described in detail below. The first line is the task queue information, which is the same as the execution result of the uptime command. The contents are as follows: 01:06:48 current time; up 1:22 system elapsed time, in the format of hours: minutes; 1 user currently logged in users; load average: 0.06,0.60,0.48 system load, that is, the average length of the task queue. The three values are the average values from 1 minute, 5 minutes and 15 minutes ago to the present. The second is the process information, Tasks: 29 total total processes; 1 running running processes; 28 sleeping sleep processes; 0 stopped stopped processes; 0 zombie zombie processes. The third line is the CPU information, 0.3% us user space occupies CPU percentage; 1.0% sy kernel space occupies CPU percentage; 0.0% ni user process space occupies CPU percentage that has changed priority; 98.7% id idle CPU percentage; 0.0% wa waits for input and output CPU time percentage; 0.0% hi; 0.0% st; the last two behavior memory information. Mem: total physical memory of 1025944k total; total physical memory used by 444872k used; total free memory of 581072k free; total memory of 27832k buffers used as kernel cache; Swap: total amount of 1572856k total swap area; total number of swap areas used by 0k used; total 1572856k free free swap area; total 301976k cached buffer swap area The contents of the memory are swapped out to the swap area, and then swapped into memory, but the used swap area has not been overwritten, and this value is the size of the swap area where these contents already exist in memory. When the corresponding memory is swapped out again, there is no need to write to the swap area.

11. Use iostat to view the hard disk Ibank O read and write load

[root@ctcdb01 ~] # which iostat # if there is no iostat, refresh yum install sysstat / usr/bin/iostat [root@ctcdb01 ~] # iostat-x 1 2 # every second Total execution of Linux 2.6.18-238.el5 (ctcdb01) on July 26, 2011 avg-cpu:% user% nice% system% iowait% steal% idle 0.10 0.00 0.22 0.57 0.00 99.11 Device: rrqm/s wrqm/s r Unix s rsec/s wsec/s avgrq-sz avgqu-sz await svctm% util sda 4.32 1.67 2.96 1.04 246.80 21.69 67.01 0.16 39.82 7.14 2.86 sda1 0.32 0.00 0.02 0.00 0.70 0.00 27.15 0.00 7.39 5.91 0.02 sda2 3.99 1.67 2.93 1.04 246.00 21.69 67.34 0.16 40.09 7.17 2.85 dm-0 0.00 0.00 6.70 2.71 244.22 21.66 28.25 0.79 84.22 3.00 2.83 dm-1 0.00 0.00 0.15 0 .00 1.20 0.03 7.99 0.00 10.70 1.24 0.02 dm-2 0.00 0.05 0.00 0.38 0.00 8.00 5.82 0.52 0.00 hdc 0.00 0.00 0.05 16.00 89 7.11 6.22 0.00 avg-cpu:% user% nice% iowait% steal% idle 0.00 0.00 .00 0.00 100.00 Device: rrqm/s wrqm/s r sda2 s rsec/s wsec/s avgrq-sz avgqu-sz await svctm% util sda 0.00 0.00 0.00 . 00 0.00 0.00 0.00 dm-0 0.00 0.00 0.00 dm-1 0.00 0.00 0.00 dm-2 0.00 0.00 0.00 0 .00 0.00 0.00 hdc 0.00 0.00 0.00 rrqm/s: the number of merge reads per second. That is, delta (rmerge) / s wrqm/s: the number of merge writes per second. That is, delta (wmerge) / s rstroke s: the number of times to read the iUnip O device per second. That is, delta (rio) / s wplink s: the number of times the write Icano device has been completed per second. That is, delta (wio) / s rsec/s: read sectors per second. Delta (rsect) / s wsec/s: the number of sectors written per second. That is, delta (wsect) / s rkB/s: read K bytes per second. Is half the rsect/s because the size of each sector is 512 bytes. (need to calculate) wkB/s: write K bytes per second. It's half of wsect/s. (need to be calculated) avgrq-sz: the average data size (sector) per device Imax O operation. Delta (rsect+wsect) / delta (rio+wio) avgqu-sz: the average length of the queue. That's delta (aveq) / aveq 1000 (because it's in milliseconds). Await: the average wait time (in milliseconds) for each device Istroke O operation. That is, delta (ruse+wuse) / delta (rio+wio) svctm: the average service time (in milliseconds) for each device Icano operation. That is, delta (use) / delta (rio+wio)% util: how many percent of the time in a second is spent on the Icano operation, or how much time in a second the Icano queue is not empty. That is, delta (use) / use 1000 (because the unit of use is millisecond) if the% util is close to 100%, it means that there are too many Imax O requests, the Imax O system is full, and there may be a bottleneck on the disk. When the idle is less than 70%, the IO pressure is higher, and generally the read speed has more wait. 12 、 Use vmstat to view virtual memory (Virtual Memory) usage [root@ctcdb01 ~] # vmstat 2 # output a result procs-memory--swap---- io- system-----cpu---- every 2 seconds -r b swpd free buff cache si so bi bo in cs us sy id wa st 00 0 517096 29988 355984 00 28 2 208 16 00 99 00 517096 29988 355984 00 00 820 49 00 100 00 0517096 29988 355984 00 841 50 00 00 00 0517096 29996 355976 00 014830 5700 00 10000

Procs (processes): r: number of processes in the run queue b: number of processes waiting for IO

Memory (memory): swpd: use virtual memory size free: available memory size

Buff: size of memory used as buffer cache: size of memory used as cache

IO: (now the size of the Linux version block is 1024bytes)

Bi: blocks read per second bo: blocks written per second

System: in: interrupts per second, including clock interrupts. Cs: context switches per second.

CPU (as a percentage):

Us: user process execution time (user time) sy: system process execution time (system time)

Id: idle time (including IO waiting time) wa: waiting time for IO

[root@ctcdb01] # vmstat-a 2 # shows active and inactive memory procs-memory--swap--io- system---cpu- r b swpd free inact active si so bi bo in cs us Sy id wa st 300 487020 303296 174940 00 26 3 208 220 0 99 1 0 1 00 485976 303304 174864 00 244 0856 2220 8 73 9 0 1 00 486004 303292 175352 00 188 212 834 1750 87 00 1 0485396 303312 175644 00 20863 2075 99 749 0 when using the-an option to display active and inactive memory The display shows the same field description as vmstat 2 except inact and active, and outputs the same field description: Memory (memory): inact: inactive memory size (displayed when using the-an option) active: active memory size (displayed when using the-an option)

13. Restart and shutdown

Before restarting and shutting down, check to see if there are any other users using [root@ctcdb01 ~] # who oracle pts/1 2011-07-26 14:15 (172.18.2.2) oracle pts/2 2011-07-26 15:18 (172.18.2.82) root pts/6 2011-07-26 12:35 (172.18.2.159) Please notify the user, save the shutdown program, log in and restart [root@ctcdb01 ~] # sync;sync After init 6 # synchronizes the cache content to the hard disk, restart or shut down [root@ctcdb01 ~] # sync;sync;sync;reboot # restart, which is almost the same as shutdown-r now [root@ctcdb01 ~] # shutdown-r shutdown [root@ctcdb01 ~] # sync;sync Init 0 # prevents the loss of data that has not been written to the hard disk [root@ctcdb01 ~] # poweroff # shutdown [root@ctcdb01 ~] # shutdown [root@ctcdb01 ~] # halt # halt is to call shutdown-h although the current shutdown/reboot/halt and other instructions have already made a call to the sync tool before shutting down, it is always more reassuring to do it a few more times ~ hehe ~

III. Initial configuration

1. System environment variable setting

Because CenterOS does not add two paths to PATH=$PATH:/sbin:/usr/sbin by default, some system commands cannot be found when using the system later. Log in to the system with root administrator privileges to set the shell environment variable, edit the file / etc/profile, and add: PATH=$PATH:/sbin:/usr/sbin in front of export PATH USER LOGNAME MAILHOSTNAME HISTSIZE INPUTRC, as follows: [root@ctcdb01 ~] # vi / etc/profile PATH=$PATH:/sbin:/usr/sbin [root@ctcdb01 ~] #. / etc/profile # use the "point" or "sourse" command to make the environment variable take effect

two。 Close the graphical interface to save resources

Log in to the graphical interface, check normal, and close the graphical interface to save resources. # runlevel # View the current runlevel N 5 # vi / etc/inittab id:5:initdefault: # change this line from 5 to 3 to close the graphical interface # reboot # restart it. Because it starts the default is a graphical interface, we install Oracle, the future is the server side, do not need a graphical interface; then the graphical interface it has programs running in memory, occupying a lot of memory, consuming precious CPU, so it is generally turned off. 3. SSH configuration

(1) modify the port and disable root login

Remote SSH login system, edit / etc/ssh/sshd_config file, modify SSH port to 2225. Find the section # Port 22. Here, the logo uses port 22 by default, which is modified as follows: [root@ctcdb01 ~] # vi + / PermitRoot / etc/ssh/sshd_config Port 22 Port 2225 # and then add the SSH port to 2225. The yes in the line PermitRootLogin no # PermitRootLogin yes is modified to no to restart the SSH service [root@ctcdb01 ~] # service sshd restart so that the SSH port will work simultaneously and verify whether the modified port is successful on 22 and 2225 [root@ctcdb01 ~] # lsof-iRanger 2225 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME sshd 22520 root 3u IPv4 59074 TCP *: 2225 (LISTEN) [root@ctcdb01 ~] # [root@localhost ~] # netstat-an | grep 2225 tcp 00: 2225:: : * LISTEN tcp 0 52:: ffff:172.18.1.160:2225:: ffff:172.18.2.159:50257 ESTABLISHED

(2) add the newly modified port to the firewall

Since the firewall is enabled, after modifying the SSH port, you need to add the new SHH port to the iptables configuration file [root@ctcdb01 ~] # cp / etc/sysconfig/iptables / etc/sysconfig/iptables.bak [root@ctcdb01 ~] # vi / etc/sysconfig/iptables # plus the following line-A RH-Firewall-1-INPUT-p tcp-m state-- state NEW-m tcp-- dport 2225-j ACCEPT save exit, you can copy the line of SSH port 22 Just change the port to 2225. [root@ctcdb01 ~] # service iptables restart clear firewall rules: [OK] set chains to ACCEPT policy: filter [OK] uninstall Iiptables module: [OK] apply iptables firewall rules: [OK] load additional iptables module: ip_conntrack_netbios_ns [OK] # iptables-L-n # View firewall rules (3), Check whether to open an account to start [root@ctcdb01 ~] # chkconfig-- list sshd # generally enable level 35 sshd 0: close 1: close 2: enable 3: enable 4: enable 5: enable 6: now please use the ssh tool to connect port 2225 To test for success. If the connection is successful, edit the configuration of sshd_config again and comment or delete the Port22 inside. The reason why it is configured into two ports first, and then closes one port after a successful test, is that in the process of modification, in case of unknown circumstances such as disconnection, disconnection, misoperation and so on, it can also be connected to another port for debugging. In case the connection fails, someone must be sent to the computer room, which makes the problem more complicated and troublesome. 4. Basic firewall configuration (take ftp as an example) (1) configure ftp service first. After installing CentOS, you need to set up the Ftp service file before you can start Ftp and enter / etc/xinetd.d. Edit the ftp service configuration file gssftp: [root@ctcdb01 ~] # cp / etc/xinetd.d/gssftp / etc/xinetd.d/gssftp.bak [root@ctcdb01 ~] # vi / etc/xinetd.d/gssftp # to modify two items: 1) server_args =-l-a remove-a to server_args =-l 2) change disable=yes to disable=no 3) Save exit. Ftp is hung under the xinetd. So as long as you reactivate xinetd, you can re-read the settings in xinetd [root@ctcdb01 ~] # service xinetd restart stop xinetd: [OK] start xinetd: [OK] (2), Add ftp port [root@ctcdb01 ~] # iptables-I INPUT-p tcp-- dport 21-j ACCEPT [root@ctcdb01 ~] # iptables-I INPUT-p tcp-- dport 21-j ACCEPT [root@ctcdb01 ~] # service iptables save to / etc/sysconfig/iptables: [OK] # service iptables restart [root@ctcdb01 home] # / sbin/service iptables save this action will execute the iptables initialization script The script runs the / sbin/iptables-save program and updates the current iptables configuration file / etc/sysconfig/iptables. The original configuration file will be saved as iptables.save. The next time the system boots, the iptables initialization script uses the / sbin/iptables-restore command to reread the contents of the / etc/sysconfig/iptables file. Verify that ftp: C:\ Users\ kam > ftp 172.18.2.60 is connected to 172.18.2.60. 220 ctcdb01 FTP server (Version 5.60) ready. User (172.18.2.60: (none)): root 331Password required for root. Password: 230 User root logged in. Ftp > (3) configure firewall [root@ctcdb01] # vi / etc/sysconfig/iptables # by modifying / etc/sysconfig/iptables, plus the following line-A RH-Firewall-1-INPUT-p tcp-m state-- state NEW-m tcp-- dport 21-j ACCEPT-A RH-Firewall-1-INPUT-p tcp-m state-- state NEW-m tcp-- dport 20-j ACCEPT save exit [root@ctcdb01 ~] # service iptables restart verification ftp: C:\ Users\ kam > ftp 172.18.2.60 5, add user [root@ctcdb01 ~] # whoami # to check whether the current user has the right to add user root

(1), add users

[root@ctcdb01] # useradd test [root@ctcdb01 ~] # passwd test Changing password for user test. New UNIX password: BAD PASSWORD: it is based ona dictionary word Retype new UNIX password: passwd: all authentication tokens updated successfully.

(2) View current user information

[root@ctcdb01 ~] # cat / etc/passwd | grep test test:x:501:501::/home/test:/bin/bash [root@ctcdb01 home] # ls test tong [root@ctcdb01 home] #

6. Set the program or script to boot (take mysql as an example)

Method 1: add the following line at the end of the / etc/rc.d/rc.local file

/ usr/local/mysql5/bin/mysql start

Method 2:chkconfig-- level 35 mysqld on

Modify the mysql.server replication in the mysql5/support-files directory to / etc/init.d/mysqld cp support-files/mysql.server / etc/init.d/mysqld chkconfig-- list mysqld chkconfig-- add mysqld service mysqld start chkconfig-- level 35 mysqld on

Linux os divides the operating environment into the following seven levels:

0: shutdown (please do not switch to this level)

1: text interface in single user mode

2: multi-user mode text interface, without network file system (NFS) function

3: multi-user mode text interface, with network file system (NFS) function (standard runtime)

4: system retention value

5: some distributions of linux use this level to enter x windows system

6: restart (never set initdefault to 6)

View the started process # ps-ef # View the mysql started when there is a process running # service mysqld status # View the status of the service

7. Software installation specification

1. Common software uses the default installation directory of the software. two。 Some software that needs to set a separate installation directory and environment variables, such as Oracle database and Mysql database, should be installed in the user directory (/ home/user), such as: Oracle user, install Oracle database software to / home/oracle directory, tong user, install tong installed software to / home/tong directory

~ end ~

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report