说明:只对vmet8 进行说明
环境:
vmet8 :172.16.43.0网段
vmware虚拟机IP:172.16.43.141
R3 IP: 172.16.43.150
注:linux需要用 sudo gns3 来启动
1、云设置:
双击云,然后添加vmet8 即可
2、添加R3,连接云和R3,开启云和R3
3、设置R3 IP地址,开启f1/0端口
4、能相互ping通~~
说明:只对vmet8 进行说明
环境:
vmet8 :172.16.43.0网段
vmware虚拟机IP:172.16.43.141
R3 IP: 172.16.43.150
注:linux需要用 sudo gns3 来启动
1、云设置:
双击云,然后添加vmet8 即可
2、添加R3,连接云和R3,开启云和R3
3、设置R3 IP地址,开启f1/0端口
4、能相互ping通~~
主要是配置寄存器的用途和使用方法
使用packettracer 5.0 进行的实验
0、设置密码,以便清除
enable
configure terminal
enable password weo234f
end
copy running-config startup-config
show running-config
show version
reload
1、进ROM监控模式,并进行设置
reload进行时 按 CTRL+break 进入 break键为F12右边的右边的右边的键
confreg 0x2142
reset
系统自动重启,进系统后可看到 寄存器值为0X2142
en
show version
2、进行清除密码,重设寄存器值等操作
copy startup-config running-config
configure terminal
enable password 123456
config-register 0x2102
end
copy running-config startup-config
sh version
reload
R0开通SSH服务,R1进行连接
1、设置R0 IP,开启F1/0
enable
configure terminal
interface fastethernet 1/0
no shutdown
ip address 19.168.1.1 255.255.255.0
exit
2、设置进特权密码
enable secret 123456
3、设置ssh
hostname a123
#没设置hostname会出现
ip domain-name a.com
crypto key generate rsa general-keys modulus 1024
ip ssh time-out 60 #会话空闲60秒
ip ssh authentication-retries 3 #错误尝试3次
line vty 0 4
transport input ssh
login#出现提示
4、设置vty登录账户及密码
exit
aaa new-model
aaa authentication login default local
username test password test
5、设置进特权密码
enable secret 123456
end
copy running-config startup-config
-——————————————————————————————-
1、设置R1 IP,开启端口
enable
configure terminal
interface fastethernet 1/0
no shutdown
ip address 19.168.1.2 255.255.255.0
end
2、SSH到R0
ssh -l test 192.168.1.1
然后输入密码test
enable
然后输入密码 123456
-——————————————————————————————–
1、取消ssh服务
crypto key zeroize rsa
参考文章:http://wenku.baidu.com/view/2e81590bf78a6529647d537f.html
环境:
本机:ubuntu10.04.4
vmware:ubuntu8.04.4
说明:
由于没有建DNS服务器,所以在本机上修改了hosts文件
sudo nano /etc/hosts 添加
172.16.43.140 www.a.com
172.16.43.140 www.b.com
1、建虚拟目录
/var/www/www.a.com
/var/www/www.b.com
2、建配置文件
cd /etc/apache2/sites-available
sudo cp default www.a.com
sudo cp default www.b.com
3、修改www.a.com 和 www.b.com 的配置文件
www.a.com配置如下
NameVirtualHost 172.16.43.140
<VirtualHost 172.16.43.140>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/www.a.com
ServerName www.a.com
Options FollowSymLinks
AllowOverride None
<Directory /var/www/www.a.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
后面略。。。。
#NameVirtualHost *
<VirtualHost 172.16.43.140>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/www.b.com
ServerName www.b.com
Options FollowSymLinks
AllowOverride None
<Directory /var/www/www.b.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
后面略。。。
4、重启apache2
sudo a2dissite default
sudo a2ensite www.a.com
sudo a2ensite www.b.com
sudo /etc/init.d/apache2 restart
5、访问网站
1、安装lamp套装
sudo apt-get install apache2 libapache2-mod-php5 php5-mysql mysql-server php5-memcache php5-gd
说明:
php5-gd用于处理图片格式
php5-memcache 用于把内存做缓存用
2、创建数据库、建用户等
nano mydb.sql
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users`(
`uid` int(10) unsigned NOT NULL default ‘0’,
`name` varchar(60) NOT NULL default ‘’,
`pass` varchar(32) NOT NULL default ‘’,
`mail` varchar(64) default ‘’,
PRIMARY KEY (`uid`),
UNIQUE KEY `name` (`name`)
);INSERT INTO `users` (`uid`, `name`, `pass`, `mail`) VALUES
(1, ‘Hiweed’, MD5(‘passwdHiweed’), ‘hiweed@test.com’),
(2, ‘Ning’, MD5(‘passwdNing’), ‘ning@test.com’),
(3, ‘Guoce’, MD5(‘passwdGuoce’), ‘guoce@test.com’)mysqladmin -uroot -p create mydb
mysql mydb -uroot -p < mydb.sql
检查导入的数据是否正确
mysql mydb -uroot -p 然后输入密码
mysql> select * from users;
建用户并设置权限
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, ALTER ON mydb.* TO ‘abc’@’localhost’ IDENTIFIED BY ‘123456’;
Query OK, 0 rows affected (0.00 sec)mysql> flush privileges; #刷新使之生效
Query OK, 0 rows affected (0.00 sec)mysql> exit
Bye
3、测试PHP
echo ““ | sudo tee /var/www/www.a.com/phpinfo.php
装phpmyadmin
sudo apt-get install phpmyadmin
sudo ln -s /usr/share/phpmyadmin /var/www/www.a.com/phpmyadmin
4、建站实例drupal
1、下载drupal
http://drupal.org/node/3060/release?api\_version\[\]=87
按书上的,我下载的也是6.6版本
tar xvf drupal-6.6.tar.gz
sudo mv drupal-6.6/{*,.htaccess} /var/www/www.a.com2、建drupal数据库和用户
mysqladmin -uroot -p create drupal6
mysql -uroot -p
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON drupal6.* TO ‘drupaluser’@’localhost’ IDENTIFIED BY ‘123456’;
Query OK, 0 rows affected (0.01 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)mysql> \q
Bye3、开启clean url功能
sudo nano /etc/apache2/sites-available/www.a.com
把<Direectory /var/www/www.a.com/> 下面的
allowoverride none 改为allowoverride all4、配置drupal
第二步 要更改权限
sudo chmod o+w /var/www/www.a.com/sites/default
sudo chmod o+w /var/www/www.a.com/sites/default/settings.php
第五步 再把权限改回来
sudo chmod o-w /var/www/www.a.com/sites/default
sudo chmod o-w /var/www/www.a.com/sites/default/settings.php
5、建wordpress
1、建wordpress数据库和用户
mysqladmin -uroot -p create wordpress
mysql -uroot -p
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON wordpress.* TO ‘wordpress’@’localhost’ IDENTIFIED BY ‘123456’;
Query OK, 0 rows affected (0.01 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)mysql> \q
Bye2、改所有者
sudo chown -R www-data:www-data /var/www/wordpress3、然后下一步下一步即可
附、更改上传文件的大小限制
sudo gedit /etc/php5/apache2/php.ini
更改post_max_size=200M
file_uploads=On
upload_max_filesize=100M
apache2.conf默认配置如下
ServerRoot “/etc/apache2”
LockFile /var/lock/apache2/accept.lock
PidFile ${APACHE_PID_FILE}
# Timeout: The number of seconds before receives and sends time out.
Timeout 300
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to “Off” to deactivate.
KeepAlive On
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
MaxKeepAliveRequests 100
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
KeepAliveTimeout 15 #保持连接15秒不断开
# prefork MPM
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
# worker MPM
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150 #最大连接数
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
AccessFileName .htaccess
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
<Files ~ “^\.ht”>
Order allow,deny
Deny from all
DefaultType text/plain
HostnameLookups Off #off只获取客户的IP地址,on则获取客户的DNS
ErrorLog /var/log/apache2/error.log
LogLevel warn
# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
# Include all the user configurations:
Include /etc/apache2/httpd.conf
# Include ports listing
Include /etc/apache2/ports.conf
LogFormat “%h %l %u %t \“%r\“ %>s %b \“%{Referer}i\“ \“%{User-Agent}i\“” combined
LogFormat “%h %l %u %t \“%r\“ %>s %b” common
LogFormat “%{Referer}i -> %U” referer
LogFormat “%{User-agent}i” agent
ServerTokens Full #显示HTTP响应头的信息
ServerSignature On
Include /etc/apache2/sites-enabled/
1、建虚拟目录
/var/www/www.a.com
/var/www/www.b.com
2、修改/etc/apache2/ports.conf
加入Listen 8080
3、建配置文件
cd /etc/apache2/sites-available
sudo cp default www.a.com
sudo cp default www.b.com
4、修改www.a.com 和 www.b.com 的配置文件
www.a.com配置如下
NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/www.a.com
ServerName www.a.com
Options FollowSymLinks
AllowOverride None
<Directory /var/www/www.a.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
后面略。。。。
<VirtualHost 172.16.43.140:8080>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/www.b.com
ServerName www.b.com
Options FollowSymLinks
AllowOverride None
<Directory /var/www/www.b.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
后面略。。。
5、重启apache2
sudo a2dissite default
sudo a2ensite www.a.com
sudo a2ensite www.b.com
sudo /etc/init.d/apache2 restart
然后访问www.a.com 就输入 172.16.43.140
访问www.b.com 就输入 172.16.43.140:8080
参考:
http://wenku.baidu.com/view/c61a0dd6b9f3f90f76c61b18.html
http://httpd.apache.org/docs/2.2/vhosts/examples.html
文件位置:/etc/apache2/sites-available/default
文档分2部分:NameVirtualHost 和
NameVirtualHost * 指定服务器的网卡,开通线路等
<VirtualHost *> 指定虚拟主机的IP地址。
ServerAdmin webmaster@localhost 指定站长EMAIL
DocumentRoot /var/www/ 指定网站根目录
1>更改为网站存放的位置:如/var/www/blog.test.com
Options FollowSymLinks 网站根目录的特性,允许使用符号链接
AllowOverride None 网站根目录的特性,忽略.htaccess文件的作用
<Directory /var/www/> 2>更改为网站存放的位置:如/var/www/blog.test.com
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny acl设置,符合下一行allow规则的都能访问,不符合allow规则的不能访问
# Order deny,allow acl设置,符合下一行deny规则的都不能访问,不符合deny规则的能访问
allow from all 控制哪些主机可以访问,默认所有主机都可以访问
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory “/usr/lib/cgi-bin”>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
ErrorLog /var/log/apache2/error.log 3>log存放的文档位置
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn 4>设置log信息的等级
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ “/usr/share/doc/“ 设置别名,访问/var/www/blog.test.com/doc 其实就是访问/usr/share/doc
<Directory “/usr/share/doc/“>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
安装apache2-mpm-worker
sudo apt-get install apache2
配置文件说明
apache2.conf:全局配置文件,如允许的进程数、日志等级、ServerTokens等多在这边设置
envvars:环境变量,运行apache的用户名和组就在这边设置
httpd.conf:用户配置文件,默认空
ports.conf:SSL的端口号
conf.d:好像是跟编码有关的配置,不是很清楚
mods-available: 可用的模块
mods-enabled:已在用的模块
sites-available: 存在的虚拟主机(网站)
sites-enabled: 已经对外服务的虚拟主机
查看模块
查看可用模块:sudo a2enmod
查看已用模块:sudo a2dismod
查找要安装的模块名称:apt-cache search xxx
虚拟主机
虚拟主机有两种:基于IP和基于域名
虚拟主机(网站)存放位置:一般为 /var/www/ 下
虚拟主机的配置文件放在:/etc/apache2/sites-available/ 注:对每个虚拟主机单独建配置文件比较好
已用的虚拟主机配置文件:/etc/apache2/sites-enable/ 通过a2dissite 和a2ensite 来关闭/开启虚拟主机
注:用a2ensite和a2dissite后,sites-enable下会自动创建符号链接
详见:ubuntus 最佳方案 3-基于端口的多虚拟主机
虚拟主机配置详解
详见:ubuntus 最佳方案 3-apache2 default文件介绍
HTTPS的实现
sudo a2enmod ssl
sudo /etc/init.d/apache2 reload
sudo apt-get install openssl
-————————————-
openssl genrsa -des3 -out server.key 1024 #然后输入密码
openssl req -new -key server.key -out server.csr #先输入密码,再输信息
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
sudo cp server.crt /etc/ssl/certs #公钥
sudo cp server.key /etc/ssl/private #私钥
-————————————
更改虚拟主机配置
添加:
SSLEngine on
SSLOptions +StrictRequire
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
-—————————————–sudo /etc/init.d/apache2 restart
https://172.16.43.140
Apache 性能优化
详见 ubuntus 最佳方案 3-apache.conf
启用压缩
sudo a2enmod deflate
sudo /etc/init.d/apache2 force-reload
配置文件为:/etc/apache2/mods-enabled/deflate.conf
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml
使用缓存
sudo a2enmod disk_cache (sudo a2enmod mem_cache)
配置文件/etc/apache2/sites-available/www.a.com
在最后添加:
<IfModule mod_disk_cache.c>
CacheEnable disk / #缓存类型为硬盘 /为网站的根目录,即对整个网站启用缓存
CacheRoot /var/www/www.a.com/cache
CacheDefaultExpire 7200 #失效周期,7200s
CacheMaxExpire 604800 #最大失效周期,604800s
创建cache文件夹
sudo mkdir /var/www/www.a.com/cache
sudo chown www-data:www-data /var/www/www.a.com/cache
sudo /etc/init.d/apache2 restart
压力测试
ab -n 20000 -c 200 http://localhost/
ab apache benchmarking
-n 发送总数
-c 一次发送
Apache安全相关
查看http文件头
telnet 172.16.43.140 80
然后输入HEAD / HTTP/1.0
然后可以看到
更改方法:更改/etc/apache2/apache2.conf 里面的ServerTokens:prod
DDOS防范
略
Apache 日志分析
系统使用:ubuntu-8.04.4-server-i386.iso
1、文件目录
/sys:用于存放系统信息
2、/etc/fstab
sudo blkid 查看分区uuid
3、lvm 逻辑卷管理器
硬盘上面建lvm,lvm上面建分区。易于扩容和备份等
4、tasksel 用于快速安装服务套件
5、更改语系
查看当前语言设置:locale
语言设置文件:/etc/default/locale
6、nano使用方法
ctrl+o :保存
ctrl+x :退出
ctrl+w:查找
ctrl+k: 剪切
ctrl+u:撤销
7、mc 图形化资源管理器
8、包管理软件
—-apt工具
apt相关文件
/etc/apt/sources.list 软件包资源列表
/etc/apt/apt.conf.d apt零碎配置文件
/var/cache/apt/archives 存放已经下载的软件包
apt软件仓库分类
main 自由软件,ubuntu完全支持
restricted 不完全自由软件,但被广泛使用,ubuntu也提供支持
universe 依赖社区提供支持,ubuntu不提供安全补丁等支持
multiverse 非自由软件,完全没有支持
apt-get命令
update 更新软件包列表
upgrade 升级所有软件包
purge 彻底删除软件包
source 下载源码包
dist-upgrade 升级整个发行版
apt-cache命令
search 搜索软件包在ubuntu下的名字
aptitude命令
图形界面安装软件
dpkg命令
dpkg -l 查找软件包是否已经安装
dpkg -L 查找软件包包含哪些文件
dpkg -C 查找哪些软件未完成安装
dpkg-reconfigure 自动配置已安装的软件包
9、服务的启动和停止
update-rc.d apache defaults 设置默认启动
update-rc.d apache purge 不自动启动
10、网络配置
/etc/network/interfaces 网卡及IP地址配置文件
重启网络
/etc/init.d/networking restart
DNS配置文件
/etc/resolv.conf
hosts文件
/etc/hosts
11、时间同步(每天同步一次)
sudo nano /etc/cron.daily/timeupdate
添加: ntpdate ntp.ubuntu.com
关于ntp servers,访问:http://tf.nist.gov/tf-cgi/servers.cgi
sudo chmod 755 /etc/cron.daily/timeupdate
12、远程管理ubuntus
—服务器上安装ssh-s
sudo apt-get install openssh-server
ssh配置文件:/etc/ssh/sshd_config
—客户端远程登录服务器
ssh xxx@172.16.43.140 然后输入xxx的密码(xxx为服务器的用户名)
查看那些人登录到本机:who
踢出用户:
ps -ef | grep pts/0
kill -9 5593