搜档网

搜档网

当前位置:搜档网 > LAMP搭建论坛

LAMP搭建论坛

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

一,LAMP(php perl python)--->rpm / 源码包--->搭建论坛linux >>apache >> mysql php

二,sql语句

三,备份数据库,恢复数据库

四,基予二进制的日志备份

五,cluster(大型应用。集群),企业中用的比较少

优化

PHP语句

*******************************************************

存在在数据库中可以避免冗余,安全==> sqlserver oracle DB2(IBM)都是商业数据库

Mysql是小型数据库,是开源的,postgresql sqlite,都是开源的

Mysql语言:C或者C++,支持API,PHP,java

存储引擎:默认为MYISAM,查询表的时候高效

三种架构:单点,AB复制(至少两台),cluster集群

********************************************************

查看需要装哪些包:

[root@stu12 ~]# rpm -q httpd

httpd-2.2.3-43.el5

[root@stu12 ~]# rpm -q php

php-5.1.6-27.el5

[root@html]#rpm -q php-mysql

php-mysql-5.1.6-27.el5

[root@stu12 ~]# rpm -q mysql

mysql-5.0.77-4.el5_4.2

[root@stu12 ~]# rpm -q mysql-server

mysql-server-5.0.77-4.el5_4.2

yum install php-mysql

[root@stationX]# rpm -qa php-mysql

php-mysql-5.1.6-27.el5

[root@stu12 html]# ls /etc/httpd/modules/libphp5.so ==> php捆绑到apache的模块

/etc/httpd/modules/libphp5.so

测试php能不能用apache打开:在/var/www/html中编写一个1.php然后在网页中打开http://192.168.1.12/1.php

[root@stationX conf]# vim /etc/httpd/conf 当初装虚拟机的时候添加的一行给注释掉

#Include conf/vhost_*.conf

[root@html]#cat 2.php

echo "ok! php";

?>

[root@html]#pwd

/var/www/html

[root@html]#which php

/usr/bin/php

[root@html]#php 2.php

ok! php[root@html]#

[root@html]#vim 2.php

echo "ok! php";

echo "\n";

?>

[root@html]#php 2.php

ok! php

[root@html]#vim 3.php

phpinfo();

?>

http://192.168.1.44/3.php 网页中打开

[root@html]#cat 4.php

system("cat /etc/passwd")

?>

[root@/]#service mysqld restart

[root@/]#\mysql -h localhost -u root -p

[root@html]#cat 5.php

mysql_connect('localhost','root','123') or die("NOT conn");

echo "ok!";

?>

http://192.168.1.44/5.php 网页中打开

**************************************************

搭建论坛系统

[root@mysql]#cp -r phpBB/ /var/www/html/

http://192.168.1.44/phpBB/install/install.php 网页中打开,如显示乱源

[root@mysql]#vim /etc/httpd/conf/httpd.conf 第748行注释掉

748 # AddDefaultCharset UTF-8

[root@/]#mysql -p123

show databases;

mysql> create database phpbb; 创建个数据库

mysql>show databases; 查看库

mysql> show tables;==> 查看当前数据库中的表

exit

[root@/]#cd /var/www/html/phpBB/

[root@phpBB]#ll config.php

-rwxr-xr-x 1 root root 0 01-18 10:42 config.php

[root@phpBB]#chmod 666 config.php

[root@phpBB]#ll config.php

-rw-rw-rw- 1 root root 0 01-18 10:42 config.php

装完论坛后执行下面命令

[root@phpBB]#rm -rf install/ contrib/

[root@phpBB]#ll config.php

-rw-rw-rw- 1 root root 251 01-18 10:52 config.php

[root@phpBB]#chmod 644 config.php

[root@phpBB]# service httpd restart

http://192.168.1.44/phpBB/profile.php

**************************apach源码包的安装*****************************

apach源码包的安装

[root@mysql]#tar jxf httpd-2.2.11.tar.bz2 -C /usr/local/src/ 指定解压目录

[root@mysql]#cd !$

cd /usr/local/src/

[root@src]#cd httpd-2.2.11/

[root@stu44 httpd-2.2.11]# ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl

如不能成功执行,用下面命令

*--enable-mods-shared=most:把apache的大部分功能编译成模块

*--enable-so:让apache核心装载DSO

*--enable-rewrite:可以地址重写

*--enable-ssl:将来访问的用会信息加密

[root@httpd-2.2.11]#./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-rewrite 如上面那条命令执行这条命令

[root@httpd-2.2.11]# yum install openssl-* 如不能执行make 看看是不是这个软件包没装[root@httpd-2.2.11]# make

[root@httpd-2.2.11]# make install

[root@httpd-2.2.11]# cd /usr/local/apache2

[root@apache2]#cd bin/

[root@bin]#ls

ab checkgid envvars-std htdigest httxt2dbm

apachectl dbmmanage htcacheclean htpasswd logresolve

apxs envvars htdbm httpd rotatelogs

[root@bin]#service httpd stop 如果已安

停止httpd:[确定]

[root@apache2]#cd bin/

[root@bin]#pwd

/usr/local/apache2/bin

[root@bin]#./apachectl start ==> 更新后默认访问/usr/local/apache2/htdocs的网页.没有重启

vim apachectl

[root@stationX bin]#./http -l

[root@stationX bin]# lsof -i:80

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

httpd 32460 root 3u IPv6 81951 TCP *:http (LISTEN)

httpd 32513 daemon 3u IPv6 81951 TCP *:http (LISTEN)

httpd 32514 daemon 3u IPv6 81951 TCP *:http (LISTEN)

httpd 32515 daemon 3u IPv6 81951 TCP *:http (LISTEN)

httpd 32516 daemon 3u IPv6 81951 TCP *:http (LISTEN)

httpd 32517 daemon 3u IPv6 81951 TCP *:http (LISTEN)

[root@stationX bin]# cp apachectl /etc/init.d/

[root@stationX bin]# cd /etc/init.d/

[root@stationX init.d]# mv apachectl apache

[root@stationX init.d]# chkconfig --list apache

apache 服务不支持chkconfig

[root@stationX init.d]# chkconfig --add apache

apache 服务不支持chkconfig

[root@etc]#vim /etc/init.d/apache

1 #!/bin/sh

2 #chkconfig: - 85 15

3 #description: Apache is a World Wide Web server. It is used to serve \

4 # HTML files and CGI.

ps -e |grep httpd

who am i

[root@stationX init.d]# cd ..

[root@stationX etc]# ls

[root@stationX etc]# cd rc5.d/

[root@stationX rc5.d]# chkconfig apache on

[root@stationX rc5.d]# chkconfig --list apache

apache 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭

[root@stationX rc5.d]# chkconfig --level 5 apache

[root@etc]#./init.d/apache stop

[root@etc]#service apache start

[root@etc]#ps -e |grep httpd

[root@etc]#firefox 192.168.1.44 &

It works!

********************安装mysql************************

安装mysql

[root@mysql]#useradd mqsql

[root@mysql]#tar zxf mysql-5.1.34.tar.gz -C /usr/local/src/

[root@stu12 mysql-5.1.34]# pwd

/usr/local/src/mysql-5.1.34

[root@stu12 mysql-5.1.34]# ./configure --with-mysqld-user=mysql --prefix=/usr/local/mysql --with-extra-charsets=all --exec-prefix=/usr/local/mysql --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-innodb --with-plugins=partition

*--with-mysqld-user=mysql:以mysql用户的身份运行mysqld进程

*--with-extra-charsets=all:支持所有字符集

*--exec-prefix=/usr/local/mysql:mysql的执行文件安装位置,会在mysql目录下产生bin 目录

*--with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static:静态编译mysql,理论上提高性能13%

*--with-innodb:支持innodb存储引擎

*--with-plugins=partition:支持分区装完后可以把数据库放到别的分区里,默认有专门放数据库的地方

*--prefix=/usr/local/mysql:安装位置

*如果装不上把最后两段给去掉看行不--with-innodb --with-plugins=partition 当前版本不支持这两个功能所以暂时不用安装

[root@localhost mysql-5.1.34]# yum search termcap 如果还没安装成功看有没装这个开发工具包

Loaded plugins: rhnplugin, security

This system is not registered with RHN.

RHN support will be disabled.

================================================ Matched: termcap ================================================

termcap.noarch : 被某些程序使用的终端机功能数据库。

libtermcap.i386 : 一个用于访问termcap 数据库的基本的系统库。

libtermcap-devel.i386 : 开发访问termcap 数据库的程序的开发工具。

[root@localhost mysql-5.1.34]# yum install termcap libtermcap libtermcap-devel

[root@stu12 mysql-5.1.34]# make

[root@stu12 mysql-5.1.34]# make install

[root@localhost mysql-5.1.34]# vim INSTALL-SOURCE 3819行开始,这里面放着一些安装步骤

shell> groupadd mysql

shell> useradd -g mysql mysql

shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -

shell> cd mysql-VERSION

shell> ./configure --prefix=/usr/local/mysql

shell> make

shell> make install

shell> cp support-files/http://www.sodocs.net/doc/b134ba0a7cd184254b35352d.htmlf /etc/http://www.sodocs.net/doc/b134ba0a7cd184254b35352d.htmlf

shell> cd /usr/local/mysql

shell> chown -R mysql .

shell> chgrp -R mysql .

shell> bin/mysql_install_db --user=mysql

shell> chown -R root .

shell> chown -R mysql var

shell> bin/mysqld_safe --user=mysql &

[root@stu12]# cd /usr/local/src/mysql-5.1.34/support-files

[root@localhost support-files]#cp http://www.sodocs.net/doc/b134ba0a7cd184254b35352d.htmlf /etc/http://www.sodocs.net/doc/b134ba0a7cd184254b35352d.htmlf

[root@stu12 bin]#cd /usr/local/mysql/bin

[root@stu12 bin]# ldd mysql

not a dynamic executable

[root@stu12 bin]# ./mysql_install_db --user=mysql

此命令是初始化脚本,只在第一次的时候初始化,为Mysql运行做准备:来创建MySQL 许可表。

此命令执行成功时会在/usr/local/mysql目录下生成var目录,,并且里面有两个目录,这就说明初始化成功了,如果执行失败则有可能mysql用户没有创建,需要手工创建:useradd mysql,再把系统的mysql卸载:rpm -e mysql。

[root@bin]#ls ../var/

mysql test

[root@stu12 mysql]# /etc/init.d/mysqld stop

[root@stu12 bin]# pwd

/usr/local/mysql/bin

[root@stu12 bin]# ./mysql_install_db ==> 这个时候初始化有问题

[root@stu12 bin]# rpm -e mysql --nodeps ==> 将系统自带的mysql卸载

如起动不起来看/tmp权限是不是1777

[root@mysql]# chown -R mysql:mysql .

[root@mysql]#cd bin/

[root@bin]# ./mysqld_safe --user=mysql & 启动mysql服务器.这时可用ps -e 命令看到mysql 的进程

[1] 25926

[root@bin]#110118 15:27:14 mysqld_safe Logging to '/usr/local/mysql/var/http://www.sodocs.net/doc/b134ba0a7cd184254b35352d.html.err'.

110118 15:27:14 mysqld_safe A mysqld process already exists

[1]+ Exit 1 ./mysqld_safe

[root@bin]#./mysql 缺省地,mysql 已经存在一个root 用户,密码为空Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.34 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit

[root@~]#cd /usr/local/mysql/share/mysql/

[root@mysql]#ls mysql.server

mysql.server

[root@mysql]#cp mysql.server /etc/init.d/mysql

[root@mysql]# chmod u+x /etc/init.d/mysqld

[root@stu12 ~]# vim .bashrc

MYSQL_HOME=/usr/local/mysql/

PATH=$MYSQL_HOME/bin:$PATH

[root@stu12 ~]# source .bashrc

[root@localhost bin]# echo $PATH

/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin: /usr/X11R6/bin:/root/bin

[root@localhost bin]# export PATH=/usr/local/mysql/bin:$PATH

[root@localhost bin]# echo $PATH

/usr/local/mysql/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bi n:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

mysql> show vairables like '%dir%';

[root@stu12 ~]# mysqladmin -u root password 123456 -p123 ==> 更改密码

[root@stu12 ~]#cd /usr/local/mysql/share/mysql

[root@stu12 mysql]# ls user* ==> 存放密码的MYISAM存储引擎的一种方式user.frm user.MYD user.MYI

[root@stu12 mysql]# chkconfig --add mysql

[root@stu12 mysql]# chkconfig --list mysql

mysql.server 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭

[root@mysql]#service mysql restart

[root@localhost mysql]# pwd

/usr/local/mysql

[root@localhost mysql]# ./bin/mysqld_safe --user=mysql & 启动mysql

[root@localhost mysql]# ps -e | grep mysql

4390 pts/4 00:00:00 mysqld_safe

4441 pts/4 00:00:00 mysqld

****[root@localhost support-files]# pwd

/usr/local/src/mysql-5.1.34/support-files

[root@localhost support-files]# cp mysql.server /etc/init.d/

[root@localhost support-files]# chmod u+x /etc/init.d/mysql.server ******

*********************安装php源码包******************************

[root@mysql]# tar jxf php-5.2.9.tar.bz2 -C /usr/local/src/

[root@mysql]#cd /usr/local/src/

[root@src]#ls

httpd-2.2.11 mysql-5.1.34 php-5.2.9

[root@src]#cd php-5.2.9/

[root@stu12 php-5.2.9]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php

*--with-apxs2=/usr/local/apache2/bin/apxs:用apache的apxs工具把php编译成apache 的一个模块

*--with-mysql=/usr/local/mysql:与mysql结合

yum install libxml2-devel 装不上看有没这个软件开发包

[root@stu12 httpd-2.2.11]# make

[root@stu12 httpd-2.2.11]# make install

[root@stu12 php-5.2.9]# cp php.ini-dist /usr/local/php/php.ini ==> php的配置文件拷贝一份

[root@stu12 php-5.2.9]# cd /usr/local/apache2/modules/

[root@stu12 modules]# ls libphp5.so 确认有这个模块

libphp5.so

[root@htdocs]#cd /usr/local/apache2/htdocs/

[root@htdocs]#ls

index.html

[root@htdocs]#vim index.php

[root@htdocs]#cat index.php

echo "ssgetyeygedy";

?>

[root@htdocs]#vim ../conf/httpd.conf

211

212 DirectoryIndex index.html index.php

213

355 AddType application/x-httpd-php .php

http://192.168.1.44/index.php

[root@htdocs]#vim 2.php

[root@htdocs]#cat 2.php

mysql_connect('localhost','root','') or die("not");

echo "ok!";

?>

[root@htdocs]#pwd

/usr/local/apache2/htdocs

[root@htdocs]#service apache restart

http://192.168.1.44/2.php

************************************************

测试:

[root@stu12 html]# cp 1.php 2.php /usr/local/apache2/htdocs/

[root@stu12 bin]# ./apachectl stop

[root@stu12 bin]# pwd

/usr/local/apache2/bin

[root@stu12 bin]# ./apachectl start

[root@stu12 conf]# vim httpd.conf

[root@stu12 conf]# pwd

/usr/local/apache2/conf

在354行添加:AddType application/x-httpd-php .php

在212行添加:DirectoryIndex index.html index.php

[root@stu12 bin]# vim web

[root@stu12 bin]# chmod +x web

[root@stu12 bin]# mv web /bin/

[root@stu12 bin]# cat /bin/web

/usr/local/apache2/bin/apachectl restart

************************再装论坛系统discuz:*******************************

[root@mysql]# mkdir a

[root@mysql]# unzip Discuz\!_6.0.0_SC_GBK.pcpop.zip -d a

[root@mysql]#cd a

[root@a]# cp -r upload/ /usr/local/apache2/htdocs/bbs

[root@a]# cd /usr/local/apache2/htdocs

http://192.168.1.44/bbs/install.php 网页中打开

[root@htdocs]# chown daemon.daemon bbs/ -R

[root@htdocs]#source /root/.bash_profile

[root@htdocs]#mysql

mysql> create database discuz;

mysql> grant all on discuz.* to discuz@localhost identified by '123'; 给刚才创建的库添加用户,给库以及他下边的表授权

[root@htdocs]# vim /usr/local/apache2/conf/httpd.conf 里面的111行显示访问页面的时候的用户和组信息

http://192.168.1.44/bbs/install.php 网页中打开

**************************安装UCenter******************************

安装UCenter

[root@mysql]#cd sns/

[root@sns]#mkdir b

[root@sns]# unzip UCenter_1.5.0_SC_UTF8.zip -d b

[root@sns]#ls

b UCenter_1.5.0_SC_UTF8.zip UCenter_Home_2.0_SC_UTF8.zip

[root@sns]#cd b

[root@b]#cp -r upload/ /usr/local/apache2/htdocs/ucenter

http://192.168.1.44/ucenter/install/index.php 网页中打开

[root@htdocs]#pwd

/usr/local/apache2/htdocs

root@htdocs]#ls

.php 2.php bbs index.html ucenter

root@htdocs]#chown daemon.daemon ucenter/ -R

o+w -R data

root@htdocs]#mysql

mysql> create database ucenter;

mysql> grant all on ucenter.* to ucenter@localhost identified by '123'; ==> 给刚才创建的库添加用户,给库以及

他下边的表授权

**************************安装UCHOME******************************

[root@sns]#mkdir c

[root@sns]#unzip UCenter_Home_2.0_SC_UTF8.zip -d c

[root@sns]#cd c/

[root@c]#cp -r upload/ /usr/local/apache2/htdocs/uchome

[root@c]#cd /usr/local/apache2/htdocs/

[root@htdocs]#cd uchome/

[root@uchome]#cp config.new.php config.php

[root@uchome]#chown daemon.daemon config.php o+w

[root@htdocs]#chown daemon.daemon uchome -R

[root@htdocs]#mysql

mysql> create database uchome;

mysql> grant all on uchome.* to uchome@localhost identified by '123';

http://192.168.1.44/uchome/

http://192.168.1.44/uchome/admincp.php

装pMyAdmin

[root@mysql]#tar jxf phpMyAdmin-3.1.4-all-languages.tar.bz2

[root@mysql]#mv phpMyAdmin-3.1.4-all-languages/ /usr/local/apache2/htdocs/pma/ root@mysql]#cd /usr/local/apache2/htdocs/

[root@htdocs]#mysqladmin -u root password 123

http://192.168.1.44/pma

[root@apache2]#cd ..

[root@local]#tar cf apache2.tar apache2/

[root@local]#ls

apache2 etc include mailgraph_ext nagios share tomcat

apache2.tar Evermore lib man php squid-graph

bin games libexec mysql sbin src

[root@local]#tar cf php.tar php/

[root@local]#tar cf mysql.tar mysql/

[root@local]#mkdir beifen20100118

[root@local]#vm apache2.tar mysql.tar php.tar beifen20100118/

bash: vm: command not found

[root@local]#mv apache2.tar mysql.tar php.tar beifen20100118/

[root@local]#cd beifen20100118/

[root@beifen20100118]#ls

apache2.tar mysql.tar php.tar

**************************************************

[root@mysql]#tar jxf httpd-2.2.11.tar.bz2 -C /usr/local/src/

ysql中默认三个文件组成一个表

[root@stu12 extmail]# ls

alias.frm domain.frm domain.MYD mailbox.MYI

alias.MYD domain_manager.frm domain.MYI manager.frm

alias.MYI domain_manager.MYD mailbox.frm manager.MYD

db.opt domain_manager.MYI mailbox.MYD manager.MYI

[root@stu12 extmail]# pwd

/var/lib/mysql/extmail

mailbox.MYD是存放数据的

[root@stu12 mysql]# ll mysql.sock 启动mysql一定会有的套节字文件

srwxrwxrwx 1 mysql mysql 0 10-21 10:10 mysql.sock

mysql的日志文件在/var/log/mysqld.log

mysql的程序文件在/usr/bin/mysql,默认端口号3306

**************************************************

测试php能不能连接上数据库

[root@stu12 mysql]# mysql -u root -p123或者mysql -h127.0.0.1 -u root -p123

在/var/www/html/中编写一个2.php脚本

$dbhost=localhost;

$dbuser=root;

$dbpass=123;

mysql_connect($dbhost,$dbuser,$dbpass) or die("Not

conn");echo "OK!";

?>

在网页中打开http://192.168.1.12/2.php一片空白,这个时候要装一个包yum install php-mysql

mysql中\c是不执行这个语句

mysql> create database abc;

mysql> drop database abc;

mysql> use extmail; ==> 选择数据库

mysql> select database(); ==> 查看当前选择的数据库

mysql> show tables;==> 查看当前数据库中的表

命令创建删除数据库:

[root@stu12 mysql]# mysqladmin create abc -u root -p123

[root@stu12 mysql]# mysqladmin drop abc -u root -p123

[root@stu12 mysql]# mysql -uroot -p123 -e "show databases;" 直接在外面查看数据库

[root@stu12 mysql]# mysql -uroot -p123 extmail -e "show tables;" 查看某个数据库的表