SA之测试机练习
一、 ssh登录测试机。
1.1)在本机上先察看ssh服务是否开启:
ssh localhost
如果报错:
ssh: connect to host localhost port 22: Connection refused
可能是ssh-server没有开启或未安装,输入ps -e | grep ssh察看(PS指令参考):
ps -e | grep ssh
如果没有sshd项,说明ssh-server没有开启。输入/etc/init.d/ssh -start启动sshd
/etc/init.d/ssh start
如果/etc/init.d/目录下没找到ssh,说明ssh-sever没安装。输入如下指令安装:
sudo apt-get install openssh-server
然后输入/etc/init.d/ssh -start启动ssh-server,如果报如下错误:
* Starting OpenBSD Secure Shell server sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key Could not load host key: /etc/ssh/ssh_host_dsa_key Could not load host key: /etc/ssh/ssh_host_ecdsa_key
出现这个问题的原因有2个,其一是没有权限访问这些key,解决方法很简单
sudo /etc/init.d/ssh start
如果仍报错,原因为系统丢失了ssh_host_dsa_key、ssh_host_rsa_key等key,使用以下命令重新生成。
sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key Generating public/private dsa key pair. /etc/ssh/ssh_host_dsa_key already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): //直接回车 Enter same passphrase again: //直接回车 Your identification has been saved in /etc/ssh/ssh_host_dsa_key. Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub. The key fingerprint is:
依次类推重新生成缺失的key。
1.2)传输文件
如果是测试机端从主机接受文件,在测试机端按以下格式输入指令
scp 主机名@IP:文件路径 测试机端接受文件目录
--------------------------------------------------------
[root@one-594 software]# scp happy@192.168.188.150:/home/happy/download/php-5.5.0.tar.bz2 /var/software/
如果是主机发送文件给测试机,在主机端按以下格式输入指令
-----------------------
二、测试机安装软件
2.1) 安装Apache
下载httpd服务器
[root@one-594 bin]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.6.tar.bz2
进入httpd的目录
[root@one-594 software]# cd /var/software/ [root@one-594 software]# tar xjvf httpd-2.4.4.tar.bz2 [root@one-594 software]# mkdir httpd [root@one-594 software]# cd httpd-2.4.4 [root@one-594 httpd-2.4.4]# ./configure --prefix=/var/software/httpd --------------------报错-------------------------- configure: checking for APR... no configure: error: APR not found. Please read the documentation
安装apr
[root@one-594 software]# wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz [root@one-594 software]# tar xvzf apr-1.4.5.tar.gz [root@one-594 software]# cd apr-1.4.5 [root@one-594 apr-1.4.5]# ./configure [root@one-594 apr-1.4.5]# make [root@one-594 apr-1.4.5]# make install
安装apr-util
[root@one-594 software]# wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz [root@one-594 software]# tar xzvf apr-util-1.3.12.tar.gz [root@one-594 software]# cd apr-util-1.3.12 [root@one-594 apr-util-1.3.12]# ./configure --with-apr=/usr/local/apr [root@one-594 apr-util-1.3.12]# make [root@one-594 apr-util-1.3.12]# make install
同理安装pcre
[root@one-594 software]# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
然后解压并安装,此略。
再次安装Apache
[root@one-594 httpd-2.4.4]# ./configure --prefix=/var/software/httpd [root@one-594 httpd-2.4.4]# make [root@one-594 httpd-2.4.4]# make install [root@one-594 httpd-2.4.4]# ../httpd/bin/apachectl start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.10.3.201. Set the 'ServerName' directive globally to suppress this message
//修改
[root@one-594 httpd-2.4.4]# vi ../httpd/conf/httpd.conf
找到
# If your host doesn't have a registered DNS name, enter its IP address here. # # ServerName www.example.com:8080 //去掉"#"
去掉# ServerName www.example.com:8080前的"#"即可。
[root@one-594 httpd-2.4.4]# ../httpd/bin/apachectl start httpd (pid 26321) already running
安装成功,关掉Apache,安装php
[root@one-594 httpd-2.4.4]# ../httpd/bin/apachectl stop
2.2)安装php5
[root@one-594 php-5.5.0]# ./configure --prefix=/var/software/php5 --with-apxs2=/var/software/httpd/bin/apxs --enable-fpm //enable-fpm为nginx中配置需要,为免重新安装,这里一并选上。 [root@one-594 php-5.5.0]# make [root@one-594 php-5.5.0]# make install //检验php5是否安装成功 [root@one-594 php-5.5.0]# ../php5/bin/php -v PHP 5.5.0 (cli) (built: Jul 10 2013 18:06:27) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.5.0-dev, Copyright (c) 1998-2013 Zend Technologies
出现上面类似信息说明安装成功。
2.3) 配置
将php配置文件拷贝至php5目录下
[root@one-594 php-5.5.0]# cp php.ini-development ../php5/php.ini
察看httpd中httpd.conf中是否加载php5,打开httpd.conf,察看是否有如下项:
#LoadModule rewrite_module modules/mod_rewrite.so LoadModule php5_module modules/libphp5.so
在httpd.conf添加如下行:
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
在httpd目录下面的htdocs新建test.php测试
//test.php <?php phpinfo(); ?>
输入php test.php,若出现相关信息,则成功。
2.4 安装Nginx
在官网上下载并安装Nginx相应版本后,开始配置nginx(若未安装php-fpm,需先安装)。
2.4.1)nginx默认安装后配置文件在/etc/nginx中,
[root@one-594 software]# cd /etc/nginx/ [root@one-594 nginx]# ls conf.d koi-win nginx.conf scgi_params win-utf fastcgi_params koi-utf mime.types uwsgi_params //将fastcgi_params拷贝至conf.d [root@one-594 nginx]# cp fastcgi_params conf.d/ [root@one-594 conf.d]# vi default.conf
其中具体修改为:
server {
listen 80 default;
server_name localhost;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
在php配置文件(php.ini)中打开cgi.fix_pathinfo选项:
cgi.fix_pathinfo=1
启动php-cgi:
[root@one-594 nginx]# php-cgi -b 127.0.0.1:9000
如果将php文件放在其他路径,需将location中的root值换成相应路径。重启服务:
[root@one-594 conf.d]# /etc/init.d/nginx reload Reloading nginx: [ OK ] [root@one-594 conf.d]# service nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ]
在路径html中新建test.php
<?php phpinfo(); ?>
在浏览器中输入localhost/test.php,出现php信息。
浙公网安备 33010602011771号