Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
limox 2014-06-08 21:18:04 +08:00
commit b8e7338f54
5 changed files with 205 additions and 245 deletions

View File

@ -1,58 +1,39 @@
在Ubuntu 14.04 LTS系统中设置Apache虚拟主机
================================================================================
**虚拟主机**常用于单独一个IP地址安装多个域名或网站服务。如果有人想在单个VPS的单个IP地址运行多个网站这是非常有用的。
**虚拟主机**常用于在一个单独的IP地址上提供多个域名的网站服务。如果有人想在单个VPS的单个IP地址运行多个网站这是非常有用的。
在这个教程中让我告诉你如何设置在Ubuntu 14.04 LTS的Apache网页服务器设置虚拟主机。请注意这个教程只针对Ubuntu14.04的32位版本。
我不能提出任何保证它也可以工作在其它更低的Ubuntu版本或者Ubuntu衍生物。
我不保证它也可以工作在其它更低的Ubuntu版本或者Ubuntu衍生版本虽然可能过程是类似的
###方案###
在这个教程中我会使用Ubuntu 14.04 32位 LTS并搭建2个测试网站分别命名为“**unixmen1.local**” 和 “**unixmen2.local**”.我的测试机分别为**192.168.1.250/24**和**server.unixmen.local**。你可以根据你的需要更改虚拟域名。
###安装Apache网站服务器###
安装apache服务器之前我们来更新一下我们的Ubuntu服务器
sudo apt-get update
现在用下面命令来安装apache网络服务器
然后用下面命令来安装apache网络服务器
sudo apt-get install apache2
安装apache服务器之后让我们通过这个URL **http://ip-address/**来测试网站服务器是否正常工作
安装apache服务器之后让我们通过这个URL **http://你的服务器的IP地址/** 来测试网站服务器是否正常工作
![](http://180016988.r.cdn77.net/wp-content/uploads/2014/06/Apache2-Ubuntu-Default-Page-It-works-Mozilla-Firefox_001.png)
像你所看到以上的图片apache服务器正在工作。
如你所见apache服务器已经工作了。
###设置虚拟主机###
#### 1.创建虚拟目录 ##
现在让我们继续安装虚拟主机。正如我先前所述我要新建2台虚拟主机分别命名为“**unixmen1.local**”和“**unixmen2.local**”.
创建一个公用的文件夹来存放这两台虚拟主机的数据。
首先让我们为unixmen1.local这个站点创建一个目录
sudo mkdir -p /var/www/unixmen1.local/public_html
@ -61,42 +42,30 @@
sudo mkdir -p /var/www/unixmen2.local/public_html
### 2. 设置所有者和权限 ####
上面目录现在只有root拥有权限。我们需要修改这2个目录的拥有权给普通用户而不仅仅是root用户。
sudo chown -R $USER:$USER /var/www/unixmen1.local/public_html/
sudo chown -R $USER:$USER /var/www/unixmen2.local/public_html/
“**$USER**”变量显示了当前的登录用户。
“**$USER**”变量指向了当前的登录用户。
设置读写权限给apache网页根/var/www)目录,这样每个人都可以从目录中读取文件。
设置读写权限给apache网页根目录/var/www及其子目录这样每个人都可以从目录中读取文件。
sudo chmod -R 755 /var/www/
这样,我们就创建好了一些文件夹来保存网络相关数据并分配必要的权限和所属用户。
#### 4. 为虚拟主机创建示例页 ####
我们需要创建一些文件夹来保存网络相关数据并分配必要的权限和所属用户
现在,我们给网站增加示例页。第一步,让我们给虚拟主机**unixmen1.local**创建一个示例页
#### 4. 为虚拟主机创建例页 ####
现在,我们必须通过网站示例样页。第一步,让我们给虚拟主机窗机一个名为**unixmen1.local**的样页。
给unixmen1.local虚拟主机创建一个目录
给unixmen1.local虚拟主机创建一个示例页
sudo vi /var/www/unixmen1.local/public_html/index.html
添加一下内容:
添加以下内容:
<html>
<head>
@ -110,12 +79,12 @@
保存并关闭文件。
同样的,添加页到第二台虚拟主机。
同样的,添加示例页到第二台虚拟主机。
sudo vi /var/www/unixmen2.local/public_html/index.html
添加下内容:
添加下内容:
<html>
<head>
@ -128,23 +97,20 @@
保存并关闭文件。
#### 5. 创建虚拟主机文件####
#### 5. 创建虚拟主机配置文件####
默认情况下apache有一个默认的虚拟主机文件叫000-default.conf.我们将会复制**000-default.conf**文件内容到我们新的虚拟主机文件中。
默认情况下apache有一个默认的虚拟主机文件叫000-default.conf。我们将会复制**000-default.conf**文件内容到我们新的虚拟主机配置文件中。
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen1.local.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen2.local.conf
确保虚拟主机配置文件末尾包含.conf扩展名。
确保虚拟主机文件包含.conf扩展名在内容的最后。
现在修改unximen1.local.conf文件以呈现新的值。
现在修改unximen1.local.conf文件以符合需求。
sudo vi /etc/apache2/sites-available/unixmen1.local.conf
使相关的变化直接呈现在unixmen1站点中。
使相关的变化直接呈现在unixmen1站点中译注以“#”开头的注释行可以忽略。)。
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
@ -183,7 +149,6 @@
sudo vi /etc/apache2/sites-available/unixmen2.local.conf
使相关的修改在unixmen2 站点呈现出来。
<VirtualHost *:80>
@ -219,40 +184,32 @@
</VirtualHost>
修改虚拟主机文件后,使默认的虚拟主机000.default.conf)不生效,然后使新的虚拟主机生效,如下所示。
修改虚拟主机文件后,禁用默认的虚拟主机配置000.default.conf),然后启用新的虚拟主机配置,如下所示。
sudo a2dissite 000-default.conf
sudo a2ensite unixmen1.local.conf
sudo a2ensite unixmen2.local.conf
最后重启apache服务器。
sudo service apache2 restart
就是这样。现在我们成功地配置了apach虚拟主机在我们的Ubuntu服务器上
测试虚拟主机
###测试虚拟主机###
编辑**/etc/hosts**文件,
sudo vi /etc/hosts
如下所示挨个添加虚拟域名。
在文件末尾添加如下所示的虚拟域名。
[...]
192.168.1.250 unixmen1.local
192.168.1.250 unixmen2.local
保存并关闭文件。
打开你的浏览器并指向**http://unixmen1.local** 或 **http://unixmen2.local**链接。你将会看到我们之前创建的样页。
打开你的浏览器并访问**http://unixmen1.local** 或 **http://unixmen2.local**。你将会看到我们之前创建的示例页。
**Unixmen1.local 测试页:**
@ -263,7 +220,7 @@
![](http://180016988.r.cdn77.net/wp-content/uploads/2014/06/www.unixmen2.local-Mozilla-Firefox_005.png)
如果你想从你的远程系统访问这些站点你需要在你的DNS服务器添加实际域名记录。因此,我不需要人和实际域名和DNS服务器我只想通过我的本地系统测试那么它刚好如我所愿地工作。
如果你想从你的远程系统访问这些站点你需要在你的DNS服务器添加实际域名记录。不过,我没有真实的域名和DNS服务器我只想通过我的本地系统测试那么它刚好如我所愿地工作。
Cheers
@ -271,6 +228,6 @@ Cheers
via: http://www.unixmen.com/setup-virtual-hosts-apache-ubuntu-14-04-lts/
译者:disylee(https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
译者:[disylee](https://github.com/disylee) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出

View File

@ -1,3 +1,5 @@
alim0x translating
Ubuntu One Formally Shuts Down
================================================================================
**Ubuntu One is now formally in shut-down. You have until July 31 to grab your files or they will be lost forever. **

View File

@ -1,3 +1,4 @@
[translating BY lolipop]
New OpenSSL breach is no Heartbleed, but needs to be taken seriously
================================================================================
> Summary: While the newest OpenSSL security problems are troubling, and you should address it, it's nothing as bad as Heartbleed.

View File

@ -1,177 +0,0 @@
Mike Translating
Practical Interview Questions and Answers on Linux Shell Scripting
================================================================================
With the overwhelming response we are getting on the Interview Series articles, the first of its kind on any Linux How-to website in the form of Likes, Feedbacks in comment as well as on personal Email Address make us going from one article to the next article.
Here is the link to the [Interview Series][1] articles already published on Tecmint.com, where we have covered lots of topics viz., FTP, MySQL, Apache, Scripting, Linux Commands, etc.
![Practical Interview Question on Shell Scripting](http://www.tecmint.com/wp-content/uploads/2014/06/Interview-Questions-on-Shell-Scripting.png)
Practical Interview Question on Shell Scripting
Continuing to the above series here we are coming with another 5 wonderful Linux Interview Questions and their answer. Your (The Tecmint.com Readers and frequent Visitors) support is always needed to make it successful.
### 1. Write a shell script to get current date, time, user name and current working directory. ###
> **Answer** : The commands logname, date, who I am and pwd will output username, current date and time, and current working directory. Just implementing these commands in the script and making it a bit interactive.
Now create a file called **userstats.sh** and add the following code to it.
#!/bin/bash
echo "Hello, $LOGNAME"
echo "Current date is `date`"
echo "User is `who i am`"
echo "Current directory `pwd`"
Place execute permission and run the script as shown below.
# chmod 755 userstats.sh
# ./userstats.sh
#### Sample Output ####
Hello, avi
Current date is Sat Jun 7 13:05:29 IST 2014
User is avi pts/0 2014-06-07 11:59 (:0)
Current directory /home/avi/Desktop
### 2. Write a Shell Script that adds two numbers if provided as the command Line Argument and if the two numbers are not entered it outputs an Error Message along with a one-Line of how-to use description. ###
> **Answer** : Here is the simple Shell Script along with description which adds two number if provided as Command-Line argument, if not it throws error with single line on how to use the script.
Again create a file called **two-numbers.sh** and add the following content to it.
#!/bin/bash
# The Shebang
if [ $# -ne 2 ]
# If two Inputs are not received from Standard Input
then
# then execute the below statements
echo "Usage - $0 x y"
# print on standard output, how-to use the script (Usage - ./1.sh x y )
echo " Where x and y are two nos for which I will print sum"
# print on standard output, “Where x and y are two nos for which I will print sum ”
exit 1
# Leave shell in Error Stage and before the task was successfully carried out.
fi
# End of the if Statement.
echo "Sum of $1 and $2 is `expr $1 + $2`"
# If the above condition was false and user Entered two numbers as a command Line Argument,
it will show the sum of the entered numbers.
Set executer permission on the file and run the script as shown below.
# chmod 755 two-numbers.sh
**Condition 1**: Running the script without entering two numbers as command line argument, you will get the following output.
#### Sample Output ####
# ./two-numbers.sh
Usage - ./two-numbers.sh x y
Where x and y are two nos for which I will print sum
**Condition 2**: When Numbers are entered as command line argument you will get the result as shown.
$ ./two-numbers.sh 4 5
Sum of 4 and 5 is 9
Hence the above shell script fulfills the condition as suggested in the question.
### 3. You needs to print a given Number say 10572, in reverse order using a Shell script such that the input is provided using command Line Argument only. If the input data is not provided as Command Line Argument, it should throw and error and should suggest, how to use the script. Write the script but before that tell me the algorithm that needs to be implemented here. ###
#### Algorithm ####
1. Let the Input Number = n
1. Set rev=0, sd=0 (Reverse and single digitis set to 0)
1. n % 10, will find and give single left most digit
1. reverse number is generated as rev * 10 + sd
1. Decrease Input Number (n) by 1.
1. if n > 0, then goto step 3 else goto setp 7
1. Print rev
Now again, create a file called **numbers.sh** and add the following given code it.
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 number"
echo " I will find reverse of given number"
echo " For eg. $0 0123, I will print 3210"
exit 1
fi
n=$1
rev=0
sd=0
while [ $n -gt 0 ]
do
sd=`expr $n % 10`
rev=`expr $rev \* 10 + $sd`
n=`expr $n / 10`
done
echo "Reverse number is $rev"
Grant a execute permission on the file and run the script as shown below.
# chmod 755 numbers.h
**Condition 1**: When Input is not provided as command line argument, you will get the following output.
#### Sample Output ####
./numbers.sh
Usage: ./numbers.sh number
I will find reverse of given number
For eg. ./2.sh 123, I will print 321
**Condition 2**: When Input was provided as command line Argument.
$ ./numbers.sh 10572
Reverse number is 27501
The above script worked perfectly and the output was just what we needed.
### 4. You are supposed to calculate a real number calculation directly from terminal and not any shell script. What will you do (say the real numbers are 7.56 and 2.453)? ###
> **Answer** : We need to use bc command in a special way as described below. The output of echo 7.56 + 2.453 should be pipelined to bc.
For example, run the following command to calculate numbers in real time using bc command as shown.
$ echo 7.56 + 2.453 | bc
10.013
### 5. You are supposed to find the value of pi upto 100 places of decimal, what is the easiest way to get the result done. ###
> **Answer** : The easiest way to find the value of pi, correct upto 100 places of decimal we just need to issue the below command.
# pi 100
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
Obviously! We must have package **pi** installed. Just do a **apt** or **yum** to get a required package to install **pi** onto the distribution you are using.
Thats all for now. Ill be here again with another interesting article very soon. Till then stay tuned and connected to Tecmint.com. Dont forget to provide us with you valuable feedback in the comment section below.
--------------------------------------------------------------------------------
via: http://www.tecmint.com/practical-interview-questions-on-linux-shell-scripting/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://www.tecmint.com/category/interview-questions/

View File

@ -0,0 +1,177 @@
实用的Linux SHELL面试问题及答案
================================================================================
随着之前有关面试的系列文章读者的反应比较强烈所以我决定出一篇有关Linux Shell相关的面试文章如果对本文有什么意见或意见的话欢迎反馈到我的邮箱里。
如果想要阅读已发表在Tecmint.com的文章可以点击链接链接到[访谈系列] [1]在这里我们已经介绍很多题目即文章。FTPMySQL和Apache的脚本Linux命令等。
![Practical Interview Question on Shell Scripting](http://www.tecmint.com/wp-content/uploads/2014/06/Interview-Questions-on-Shell-Scripting.png)
> 实用的shell脚本面试问题
这边提到的5个面试问题延续之前的有关Linux面试问题和答案。如果你是Tecmint.com的读者你的支持我非常感谢。
### 1. 写一个shell脚本来得到当前的日期时间用户名和当前工作目录。 ###
> **Answer** : 将输出用户名当前日期和时间以及当前工作目录的命令就是lognamedatewho i am和pwd。
现在,创建一个名为**`userstats.sh`**文件,将下面的代码添加到它。
#!/bin/bash
echo "Hello, $LOGNAME"
echo "Current date is `date`"
echo "User is `who i am`"
echo "Current directory `pwd`"
给他添加执行权限,并且执行他。
# chmod 755 userstats.sh
# ./userstats.sh
#### 样例输出 ####
Hello, avi
Current date is Sat Jun 7 13:05:29 IST 2014
User is avi pts/0 2014-06-07 11:59 (:0)
Current directory /home/avi/Desktop
### 2.写一个shell脚本进行两个数字的相加如果没有输入参数就输出错误信息和使用说明的###
> **Answer** :
下面是简单的shell脚本以及描述如果没有命令行参数它会抛出错误与如何使用脚本的说明。
再创建一个名为**`twonumbers.sh`**文件和下面的内容添加到文件里。
#!/bin/bash
# The Shebang
if [ $# -ne 2 ]
# If two Inputs are not received from Standard Input
then
# then execute the below statements
echo "Usage - $0 x y"
# print on standard output, how-to use the script (Usage - ./1.sh x y )
echo " Where x and y are two nos for which I will print sum"
# print on standard output, “Where x and y are two nos for which I will print sum ”
exit 1
# Leave shell in Error Stage and before the task was successfully carried out.
fi
# End of the if Statement.
echo "Sum of $1 and $2 is `expr $1 + $2`"
# If the above condition was false and user Entered two numbers as a command Line Argument,
it will show the sum of the entered numbers.
给他添加可执行权限,并且执行。
# chmod 755 two-numbers.sh
**Condition 1**: 未输入两个数字作为命令行参数运行脚本,你将得到下面的输出。
#### Sample Output ####
# ./two-numbers.sh
Usage - ./two-numbers.sh x y
Where x and y are two nos for which I will print sum
**Condition 2**: 当数字存在时,你会得到如图所示的结果。
$ ./two-numbers.sh 4 5
Sum of 4 and 5 is 9
因此上述shell脚本满足条件作为问题提出了建议。
### 3.你需要打印一个给定的数字的反序如输入10572输出27501如果没有输入数据应该抛出错误和使用脚本说明。在此之前告诉我你需要在这里使用的算法。 ###
#### 算法 ####
1. 输入的数字为n
2. 赋值 rev=0, sd=0 (反向和单个数字设置为0)
3. n % 10, 将得到最左边的数字
4. 反向数字可以用这个方法生成 rev * 10 + sd
5. 对输入数字进行-1操作
6. 如果n > 0, 进入第三步,否则进行第七步
7. 输出rev
现在,创建一个名为**`numbers.sh**`文件,并添加以下代码。
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 number"
echo " I will find reverse of given number"
echo " For eg. $0 0123, I will print 3210"
exit 1
fi
n=$1
rev=0
sd=0
while [ $n -gt 0 ]
do
sd=`expr $n % 10`
rev=`expr $rev \* 10 + $sd`
n=`expr $n / 10`
done
echo "Reverse number is $rev"
授予对文件的执行权限,并运行如下所示的脚本。
# chmod 755 numbers.h
**Condition 1**: 当输入不包含命令行参数,你将得到下面的输出。
#### Sample Output ####
./numbers.sh
Usage: ./numbers.sh number
I will find reverse of given number
For eg. ./2.sh 123, I will print 321
**Condition 2**: 正常输入
$ ./numbers.sh 10572
Reverse number is 27501
上面的脚本非常完美,输出正是我们需要的。
### 4. 你应该直接用终端而不是依靠任何shell脚本来进行实数计算。你会怎么做比如实数7.56+2.453 ###
> **Answer** :
我们需要用如下所述的特殊方式使用bc命令。将7.56+2.453作为输入通过管道进入bc中。
$ echo 7.56 + 2.453 | bc
10.013
### 5. 你需要给出圆周率的值精度为小数点后100位什么是最简单的方法。 ###
> **Answer** : 找圆周率的值最简单的方法,我们只是需要发出以下命令。
# pi 100
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
很明显!安装我们必须有包**`pi`**。只是一个**apt**或**yum**命令,就能获得所需的软件包,同时用最简单方法来实现这个需求。
就是这样。我会很快在Tecmint.com发表另一个有趣的文章。至此敬请关注。别忘了向我们提供您在的评论和反馈。
--------------------------------------------------------------------------------
via: http://www.tecmint.com/practical-interview-questions-on-linux-shell-scripting/
译者:[MikeCoder](https://github.com/MikeCoder) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://www.tecmint.com/category/interview-questions/