lamp架構=LAMP指的Linux(操做系統)、Apache(HTTP 服務器),MySQL(數據庫軟件) 和PHP(有時也是指Perl或Python) 的第一個字母,通常用來創建web 服務器。php
#############源碼安裝php###########html
tar jxf php-5.6.20.tar.bz2 node
cd php-5.6.20mysql
解決依賴性:nginx
yum install freetype-devel libmcrypt-2.5.8-9.el6.x86_64.rpm net-snmp-devel libmcrypt-devel-2.5.8-9.el6.x86_64.rpm libpng-devel gmp-devel libjpeg-turbo-devel libcurl-devel libxml2-devel -yweb
檢測依賴性:sql
[root@server1 php-5.6.20]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --without-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlndshell
沒有報錯以後就能夠執行如下操做:數據庫
[root@server1 php-5.6.20]# make && make install vim
[root@server1 php-5.6.20]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.20]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
cd /mnt/php-5.6.20/sapi/fpm/
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm
[root@server1 fpm]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# vim php-fpm.conf#取消25行的註釋
25 pid = run/php-fpm.pid
[root@server1 etc]# vim php.ini ##修改時區
925 date.timezone = 'Asia/Shanghai'
[root@server1 etc]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@server1 etc]# cd /usr/local/
[root@server1 local]# cd nginx/sbin/
[root@server1 sbin]# ls
nginx
[root@server1 sbin]# pwd
/usr/local/nginx/sbin
[root@server1 sbin]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
[root@server1 sbin]# source ~/.bash_profile
[root@server1 sbin]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
cd /usr/local/nginx/conf
[root@server1 conf]# vim nginx.conf
49 location / {
50 root html;
51 index index.php index.html index.htm;#調整優先級,先看index.php
52 }
71 location ~ \.php$ {
72 root html;
73 fastcgi_pass 127.0.0.1:9000;
74 fastcgi_index index.php;
75 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
76 include fastcgi.conf;
[root@server1 conf]# nginx
[root@server1 conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server1 conf]# cd ..
[root@server1 nginx]# cd html/
[root@server1 html]# vim nginx.php
<?php
phpinfo()
?>
找到當前主機mysql的緩存文件
[root@server1 mysql]# ll /var/lib/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 3月 23 17:16 /var/lib/mysql/mysql.sock
cd /usr/local/lnmp/php/etc
[root@server1 etc]# vim php.ini
#默認數據存儲在/var/lib/mysql/mysql.sock這個文件中
1001 pdo_mysql.default_socket=/var/lib/mysql/mysql.sock
1150 mysql.default_socket =/var/lib/mysql/mysql.sock
1209 mysqli.default_socket =/var/lib/mysql/mysql.sock
[root@server1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
測試:
Php安裝成功!
Heartbeat + mysql +drbd
三個部分分別提供了高可用,數據庫,以及存儲服務。將以後的論壇整合成一個完整的體系
說明:server3,server4提供以上三個服務
1數據庫
直接yum install mysql-server -y #server3和server4都作
mysql_secure_installation#安全初始化,設置root密碼,不然數據庫不要密碼也能登錄
2.Heartbeat
[root@server3 heartbeat]# ls
heartbeat-3.0.4-2.el6.x86_64.rpm heartbeat-libs-3.0.4-2.el6.x86_64.rpm
heartbeat-devel-3.0.4-2.el6.x86_64.rpm ldirectord-3.9.5-3.1.x86_64.rpm
Server3,server4都要安裝
[root@server3 heartbeat]# yum install * -y
[root@server3 heartbeat]# cd /etc/ha.d/
[root@server3 ha.d]# ls
harc rc.d README.config resource.d shellfuncs
[root@server3 ha.d]# cp /usr/share/doc/heartbeat-3.0.4/{authkeys,ha.cf,haresources} .
[root@server3 ha.d]# vim ha.cf
48 keepalive 2
56 deadtime 30
76 udpport 1111
91 bcast eth0
157 auto_failback on
211 node server3.example.com
212 node server4.example.com
222 ping 172.25.50.250
254 respawn hacluster /usr/lib64/heartbeat/ipfail
262 apiauth ipfail gid=haclient uid=hacluster
[root@server3 ha.d]# vim authkeys
23 auth 1
24 1 crc
25 #2 sha1 HI!
26 #3 md5 Hello!
[root@server3 ha.d]# vim haresources
在文件最後添加:
server3.example.com IPaddr::172.25.50.200/24/eth0 drbddisk::homework Filesystem::/dev/drbd2::/var/lib/mysql::ext4 mysqld
##作測試能夠用:server3.example.com IPaddr::172.25.50.200/24/eth0 mysqld(上面的是針對drbd所做的)
[root@server3 ha.d]# scp ha.cf haresources authkeys 172.25.50.40:/etc/ha.d/
兩邊都從新啓動heartbeat
3.drbd共享存儲
給server3和server4都劃分一個4G的虛擬磁盤
[root@server3 mnt]# fdisk -l
Disk /dev/vdb: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@server4 drbd]# fdisk -l
Disk /dev/vda: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
安裝如下rpm包
drbd-8.4.2-2.el6.x86_64.rpm
drbd-bash-completion-8.4.2-2.el6.x86_64.rpm
drbd-heartbeat-8.4.2-2.el6.x86_64.rpm
drbd-km-2.6.32_431.el6.x86_64-8.4.2-2.el6.x86_64.rpm
drbd-pacemaker-8.4.2-2.el6.x86_64.rpm
drbd-udev-8.4.2-2.el6.x86_64.rpm
drbd-utils-8.4.2-2.el6.x86_64.rpm
drbd-xen-8.4.2-2.el6.x86_64.rpm
[root@server3 drbd]# rpm -ivh *
Server4也須要安裝這些rpm包
[root@server3 mnt]# cd /etc/drbd.d/
[root@server3 drbd.d]# ls
global_common.conf
[root@server3 drbd.d]# vim homework.res
[root@server3 drbd.d]# cat homework.res
resource homework {
meta-disk internal;
device /dev/drbd2;#自定義的共享磁盤名稱
syncer {verify-alg sha1;
}
on server3.example.com {#節點的hostname
disk /dev/vdb;#自身主將用來設置成共享的磁盤路徑
address 172.25.50.30:7789;#節點ip
}
on server4.example.com {
disk /dev/vda;
address 172.25.50.40:7789;
}
}
這樣就無需擔憂發佈共享磁盤名稱不同如何解決的問題了
[root@server3 drbd.d]# scp homework.res 172.25.50.40:/etc/drbd.d/
[root@server3 drbd.d]# drbdadm create-md homework
##server3和server4都作
--== Thank you for participating in the global usage survey ==--
The server's response is:
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.
[root@server3 drbd.d]# /etc/init.d/drbd start#server4同時啓動
Starting DRBD resources: [
create res: homework
prepare disk: homework
adjust disk: homework
adjust net: homework
]
[root@server3 drbd.d]# cat /proc/drbd
version: 8.4.2 (api:1/proto:86-101)
GIT-hash: 7ad5f850d711223713d6dcadc3dd48860321070c build by root@server1.example.com, 2017-02-21 09:59:13
1: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:4194140
[root@server3 drbd.d]# drbdadm primary homework --force
[root@server3 drbd.d]# mkfs.ext4 /dev/drbd2
[root@server3 mnt]# mount /dev/drbd2 /mnt/mount/
[root@server3 mnt]# cd mount/
[root@server3 mount]# ls
lost+found
[root@server3 mount]# touch 111
[root@server3 mount]# ls
111 lost+found
[root@server3 mount]# cd ..
[root@server3 mnt]# umount /mnt/mount/
[root@server3 mnt]# drbdadm secondary homework
[root@server4 drbd.d]# drbdadm primary homework
[root@server4 drbd.d]# vim homework.res
[root@server4 drbd.d]# mount /dev/drbd2 /mnt/mount/
[root@server4 drbd.d]# cd /mnt/mount/
[root@server4 mount]# ls
111 lost+found
[root@server4 mnt]# umount /mnt/mount/
[root@server4 mnt]# drbdadm secondary homework
在掛載的目錄下看到在server3上建立的文件,說明分佈式共享存儲配置成功
Heartbeat+mysql
關閉兩臺虛擬機的 heartbeat 服務
[root@server3 mnt]# /etc/init.d/mysqld stop
[root@server3 mnt]# drbdadm primary homework
[root@server3 mnt]# mount /dev/drbd2 /mnt/mount/
[root@server3 mount]# cd /var/lib/mysql/
[root@server3 mysql]# cp -r * /mnt/mount/
[root@server3 ~]# umount /mnt/mount/
[root@server3 ~]# mount /dev/drbd2 /var/lib/mysql/
[root@server3 ~]# chown mysql.mysql /var/lib/mysql/ -R
[root@server3 ~]# /etc/init.d/mysqld start
正在啓動 mysqld: [肯定]
[root@server3 ~]# cd
[root@server3 ~]# /etc/init.d/mysqld stop
中止 mysqld: [肯定]
[root@server3 ~]# umount /var/lib/mysql/
[root@server3 ~]# drbdadm secondary homework
把server3,server4的heartbeat服務打開服務會自動開啓,當server3的heatbeat服務關閉是。Vip:172.25.50.200會調轉到server4上。
最後:
整合
如今咱們來搭建一個論壇
[root@server1 mnt]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/nginx/html/
##將這個論壇壓縮包解壓在nginx的默認發佈目錄中
[root@server1 mnt]# cd /usr/local/nginx/html/
[root@server1 html]# ls
50x.html index.html nginx.php readme upload utility
[root@server1 html]# cd upload/
[root@server1 upload]# ls
admin.php connect.php forum.php member.php search.php uc_server
api cp.php group.php misc.php source userapp.php
api.php crossdomain.xml home.php plugin.php static
archiver data index.php portal.php template
config favicon.ico install robots.txt uc_client
[root@server1 upload]# chmod 777 config/
[root@server1 upload]# chmod 777 data/ -R
[root@server1 upload]# chmod 777 uc_* -R
在serer3上設置root用戶能夠遠程登錄的權限
grant all privileges on *.* to "root"@"%" identified by "redhat";
Query OK, 0 rows affected (0.00 sec)
測試方法,在serer1上遠程登錄172.25.50.200這個ip的數據庫
而且在數據庫中有解的權限便可。
在瀏覽器上:172.25.50.10/upload/
數據庫寫入測試:在server3上
高可用測試:
關閉server3上的heartbeat服務。
如圖,能夠看見heartbeat服務停了以後,sererv4自動接管數據庫,這時查看數據庫內容與在server3上看到的一致!
實驗成功!!!!!!!!!!!!!!!!!!!!!!!!