Linux Operations (v)

Source: Internet
Author: User
Tags ack php language

The head was a little big and wasted some time. Buffer After tomorrow .

1. What is the difference between a stored procedure and a trigger?

A: (1) triggers are executed primarily through event execution, and stored procedures can be called directly by the stored procedure name. (Call/execute)

(2) A trigger is a special stored procedure in which the database server automatically executes the SQL statement defined by the trigger when a DML statement, such as INSERT, UPDATE, Delete, is made in the table

(3) The trigger has no parameters, and the stored procedure has parameters.

(4) The trigger is best not to return data, and the stored procedure can return the data


2, the difference between NetFilter and iptables?

A: (1) iptables is the application, it defines some rules, and NetFilter is the framework.

(2) iptables work in user space, while netfilter work in kernel space.

(3) NetFilter is used to implement the kernel space program code snippet in the Linux kernel firewall, which is either compiled directly into the kernel or included in the module, while Iptables is the user program used to manage the NetFilter firewall.


3. TCP Message Format field, what is the difference between congestion control and flow control? (The difference is not good to say, a bit difficult, even if previously organized)

A: Serial number, confirmation number, 6 flag fields (FIN/ACK/RST/SYN/URG/PSH), source port number, destination port number, checksum, data offset, window, emergency pointer.

The difference: (1) Congestion control is to prevent excessive data injection into the network caused by the chain, do not send hundreds of thousands of files at a sudden. It is a global process that involves all the hosts, routers, and all the factors that are associated with reducing network transmission performance.

(2) Flow control refers to the end-to-end traffic control, do not suddenly come to a few G-size large files, the other busy not to come. The flow control is to suppress the sending side to send the data rate, so that the receiving end time to receive.


4, file A in 10 records, File B has 5 records, to find a in a but there is no record of B. (It's hard to do, it seems to have done before)

Answer: Cat A.txt B.txt |sort|uniq-d >chongfu.txt;cat A.txt chongfu.txt|sort |uniq-u

# #思路就是先找出两个文件中相同的记录重定向到一个文件, compare the same record in a file, leaving the only record in a.


5. User A wants to log on to the C host on its Linux workstation as User B to see what the UID of D is, how to do it? (Sounds scary.)

Answer: As long as the host on a: Ssh-l B C ID d or SSH [email protected] ID D # #C相当于主机名或IP地址,-L for login log in

6. Duplicate row data appears in a database without a primary key, how can I delete these duplicate records? and repeat records are retained once.

Answer: SELECT DISTINCT * to TMP from TABLE_NAME; # #distinct去会去掉重复行 and reserved only once.

DROP TABLE table_name; # #删除原来的表

SELECT * into table_name from TMP; # #将不含重复的临时表插入到原来的新表中;

DROP table tmp; Delete temp table


7. In the above questions, if you encounter duplicate rows are deleted? As long as there is repetition, it is not preserved.

Mysql> select * from T1;

+------+------+

| ID | NAMW |

+------+------+

| 1 | y |

| 2 | H |

| 2 | H |

| 3 | H |

| 3 | H |

| 3 | H |

+------+------+

A: The idea is that group by,having count (*) >1 words, put into a temporary table, and then compare two tables with exists, delete the original base table the same record, return

Mysql> CREATE TABLE tmp as SELECT * from T1 GROUP by Id,name have Count (*) >1;# #在这里重复行只出现一次在tmp表中.

Mysql> SELECT * FROM TMP;

+------+------+

| ID | NAMW |

+------+------+

| 2 | H |

| 3 | H |

Mysql> SELECT * from t1 where exists (SELECT * from TMP where tmp.id=t1.id and TMP.NAMW=T1.NAMW); #从t1表返回重复行

+------+------+

| ID | NAMW |

+------+------+

| 2 | H |

| 2 | H |

| 3 | H |

| 3 | H |

| 3 | H |

+------+------+

mysql> Delete from T1 where exists (SELECT * from TMP where tmp.id=t1.id and TMP.NAMW=T1.NAMW)

# #只把select换成delete即可.

Mysql> select * from T1;

+------+------+

| ID | NAMW |

+------+------+

| 1 | y |

+------+------+


8, a Linux host from two network cards eth0, ETH1,IP respectively 192.168.1.1 and 10.0.0.1, how to make this server as a gateway or proxy server so that the internal people can surf the internet?

Answer: (1) on the Linux host: Echo 1>/proc/sys/net/ipv4/ip_forward=1 # #开启路由管道

(2) iptables-t nat-a postrouting-o eth1-j Masqurade # #出口IP是动态的

Iptables-t nat-a postrouting-s 192.168.1.0/24-o eth1-j SNAT--to 10.0.0.1 # #出口IP是静态的

Service Iptables Save

(3) The Internet can be accessed by setting up the agent in the client's browser.


9, a company's internal user reflects the inability to receive mail from a new customer company, a company using their own sendmail mail server, what do you think is the problem?

A: (1) When SendMail receives a message from any MTA, it first checks the delivery address. If the part after "@" matches the host name of the local domain in the native file/etc/mail/local-host-names, try saving it as an on-premises message. When there is no match, it attempts to forward the message to the external MTA. Mainly used to prevent spam, such as the company just want to receive or forward messages from local 192.168.1.0/24, should add the following line in the file: 192.168.1 RELAY

(2)/etc/mail/access.db is an Access data file that can be generated by the Makemap command to convert a text file/etc/mail/access

(3)/etc/aliases used to implement the alias of the Mail user (because the mailbox Account record is not convenient), the establishment of the company's mailing list, mail server forwarding; newaliases used to reload the file, allowing SendMail to read the contents of the file

Comprehensive analysis, is/etc/mail/access out a problem, can be changed to From:[email protected] OK # #OK是制约关键字, similar to relay, REJECT, Disgard


10. What kinds of internal connections are there? What's the difference?

A: Equivalent connection: Returns all data in two tables that meet the "=" condition and includes duplicate columns.

Non-equivalent connections: Returns all data in two tables that meet the "<>" condition.

Natural connection: On the basis of the equivalent connection, remove the repeating column.


11, the existence of table T (a,b,c,d), to be sorted according to the field C 第21-30条 record display, please give SQL?

A: SELECT * from T ORDER by C limit 20,10 # #初始记录行的偏移量是 0, 20 for line 21st, I want to record 10 lines in a row to meet 30 lines


12. What is the line lock of InnoDB engine in MySQL completed by adding? (The routines are a little different.)

Answer: Index value. InnoDB table data is stored as Index organization table, but the index page is locked and implemented by bitmap. Lock: Provide concurrent access to shared resources, ensure the integrity and consistency of the data; InnoDB and MyISAM cache mechanism, InnoDB both cache data blocks and cache index values.


13. How to Partition Linux?

A: Suppose the hard disk 8GB, I set the virtual machine physical memory 512MB (for the character interface enough, for the X_windows graphical interface is not enough, but can be adjusted at any time), the real machine physical memory is fixed (unless using PAE Address Extension Technology),/boot partition 200mb,/ Swap partition is 1G, guaranteed to twice times the size of physical memory,/data partition 1G, for storing database files,/root partition 2GB, about 25% of the total disk size, the last remaining space is divided into the/home partition.


14, how to test the lamp environment? How is the host separation service for FASTCGI deployed? (Server separation is what I always want to think about, three host experiment is a bit difficult)

A: test: For Apache, very good test, browser page access to the site, return to the root of the Web page I published index.html the corresponding content. Bad test is MySQL, you have to use a PHP language to write dynamic pages, when I input data on the front page and submit, my background database server will automatically add content, I just need to select the query whether there is an update. Only test PHP alone, write a index.php, see browser Access can appear page not.

Detach: HTTPD--PHP-FPM (fastcgi process Manager)--mysql, each with its own IP address. Apahce need to uncomment the Mod_proxy module,

Add proxyrequests off to the virtual host, turn off the forward proxy, Proxypassmatch ^/(. *\.php) $fcgi://192.168.1.2:9000/path/$1,

In PHP code, use $link = mysql_connect (' 172.16.2.6 ', ' root ', ' magelinux '), and similar fields to connect to the database, called ODBC.

Reference Document: http://yao3800.blog.51cto.com/1522113/1705701


15. When will TCP be re-transmitted? How to tell if a TCP message is a retransmission message? (This is a question to be asked to brush a group of people to interview)

A: (1) The data packet transmission process is lost;

(2) The server receives the client's data message, but does not respond, that is, does not send an ACK;

(3) The service side response process for various reasons caused the ACK message lost.

Judgment: Retransmission message generally has the following two characteristics: first, the TCP interaction sequence number is suddenly dropped (because the sequence number is incremented, to retransmit the previous message of course to decline), the second is in the TCP header of the serial number, data length, application data and other parameters with the previous TCP messages consistent.

Mechanism: The sender sends one or several successive messages with serial number, in the specified timer time, receives the acknowledgment of the receiver, and then continues to send the next content, otherwise, retransmission.

Number of retransmissions; cat/proc/sys/net/ipv4/tcy_synack_retries default 5 times, if the number of times is reached, then the server sends reset to indicate that the reset terminates the connection.

Retransmission time: such as Windows first retransmission 3 seconds, the second retransmission before the timer wait time is the second time twice times, Linux do not know


16, there is a Web service, how to monitor it in the provision of services?

A: (1) write a script, every 5 minutes to ping it, test the network connectivity of this host, otherwise the mail alarm

(2) In this script, every 1 minutes with the Curl command-i parameter to test, and then use the awk command to filter out the K OK field, otherwise, the mail alarm

(3) On the other hand, those monitoring tools such as Nagios are very powerful, unable to provide services it will also SMS and email alerts.


17, send a small video, what kind of protocol to use? Explain why? (If you don't think ahead, it's a little hard to say why)

Answer: No suspicion is UDP. Reasons: (1) UDP package upper application data, add less control information, do not need to build three handshake, direct delivery to the network layer processing, delay that is small point. In addition, we know that these voice and video traffic have higher latency and jitter requirements

(2) ... (should also, to be continued)


18, there is a file contains many words, the words are separated by white space, find the word ' Linux ' the previous word, or the last word? (Incredibly, it's hard to ask, or a netizen!) )

echo "CentOS linuxcast Redhat" >1.txt

A: The previous word: Cat 1.txt |tr "" \ n "|awk '/linux/{print var}{var=$0} ' # # # # # # # # # # # # # # # # # # # # Use Var to save the last line of the keyword

Current line: Cat 1.txt |tr "" \ n "|awk '/linux/{print $RS} ' # #RS是当前行的内容

Last word: Cat 1.txt |tr "" \ n "| awk ' {if (A) print; A=0}/linux/{a=1} ' # #找到linux关键字后, constructs the output condition for the next row.



19, some hot and cold data, to these very cold data, suddenly have a lot of user access, how to improve the disk I/O ability (a bit difficult oh)

A: (1) use a solid-state drive to do a RAID5 array.

(2) Reduce the number of visits to a certain time period from the business


20, how to check the network card traffic of Linux, is it byte or bit? What to look for Nic information, what the network card information includes, and where is the configuration file? (Constant test)

Answer: bytes. Ethtool command to view network card information, including gigabit or hundred-gigabit, duplex or half-duplex, self-negotiation or not, the model of the interface,

(1) Sar-n DEV [Refresh delay] [refresh], (2) Iptraf interface, if the screen is too small, you need to press the F11 key


21. The difference between socket connection and HTTP connection. (This is really hard)

A: (1) The socket itself is not a protocol, but a calling interface (API), which is the abstraction layer between the application layer and the Transport layer; HTTP is an application-layer stateless protocol that uses TCP to encapsulate HTTP messages.

(2) Socket has an IP address and port number, it is a programming technology to provide network communication capabilities. HTTP is used to specify how to transfer some data, such as ASIII or binary types



22. What are the differences between routers and switches? (Put it in Linux ops because it might involve a very shallow network knowledge.)

A: (1) The router works in the network only then, the switch works at the data link layer. (Of course, the default switch here is Layer two)

(2) Its working mechanism is different. Routers take apart the IP address of the three-layer header, which is routed through Anza and stored and forwarded by the table. While the switch is to disassemble the frame head to view the destination MAC address, if the MAC address table has a cache record then forward, otherwise broadcast out.

(3) Routers divide the broadcast domain and the conflict domain, and the switch divides the conflict domain only, but does not divide the broadcast domain.

(4) from the port density, the router port is very few, the switch usually has 16, 24 is different.

(5) From the communication range, the router is to allow different network segments to communicate, and the switch is to let the local network segment communication.


23, the website response is too slow, how wrong? (This problem is the focus, repeated many times)

A: The first judgment is a person's problem or a large area of the problem. You have to go to the test, see how the Ping Server packet loss rate situation.

(1) User bandwidth issues (2) High server CPU Utilization (3) DNS resolution slow (4) Web site egress bandwidth Issues

(5) Customer browser front-end design issues (6) page code quality issues (7) server encounters attack


24, how to let 192.168.10.6 Ping pass 172.16.100.6? (I really thought that it was impossible to see Mago, really overturned)

Answer: Set iptable-t nat-a postrouting-s 192.168.10.0/24-j snat--to-source 172.16.100.6 on this host 172.16.100.6.


25. What tools or commands are used to view and test the performance of the system? (This question is worth a good tidy up)

Answer: (1) disk performance: Sysbench, Iostat, Iotop

(2) Network performance: Ethtool, SAR command. Ping connectivity, traceroute detection path failure

(3) memory and swap conditions: vmstat refresh delay refresh times, free-m, and file/proc/meminfo

(4) Process status: Top, PS, pstree; thread condition: htop, Ps-t

(5) Port condition: netstat

(6) Load condition: uptime, top

(7) CPU Condition: SAR command, Top command, and file/proc/cpuinfo

(8) Log condition: Awstats, Last command, and some files such as System log, service log, security log

(9) disk condition: Df-h and Fisk-l

(10) Concurrent processing capacity: AB, Httperf




Linux Operations (v)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.