设为首页 收藏本站
查看: 1682|回复: 0

使用rpm包实现LAMP构架模型

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-5-4 08:59:57 | 显示全部楼层 |阅读模式
友情提示:本文系统环境:Centos 6.6 X86_64 KDE DISKTOP + VirtualBOX(Centos 6.6 X86_64,安装类型选择为server), KSnapshot抓图,Konsole 终端连接远程虚拟机。
    LAMP是Linux,Apache,Mysql,Php(perl/python)的简写,Linux提供OS平台,Apche(现在应该称为httpd)提供html协议报文的解析和响应,Mysql提供结构化数据的查询,Php(或者perl,python)的应用程序提供脚本语言的解析,4者合力实现了web动态网站,是种非常经典的wen站点的构架。现在非常著名的电商站点淘宝,当初创建之时也就是采用的这种构架,详见子柳所著《淘宝技术这十年》。
    Apache(下面称为httpd),Mysql,Php这三者可以放置以同一服务器,也可各自各自以独立守护进程形式安装在不同的服务器上。在一台服务器上实现时,httpd同php可以以3种形式组合:php作为httpd的一个模块;使用fastcgi做为协议来组合;使用cgi做为协议来组合。本文采用:Centos系统光盘自带rpm包在一台服务器上实现LAMP构架模型,php采用模块形式同httpd组合在一起。
    实验环境:
实验网络为:172.16.0.0/16

主机
IP地址
角色
Test02.lijun.com
172.16.34.2/16
提供OS平台

提供基于80端口的虚拟主机站点:www.mywordpress.com

提供基于443端口的虚拟主机站点:www.myphpadmin.com

server.lijun.com
172.16.34.100/16
站点测试机
    实验步骤:
一。构建yum环境,提供程序包的安装源。
    1.1)使用Centos6.6 x86_64 DVD1系统光盘,挂载至系统。
wKiom1VDjtSxw7MAAAQC3BVn1Tw852.jpg
1
2
3
4
5
6
7
8
9
10
[lijun@Test02 ~]$ mount | egrep '(cdrom|sr0|media)'
[lijun@Test02 ~]$ sudo mount -r /dev/sr0 /media
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
[sudo] password for lijun:
[lijun@Test02 ~]$ mount | egrep '(cdrom|sr0|media)'
/dev/sr0 on /media type iso9660 (ro)



    1.2)建立本地yum repo文件,指导yum程序安装rpm包
#设定本地repo文件

1
2
3
4
5
6
7
8
9
10
11
[lijun@Test02 ~]$ cd /etc/yum.repos.d/
[lijun@Test02 yum.repos.d]$ sudo mkdir beifen
[lijun@Test02 yum.repos.d]$ sudo mv CentOS* beifen/
[lijun@Test02 yum.repos.d]$ sudo touch local.repo
[lijun@Test02 yum.repos.d]$ sudo vim local.repo
[localyumrepo]
name='this is local yum source'
baseurl=file:///media/
enable=1
gpgcheck=0
:wq




#建立本地yum库缓存

1
2
3
4
5
6
7
8
9
10
11
12
[lijun@Test02 yum.repos.d]$ sudo yum clean all
已加载插件:fastestmirror, security           
Cleaning repos: localyumrepo                  
清理一切                                      
[lijun@Test02 yum.repos.d]$ sudo yum repolist
已加载插件:fastestmirror, security         
Determining fastest mirrors                  
localyumrepo                                                                    | 4.0 kB     00:00 ...
localyumrepo/primary_db                                                         | 4.5 MB     00:00 ...
仓库标识                                  仓库名称                                                状态
localyumrepo                              'this is local yum source'                              6,518
repolist: 6,518



1
2
3
4
5
6
7
8
9

[lijun@Test02 yum.repos.d]$ sudo yum makecache
已加载插件:fastestmirror, security           
Loading mirror speeds from cached hostfile   
localyumrepo                                                                    | 4.0 kB     00:00 ...
localyumrepo/group_gz                                                           | 216 kB     00:00 ...
localyumrepo/filelists_db                                                       | 6.0 MB     00:00 ...
localyumrepo/other_db                                                           | 2.8 MB     00:00 ...
元数据缓存已建立




#安装tree命令包做测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[lijun@Test02 yum.repos.d]$ sudo yum -y install tree                                                   
已加载插件:fastestmirror, security                                                                    
设置安装进程                                                                                          
Loading mirror speeds from cached hostfile                                                            
解决依赖关系                                                                                          
--> 执行事务检查                                                                                       
---> Package tree.x86_64 0:1.5.3-2.el6 will be 安装                                                   
--> 完成依赖关系计算                                                                                   
依赖关系解决
=======================================================================================================
软件包             架构                 版本                         仓库                        大小
=======================================================================================================
正在安装:
tree               x86_64               1.5.3-2.el6                  localyumrepo                36 k
事务概要
=======================================================================================================
Install       1 Package(s)
总下载量:36 k
Installed size: 65 k
下载软件包:
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
  正在安装   : tree-1.5.3-2.el6.x86_64                                                             1/1
  Verifying  : tree-1.5.3-2.el6.x86_64                                                             1/1
已安装:
  tree.x86_64 0:1.5.3-2.el6
完毕!
[lijun@Test02 yum.repos.d]$




二.安装程序包,并设定程序启动
php-mysql是php应用程序服务程序中提供mysql查询的驱动程序。
1
2
3
4
5
6
7
8
9
10
11
[lijun@Test02 yum.repos.d]$ sudo yum -y install httpd php mysql-server php-mysql mod_ssl
。。。。。。
已安装:
  httpd.x86_64 0:2.2.15-39.el6.centos        mod_ssl.x86_64 1:2.2.15-39.el6.centos        mysql-server.x86_64 0:5.1.73-3.el6_5
  php.x86_64 0:5.3.3-38.el6                  php-mysql.x86_64 0:5.3.3-38.el6
作为依赖被安装:
  apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1       httpd-tools.x86_64 0:2.2.15-39.el6.centos       mysql.x86_64 0:5.1.73-3.el6_5
  perl-DBD-MySQL.x86_64 0:4.013-3.el6          php-cli.x86_64 0:5.3.3-38.el6                   php-common.x86_64 0:5.3.3-38.el6
  php-pdo.x86_64 0:5.3.3-38.el6
完毕!
[lijun@Test02 yum.repos.d]$



#mysql启动并初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[lijun@Test02 ~]$ sudo service mysqld  start
Initializing MySQL database:  WARNING: The host 'Test02.lijun.com' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible                                    
with this binary MySQL version. The MySQL daemon, mysqld, should work                                    
normally with the exception that host name resolving will not work.                                      
This means that you should use IP addresses instead of hostnames                                         
when specifying MySQL privileges !                                                                       
Installing MySQL system tables...                                                                        
OK                                                                                                      
Filling help tables...                                                                                   
OK                                                                                                      
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h Test02.lijun.com password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[lijun@Test02 ~]$




三 修改httpd配置文件,配置虚拟主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[lijun@Test02 ~]$ cd /etc/httpd/conf
[lijun@Test02 conf]$ sudo cp httpd.conf{,.bak}
[lijun@Test02 conf]$ sudo vim httpd.conf
ServerName 127.0.0.1:80
#DocumentRoot "/var/www/html"
NameVirtualHost *:80
<VirtualHost 172.16.34.1:80>   
ServerAdmin admin@mywordpress.com   
DocumentRoot /var/www/mywordpress.com   
ServerName www.mywordpress.com   
ErrorLog logs/mywordpress.com-error_log   
CustomLog logs/mywordpress.com-access_log common
</VirtualHost>
:wq

[lijun@Test02 conf]$ cd ../conf.d/
[lijun@Test02 conf.d]$ sudo cp ssl.conf{,.bak}
[lijun@Test02 conf.d]$ sudo vim ssl.conf
<VirtualHost 192.168.1.20:443>
DocumentRoot "/var/www/myphpadmin.com"
ServerName
SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
:wq

[lijun@Test02 conf.d]$ cd /var/www
[lijun@Test02 www]$ sudo mkdir mywordpress.com
[lijun@Test02 www]$ sudo mkdir myphpadmin.com




四 建立私有CA,自己给自己签署证书用于https站点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#建立https站点使用证书和私钥目录
[lijun@Test02 www]$ sudo mkdir /etc/httpd/ssl/
[lijun@Test02 www]$ cd /etc/pki/CA
[lijun@Test02 CA]$ ls
certs  crl  newcerts  private
[lijun@Test02 CA]$ su -
密码:

#生成CA私钥
[iyunv@Test02 ~]# cd /etc/pki/CA
[iyunv@Test02 CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus.................................
..........+++.......................................................................
....................................................................................
........+++e is 65537 (0x10001)

#生成CA自签证书
[iyunv@Test02 CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3660
You are about to be asked to enter information that will be incorporatedinto your
certificate request.What you are about to enter is what is called a Distinguished
Name or a DN.There are quite a few fields but you can leave some blankFor some
fields there will be a default value,If you enter '.',
  the field will be left blank.-----
  Country Name (2 letter code) [XX]:CN
  State or Province Name (full name) []:HN
  Locality Name (eg, city) [Default City]:ZZ
  Organization Name (eg, company) [Default Company Ltd]:lijun
  Organizational Unit Name (eg, section) []:Ops
  Common Name (eg, your name or your server's hostname) []:ca.lijun.com
  Email Address []:admin@lijun.com
  [iyunv@Test02 CA]# ls
  cacert.pem  certs  crl  newcerts  private
  [iyunv@Test02 CA]# touch index.txt
  [iyunv@Test02 CA]# touch serial
  [iyunv@Test02 CA]# echo 01 > serial
  [iyunv@Test02 CA]# cat serial
  01

#为https站点生成私钥
[iyunv@Test02 CA]# (umask 077;openssl genrsa -out /etc/httpd/ssl/httpd.key 1024)
Generating RSA private key, 1024 bit long modulus                             
.......................++++++                                                
.......++++++e is 65537 (0x10001)

#为https站点生成证书申请                                                         
[iyunv@Test02 CA]# openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr
You are about to be asked to enter information that will be incorporated   
into your certificate request.                                       
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blankFor some fields there will be
a default value,If you enter '.', the field will be left blank.-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HN
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:lijun
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server's hostname) []:www,myphpadmin.com
Email Address []:admin@myphpadmin.comPlease enter the following 'extra'
attributesto be sent with your certificate requestA
challenge password []:
An optional company name []:
[iyunv@Test02 CA]# ls /etc/httpd/ssl/
httpd.csr  httpd.key
[iyunv@Test02 CA]#

#为https站点签署证书
[iyunv@Test02 CA]# openssl ca -in /etc/httpd/ssl/httpd.csr  -out /etc/httpd/ssl/httpd.crt -days 366
Using configuration from /etc/pki/tls/openssl.cnf                                                
Check that the request matches the signature                                                      
Signature ok                                                                                      
Certificate Details:                                                                              
        Serial Number: 1 (0x1)                                                                    
        Validity                                                                                 
            Not Before: Apr 30 20:05:16 2015 GMT                                                  
            Not After : Apr 30 20:05:16 2016 GMT                                                  
        Subject:                                                                                 
            countryName               = CN                                                        
            stateOrProvinceName       = HN                                                        
            organizationName          = lijun                                                     
            organizationalUnitName    = Ops                                                      
            commonName                = www,myphpadmin.com                                       
            emailAddress              = admin@myphpadmin.com                                      
        X509v3 extensions:                                                                        
            X509v3 Basic Constraints:                                                            
                CA:FALSE                                                                          
            Netscape Comment:                                                                     
                OpenSSL Generated Certificate                                                     
            X509v3 Subject Key Identifier:                                                        
                6D:45:30:0B:DC:12:11:83:9C:37:63:FF:3A:14:49:18:5D:71:D8:D6                       
            X509v3 Authority Key Identifier:                                                      
                keyid:BD:88:4A:1C:EC:CF:95:E4:03:41:B0:60:9E:A2:69:B3:66:8A:ED:5D                 

Certificate is to be certified until Apr 30 20:05:16 2016 GMT (366 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[iyunv@Test02 CA]# ls /etc/httpd/ssl
httpd.crt  httpd.csr  httpd.key
[iyunv@Test02 CA]#



五 建立基于80端口的虚拟主机站点www.mywordpress.com的站点文档

#建立wordpress程序需要使用的mysql库和用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[lijun@Test02 ~]$ sudo mysql
mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> create user 'lijun'@'localhost' identified by 'redhat'; -->若密码,纯测试
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on  wordpress.*TO 'lijun'@'localhost';  -->权限过大,纯测试                                          
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[lijun@Test02 ~]$



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#建立www.mywordpress.com的站点文档
[lijun@Test02 ~]$ cd /var/www/mywordpress.com/
[lijun@Test02 mywordpress.com]$sudo cp ~lijun/source/wordpress-3.2.1-zh_CN.zip .
[lijun@Test02 mywordpress.com]$sudo unzip wordpress-3.2.1-zh_CN.zip
[lijun@Test02 mywordpress.com]$ sudo cp -a wordpress/* .
[lijun@Test02 mywordpress.com]$ sudo cp wp-config-sample.php  wp-config.php
[lijun@Test02 mywordpress.com]$ sudo vim wp-config.php
define('DB_NAME', 'wordpress');

/** MySQL 数据库用户名 */
define('DB_USER', 'lijun');

/** MySQL 数据库密码 */
define('DB_PASSWORD', 'redhat');

/** MySQL 主机 */
define('DB_HOST', 'localhost');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');

/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');
:wq




六.建立https虚拟主机站点使用文档

1
2
3
4
5
6
[lijun@Test02 httpd]$ cd /var/www/myphpadmin.com/                                                              
[lijun@Test02 myphpadmin.com]$ sudo cp ~lijun/source/phpMyAdmin-3.2.5-all-languages.tar.gz  .                                                      
[lijun@Test02 myphpadmin.com]$ sudo tar -xf phpMyAdmin-3.2.5-all-languages.tar.gz
[lijun@Test02 myphpadmin.com]$ ls                                                
phpMyAdmin-3.2.5-all-languages  phpMyAdmin-3.2.5-all-languages.tar.gz     
[lijun@Test02 myphpadmin.com]$ sudo cp -a phpMyAdmin-3.2.5-all-languages/* .




七设定防火墙和selinux
可以通过#server iptables stop 和 #setenforce 0 来关闭防火墙和设定selinux状态,防止干扰测试
也可以按下面的设定:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[lijun@Test02 httpd]$ sudo iptables -IINPUT -p tcp -s 172.16.0.0/16 -d 172.16.34.2 -m multiport --dports 80,443 -j ACCEPT
[lijun@Test02 httpd]$ sudo iptables -IINPUT 2  -p tcp  -d 172.16.34.2 -m multiport --dports 80,443 -j DROP
[lijun@Test02 httpd]$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  172.16.0.0/16        172.16.34.2         multiport dports http,https
DROP       tcp  --  anywhere             172.16.34.2         multiport dports http,https
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited



1
2
3
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
[lijun@Test02 httpd]$setselinux 0



八 测试机上进行测试:
#因没有设定DNS,只能使用测试主机的host文件进行设定

1
2
3
4
[lijun@server ~]$ sudo vim /etc/hosts
172.16.34.2     www.mywordpress.com
172.16.34.2     www,myphpadmin.com
:wq



wKioL1VDne-weV5JAAG_UvDxhMk104.jpg

wKiom1VDnKjhW6W-AAKl-0EWm24669.jpg
wKioL1VDnjKiJUP6AAFr5GOqrj4775.jpg
wKiom1VDnOWTJHTKAAFl3xfuDs8655.jpg
wKiom1VDnRaRrmMDAAFFMqNQeJY158.jpg
wKioL1VDnrCxXeH4AAPu3P6mscA085.jpg
wKioL1VDnsyB4Hp5AAW8Yiae7Cc246.jpg

下面时https站点:
wKiom1VDnYOTsb80AAJkmC8JUdM997.jpg

wKioL1VDnwTwqUBiAAH-zD3n1zM981.jpg

PS:KDE桌面着实让我惊艳了一下,无论笔记本散热量还是程序启动速度与稳定性,都比win7表现要好,
    现在除了聊QQ,观看加密视频不方便外,其他均可胜任平常使用需要。
    路人甲: 什么?你把Centos 6.6 X86_64 社区企业版装在笔记本上用?你个疯子!!!
    海盗哥:再敢嘲讽拉仇恨,哥放狗狗---斯派克去咬你的丁丁。





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-63376-1-1.html 上篇帖子: rpm包格式安装配置lamp提供两个虚拟主机分别wordpress和phpMyAdmin,后一个提供ssl访问方式。 下篇帖子: bash-scripts源码安装lamp(apache、php及部分扩展、mysql) 模型
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表