root@tecmint [~]# host www.google.com
www.google.com has address 173.194.66.147
www.google.com has address 173.194.66.105
www.google.com has address 173.194.66.99
www.google.com has address 173.194.66.104
www.google.com has address 173.194.66.106
www.google.com has address 173.194.66.103
www.google.com has IPv6 address 2a00:1450:400c:c03::68
whoami 命令也用于当你使用 su 命令(切换用户)时, 它能让你确认登录的用户名是否正确。whoami 和 who 命令不相同, who 命令会显示所有已经登录的用户名,而 whoami 不是。当你切换用户时,whoami 命令会显示会话所属的当前用户,而 who 命令会显示你切换前的那个源用户。
[...]
#Uncomment and Set YES to enable write.
write_enable=YES
[...]
# Uncomment and Set banner name for your website
ftpd_banner=Welcome to Unixmen FTP service.
[...]
# Uncomment
ls_recurse_enable=YES
[...]
# Uncomment and set YES to allow local users to log in.
local_enable=YES
[...]
# To disable anonymous access, set NO.
anonymous_enable=NO
[...]
# Uncomment to enable ascii download and upload.
ascii_upload_enable=YES
ascii_download_enable=YES
[...]
## Add at the end of this file ##
use_localtime=YES
保存并退出文件。
测试本地FTP服务器
首先 让我们按如下步骤尝试登录FTP服务器
# ftp localhost
Trying ::1:21 ...
Connected to localhost.
220 (vsFTPd 3.0.2)
Name (localhost:root): unixmen
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
sk@sk:~$ ftp 192.168.1.53
Connected to 192.168.1.53.
220 (vsFTPd 3.0.2)
Name (192.168.1.53:sk): unixmen
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
$ netstat -g
IPv6/IPv4 Group Memberships
Interface RefCnt Group
--------------- ------ ---------------------
lo 1 all-systems.mcast.net
eth0 1 224.0.0.251
eth0 1 all-systems.mcast.net
lo 1 ip6-allnodes
lo 1 ff01::1
eth0 1 ff02::fb
eth0 1 ff02::1:fff8:b264
eth0 1 ip6-allnodes
eth0 1 ff01::1
wlan0 1 ip6-allnodes
wlan0 1 ff01::1
更多用法
目前为止我们列出了 netstat 的基本用法,现在让我们一起来 geek 吧~
打印 active 状态的连接
active 状态的套接字连接用 “ESTABLISHED” 字段表示,所以我们可以使用 grep 命令获得 active 状态的连接:
$ netstat -atnp | grep ESTA
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 192.168.1.2:49156 173.255.230.5:80 ESTABLISHED 1691/chrome
tcp 0 0 192.168.1.2:33324 173.194.36.117:443 ESTABLISHED 1691/chrome
root@mrtg:/etc/nagios3/conf.d/# cp localhost_nagios2.cfg example.cfg
root@mrtg:/etc/nagios3/conf.d/# vim example.cfg
–
# Host 1
define host{
use linux-server ; 使用的主机模板名
host_name our-server ; nagios使用的主机名
alias our-server
address 172.17.1.23 ; 主机的IP地址
}
# Host 2
define host{
use cisco-device ; 使用的主机模板名
host_name our-router ; nagios使用的主机名
alias our-router
address 172.17.1.1 ; 主机的IP地址
}
主机组定义
当有多个主机时,为方便管理,建议将相似的主机组成一组。
root@mrtg:/etc/nagios3/conf.d/# vim hostgroups_nagios2.cfg
–
define hostgroup {
hostgroup_name linux-server ; 主机组名
alias Linux Servers
members our-server ; 组员列表
}
define hostgroup {
hostgroup_name cisco-device ; 主机组名
alias Cisco Devices
members our-server ; comma separated list of members
}
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted
cd /etc/yum.repos.d
sudo wget http://www.hop5.in/yum/el6/hop5.repo
4、安装docker-io
[root@localhost ~]# yum install docker-io
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* epel: kartolo.sby.datautama.net.id
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package docker-io.x86_64 0:0.5.3-4.el6 will be installed
--> Processing Dependency: lxc >= 0.8.0 for package: docker-io-0.5.3-4.el6.x86_64
--> Processing Dependency: kernel-ml-aufs >= 3.10.5 for package: docker-io-0.5.3-4.el6.x86_64
--> Running transaction check
---> Package kernel-ml-aufs.x86_64 0:3.10.5-3.el6 will be installed
---> Package lxc.x86_64 0:0.8.0-3.el6 will be installed
--> Processing Dependency: liblxc.so.0()(64bit) for package: lxc-0.8.0-3.el6.x86_64
--> Running transaction check
---> Package lxc-libs.x86_64 0:0.8.0-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================
Package Arch Version Repository Size
============================================================================================
Installing:
docker-io x86_64 0.5.3-4.el6 hop5 1.2 M
Installing for dependencies:
kernel-ml-aufs x86_64 3.10.5-3.el6 hop5 33 M
lxc x86_64 0.8.0-3.el6 hop5 81 k
lxc-libs x86_64 0.8.0-3.el6 hop5 75 k
Transaction Summary
============================================================================================
Install 4 Package(s)
Total download size: 34 M
Installed size: 159 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): docker-io-0.5.3-4.el6.x86_64.rpm | 1.2 MB 00:03
(2/4): kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm | 33 MB 00:33
(3/4): lxc-0.8.0-3.el6.x86_64.rpm | 81 kB 00:00
(4/4): lxc-libs-0.8.0-3.el6.x86_64.rpm | 75 kB 00:00
--------------------------------------------------------------------------------------------
Total 896 kB/s | 34 MB 00:39
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : lxc-libs-0.8.0-3.el6.x86_64 1/4
Installing : lxc-0.8.0-3.el6.x86_64 2/4
Installing : kernel-ml-aufs-3.10.5-3.el6.x86_64 3/4
Installing : docker-io-0.5.3-4.el6.x86_64 4/4
Verifying : kernel-ml-aufs-3.10.5-3.el6.x86_64 1/4
Verifying : lxc-0.8.0-3.el6.x86_64 2/4
Verifying : lxc-libs-0.8.0-3.el6.x86_64 3/4
Verifying : docker-io-0.5.3-4.el6.x86_64 4/4
Installed:
docker-io.x86_64 0:0.5.3-4.el6
Dependency Installed:
kernel-ml-aufs.x86_64 0:3.10.5-3.el6 lxc.x86_64 0:0.8.0-3.el6
lxc-libs.x86_64 0:0.8.0-3.el6
Complete!
[root@localhost ~]#
5、检查安装情况
[root@localhost ~]# docker -h
Usage of docker:
-D=false: Debug mode
-H=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use
-api-enable-cors=false: Enable CORS requests in the remote api.
-b="": Attach containers to a pre-existing network bridge. Use 'none' to disable container networking
-d=false: Daemon mode
-dns="": Set custom dns servers
-g="/var/lib/docker": Path to graph storage base dir.
-p="/var/run/docker.pid": File containing process PID
-r=false: Restart previously running containers
[root@localhost ~]# docker -d
2013/08/21 07:47:07 WARNING: Your kernel does not support cgroup swap limit.
2013/08/21 07:47:07 Listening for HTTP on /var/run/docker.sock (unix)
10、在centos6.4容器里输出hello world
[root@localhost ~]# docker run centos:6.4 echo "hello world"
2013/08/21 07:48:41 POST /v1.4/containers/create
2013/08/21 07:48:41 POST /v1.4/containers/c6bc9e80097e/start
2013/08/21 07:48:41 POST /v1.4/containers/c6bc9e80097e/attach?logs=1&stderr=1&stdout=1&stream=1
hello world
11、从容器里测试ping
[root@localhost ~]# docker -dns '8.8.8.8' run centos:6.4 ping -c 3 yahoo.com
2013/08/21 08:02:15 POST /v1.4/containers/create
2013/08/21 08:02:15 POST /v1.4/containers/c40a1244f9bc/start
2013/08/21 08:02:15 POST /v1.4/containers/c40a1244f9bc/attach?logs=1&stderr=1&stdout=1&stream=1
PING yahoo.com (98.138.253.109) 56(84) bytes of data.
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=48 time=323 ms
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=2 ttl=48 time=329 ms
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=3 ttl=49 time=302 ms
--- yahoo.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2304ms
rtt min/avg/max/mdev = 302.032/318.318/329.656/11.807 ms
常见错误:
“DNS/Networking Errors inside the docker”
[root@localhost ~]# docker -dns="8.8.8.8" run centos:6.4 yum install hiphop-php
2013/08/21 07:53:05 POST /v1.4/containers/create
2013/08/21 07:53:05 POST /v1.4/containers/6d9fef14bd1a/start
2013/08/21 07:53:05 POST /v1.4/containers/6d9fef14bd1a/attach?logs=1&stderr=1&stdout=1&stream=1
Loaded plugins: fastestmirror
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
ERROR: failed to mkdir C:phppeardataAuthAuthFrontend
ERROR: failed to mkdir C:phppeardocsBenchmarkdoc
ERROR: failed to mkdir C:phppeardataCacheContainer
ERROR: failed to mkdir C:phppeardocsCache_Litedocs
ERROR: failed to mkdir C:phppeardocsCalendardocsexamples
ERROR: failed to mkdir C:phppeardocsConfigdocs
此前我们已经有发表过Linux 面试基础问答之一、二和三共3篇文章,获得读者的好评,同时我们得到反馈,有些读者希望这种交互式学习方法能够做得更加灵活。心动不如行动,我们这就为您奉上 15个 MySQL 面试题
问题1:你如何确定 MySQL 是否处于运行状态?
答案: Debian 上运行命令 service mysql status,在RedHat 上运行命令 service mysqld status。然后看看输出即可。
root@localhost:/home/avi# service mysql status
/usr/bin/mysqladmin Ver 8.42 Distrib 5.1.72, for debian-linux-gnu on i486
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.1.72-2
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 1 hour 22 min 49 sec
Threads: 1 Questions: 112138 Slow queries: 1 Opens: 1485 Flush tables: 1 Open tables: 64 Queries per second avg: 22.567.
问题2:如何开启或停止 MySQL 服务?
答案:运行命令 service mysqld start 开启服务;运行命令 service mysqld stop 停止服务。
root@localhost:/home/avi# service mysql stop
Stopping MySQL database server: mysqld.
root@localhost:/home/avi# service mysql start
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..
问题3:如何通过 Shell 登入 MySQL?
答案:运行命令 mysql -u root -p
root@localhost:/home/avi# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 207
Server version: 5.1.72-2 (Debian)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>
问题4:如何列出所有数据库?
答案:运行命令 show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| a1 |
| cloud |
| mysql |
| phpmyadmin |
| playsms |
| sisso |
| test |
| ukolovnik |
| wordpress |
+--------------------+
10 rows in set (0.14 sec)
问题5: 如何切换到某个数据库并在上面工作?
答案:运行命令 use database_name; 进入名为 database_name 的数据库。
mysql> use cloud;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
mysql> select * from engines;
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ENGINE | SUPPORT | COMMENT | TRANSACTIONS | XA | SAVEPOINTS |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
8 rows in set (0.00 sec)
问题11:如何从表(比如 oc_users )中获取一个 field 对象(比如 uid)的所有数据?
答案:运行命令 select uid from oc_users;
mysql> select uid from oc_users;
+-----+
| uid |
+-----+
| avi |
+-----+
1 row in set (0.03 sec)
问题13:如何列出表 ‘xrt’ 内 name 域值为 ‘tecmint’,web_address 域值为 ‘tecmint.com’ 的所有数据?
答案:运行命令 select * from xrt where name = “tecmint” and web_address = “tecmint.com”;
mysql> select * from xrt where name = "tecmint" and web_address = “tecmint.com”;
+---------------+---------------------+---------------+
| Id | name | web_address |
+---------------+---------------------+----------------+
| 13 | tecmint | tecmint.com |
+---------------+---------------------+----------------+
| 41 | tecmint | tecmint.com |
+---------------+---------------------+----------------+
问题14:如何列出表 ‘xrt’ 内 name 域值不为 ‘tecmint’,web_address 域值为 ‘tecmint.com’ 的所有数据?
答案:运行命令 select * from xrt where name != “tecmint” and web_address = “tecmint.com”;
mysql> select * from xrt where name != ”tecmint” and web_address = ”tecmint.com”;
+---------------+---------------------+---------------+
| Id | name | web_address |
+---------------+---------------------+----------------+
| 1173 | tecmint | tecmint.com |
+---------------+---------------------+----------------+
问题15:如何知道表内行数?
答案:运行命令 select count(*) from table_name;
mysql> select count(*) from Tables;
+----------+
| count(*) |
+----------+
| 282 |
+----------+
1 row in set (0.01 sec)
$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 003: ID 17ef:4811 Lenovo Integrated Webcam [R5U877]
Bus 008 Device 002: ID 0a5c:217f Broadcom Corp. Bluetooth Controller
lsusb会显示驱动和内部连接到你系统的设备。
下面介绍如何理解输出。我抓取了上面输出的最后一行:
Bus 008 Device 002 : ID 0a5c:217f Broadcom Corp. Bluetooth Controller
$ dmesg |grep -i usb
[ 0.353138] usbcore: registered new interface driver usbfs
[ 0.353150] usbcore: registered new interface driver hub
[ 0.353182] usbcore: registered new device driver usb
[ 0.730026] ehci_hcd: USB 2.0 ‘Enhanced’ Host Controller (EHCI) Driver
[ 0.730116] ehci_hcd 0000:00:1a.7: new USB bus registered, assigned bus number 1
[ 0.748019] ehci_hcd 0000:00:1a.7: USB 2.0 started, EHCI 1.00
[ 0.748169] hub 1-0:1.0: USB hub found
[ 0.748336] ehci_hcd 0000:00:1d.7: new USB bus registered, assigned bus number 2
[ 0.768019] ehci_hcd 0000:00:1d.7: USB 2.0 started, EHCI 1.00
[ 0.768147] hub 2-0:1.0: USB hub found
[ 0.768236] ohci_hcd: USB 1.1 ‘Open’ Host Controller (OHCI) Driver
[ 0.768251] uhci_hcd: USB Universal Host Controller Interface driver
如何列出USB详细信息
使用-v选项来开启。下面是一个例子。
$ lsusb -v
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 5
bNumEndpoints 2
bInterfaceClass 224 Wireless
bInterfaceSubClass 1 Radio Frequency
bInterfaceProtocol 1 Bluetooth
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0×83 EP 3 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0×0040 1x 64 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0×03 EP 3 OUT
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0×0040 1x 64 bytes
bInterval 1
$ lsusb -t
/: Bus 08.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 07.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 06.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 05.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/6p, 480M
|__ Port 1: Dev 4, If 0, Class=stor., Driver=usb-storage, 480M
|__ Port 6: Dev 3, If 0, Class=’bInterfaceClass 0x0e not yet handled’, Driver=uvcvideo, 480M
|__ Port 6: Dev 3, If 1, Class=’bInterfaceClass 0x0e not yet handled’, Driver=uvcvideo, 480M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/6p, 480M
tecmint@localhost:~$ [ -f /home/tecmint/Downloads/xyz1.txt ] || {touch /home/tecmint/Downloads/xyz.txt; echo "The file does not exist"}
“The file does not exist”