CENTOS下安装LAMP总结


CENTOS下安装LAMP总结

(一,mysql)


最近新的子网站上线,需要搭建服务器。在部署时,开始想复制老服务器的模式,连包也用一样的,但杯具的是包不全,导致后来东拼西凑错误百出,不得已重装了系统再进行配置。

在源码安装的时候由于记录不详细,导致配置错误,最后的解决方式是yum安装,总结源码安装和yum安装,前者灵活性高,但需要在每一步都详细记录,配置好关联路径;后者则是固定的编译参数+固定位置,会省事不少。



1,安装操作系统centos5.6
比较简单,超详细的图文教程见http://hi.baidu.com/eao110/blog/item/6fb6fed31ffcc1d3a8ec9a28.html

建议使用文本模式,毕竟是做服务器应用的,图形界面对维护来说帮助不大(尤其是在ssh下)。
另外,分区需要注意自己的应用(数据库、WEB)分布在哪个目录,则相应的调整好大小,免得到时候磁盘空间不够


2,安装完毕,下载所需要的包,搜索tar包的资源,找到地址后使用wget直接下载到本地目录,建议单独新建一个目录用来保存安装文件
cd /home
mkdir source
cd source
进入该目录后,输入wget http://xxxxxxxx/xxxx.tar.gz 即可从该地址获取包


3,下载完所有包,开始解压,tar命令很简单,概括来讲:
.tar.gz 后缀的,用tar zxvf 文件名
.tar.bz2后缀的,用tar jcvf 文件名


4,MYSQL安装,以5.0.77为例


安装需要的库  
yum -y install ncurses ncurses-devel
  
#创建MySQL用户及用户组  
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql

#解压源码包
cd /home/source
tar zxvf mysql-5.0.77.tar.gz

#赋予解压文件夹mysql用户的可读权限
chown -R mysql:mysql mysql-5.0.77

#进入目录开始编译
cd mysql-5.0.77

#安装前检查是否有运行的mysql进程,杀之
ps -aef|grep mysql
kill -9 XXX


#开始安装,如果提示缺库则需先安装该库,一般会缺失多个
./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static  --with-client-ldflags=-all-static  --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --with-mysqld-user=mysql --with-charset=utf8  --with-collation=utf8_general_ci --with-extra-charsets=all --without-debug --enable-assembler --with-innodb --localstatedir=/var/lib/mysql

#make && make install
make ZEND_EXTRA_LIBS='-liconv' && make install




./configure中的编译参数说明如下,可根据情况自己定制:

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]


By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.


For better control, use the options below.


Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]


Program names:
  --program-prefix=PREFIX            prepend PREFIX to installed program names
  --program-suffix=SUFFIX            append SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names


System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]


Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --disable-dependency-tracking  speeds up one-time build
  --enable-dependency-tracking   do not reject slow dependency extractors
  --enable-shared[=PKGS]  build shared libraries [default=yes]
  --enable-static[=PKGS]  build static libraries [default=yes]
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --disable-community-features
                          Disable additional features provided by the user
                          community.
  --disable-thread-safe-client
                          Compile the client without threads.
  --enable-assembler      Use assembler versions of some string
                          functions if available.
  --enable-profiling      Build a version with query profiling code (req.
                          community-features)
  --enable-local-infile   Enable LOAD DATA LOCAL INFILE (default: disabled)
  --disable-grant-options Disables the use of --init-file, --skip-grant-tables and --bootstrap options
  --disable-largefile     Omit support for large files


Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-charset=CHARSET
                          Default character set, use one of:
                          binary
                          armscii8 ascii big5 cp1250 cp1251 cp1256 cp1257
                          cp850 cp852 cp866 cp932 dec8 eucjpms euckr gb2312 gbk geostd8
                          greek hebrew hp8 keybcs2 koi8r koi8u
                          latin1 latin2 latin5 latin7 macce macroman
                          sjis swe7 tis620 ucs2 ujis utf8
  --with-collation=COLLATION
                          Default collation
  --with-extra-charsets=CHARSET,CHARSET,...
                          Use charsets in addition to default (none, complex,
                          all, or a list selected from the above sets)
  --without-uca           Skip building of the national Unicode collations.


  --with-system-type      Set the system type, like "sun-solaris10"
  --with-machine-type     Set the machine type, like "powerpc"
  --with-darwin-mwcc      Use Metrowerks CodeWarrior wrappers on OS X/Darwin
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-pic              try to use only PIC/non-PIC objects [default=use
                          both]
  --with-tags[=TAGS]      include additional configurations [automatic]
  --with-other-libc=DIR   Link against libc and other standard libraries
                          installed in the specified non-standard location
                          overriding default. Originally added to be able to
                          link against glibc 2.2 without making the user
                          upgrade the standard libc installation.
  --with-server-suffix    Append value to the version string.
  --with-pthread          Force use of pthread library.
  --with-named-thread-libs=ARG
                          Use specified thread libraries instead of
                          those automatically found by configure.
  --with-named-curses-libs=ARG
                          Use specified curses libraries instead of
                          those automatically found by configure.
  --with-unix-socket-path=SOCKET
                          Where to put the unix-domain socket.  SOCKET must be
                          an absolute file name.
  --with-tcp-port=port-number
                          Which port to use for MySQL services (default 3306)
  --with-mysqld-user=username
                          What user the mysqld daemon shall be run as.
  --with-zlib-dir=no|bundled|DIR
                          Provide MySQL with a custom location of compression
                          library. Given DIR, zlib binary is assumed to be in
                          $DIR/lib and header files in $DIR/include.
  --with-libwrap=DIR      Compile in libwrap (tcp_wrappers) support
  --with-pstack           Use the pstack backtrace library
  --with-debug            Add debug code
  --with-debug=full       Add debug code (adds memory checker, very slow)
  --with-error-inject     Enable error injection in MySQL Server
  --with-fast-mutexes     Compile with fast mutexes (default is disabled)
  --with-atomic-ops=rwlocks|smp|up
                          Implement atomic operations using pthread rwlocks or
                          atomic CPU instructions for multi-processor
                          (default) or uniprocessor configuration
  --with-mysqld-ldflags   Extra linking arguments for mysqld
  --with-client-ldflags   Extra linking arguments for clients
  --with-mysqld-libs   Extra libraries to link with for mysqld
  --with-lib-ccflags      Extra CC options for libraries
  --with-low-memory       Try to use less memory to compile to avoid
                          memory limitations.
  --with-comment          Comment about compilation environment.
  --with-big-tables       Support tables with more than 4 G rows even on 32
                          bit platforms
  --with-max-indexes=N    Sets the maximum number of indexes per table,
                          default 64
  --with-ssl=DIR    Include SSL support
  --with-plugins=PLUGIN[[[,PLUGIN..]]]
                          Plugins to include in mysqld. (default is: none)
                          Must be a configuration name or a comma separated
                          list of plugins.
                          Available configurations are: none max max-no-ndb
                          all.
                          Available plugins are: partition daemon_example
                          ftexample archive blackhole csv example federated
                          heap innobase myisam myisammrg ndbcluster.
  --without-plugin-PLUGIN Disable the named plugin from being built.
                          Otherwise, for plugins which are not selected for
                          inclusion in mysqld will be built dynamically (if
                          supported)
  --with-plugin-PLUGIN    Forces the named plugin to be linked into mysqld
                          statically.
  --with-ndb-sci=DIR      Provide MySQL with a custom location of sci library.
                          Given DIR, sci library is assumed to be in $DIR/lib
                          and header files in $DIR/include.


  --with-ndb-test       Include the NDB Cluster ndbapi test programs


  --with-ndb-docs       Include the NDB Cluster ndbapi and mgmapi documentation


  --with-ndb-port       Port for NDB Cluster management server


  --with-ndb-port-base  Base port for NDB Cluster transporters


  --without-ndb-debug   Disable special ndb debug features
  --with-ndb-ccflags=CFLAGS
                          Extra CFLAGS for ndb compile


  --without-ndb-binlog       Disable ndb binlog
  --without-server        Only build the client.
  --with-embedded-server  Build the embedded server (libmysqld).
  --without-query-cache   Do not build query cache.
  --without-geometry      Do not build geometry-related parts.
  --with-embedded-privilege-control
                          Build parts to check user's privileges.
  Only affects embedded library.
  --with-mysqlmanager     Build the mysqlmanager binary: yes/no (default:
                          build if server is built.)
  --without-docs          Skip building of the documentation.
  --without-man          Skip building of the man pages.
  --without-readline      Use system readline instead of bundled copy.
  --without-libedit       Use system libedit instead of bundled copy.




仔细核对上述命令及参数,一些输入的错误会被configure脚本忽略,一定要仔细检查。用 && 连接符可以将几个命令进行连接,保证上一个命令完成后才执行下一个命令。这是检验命令正确运行的一个好方法。


如果你看到安装成功的提示,则说明mysql已正确编译 并安装。


5,在mysql安装目录下,ls –l | grep my-

出来的都是mysql的配置文件,按照需要拷贝其中一个到/etc下,重命名为my.cnf,mysql默认的配置文件即是/etc/my/cnf


6,修改数据目录的可写权限。因为当前用户运行mysql的后台程序可能没有这个目录的可写权限。

chmod 777 ./var –r


7,配置系统环境变量,使得可以直接执行mysql的程序

 (1) /etc/profile的配置:
PATH=/usr/local/mysql/bin:$PATH
PATH=/usr/local/mysql/libexec:$PATH
export PATH

其中,/usr/local/mydql/bin是mysql主要的可执行程序的目录,而libexec则用来存放mysql后台主程序mysqld

  (2).bashrc的配置: 
set PATH=/usr/local/mysql/bin:$PATH
set PATH=/usr/local/mysql/libexec:$PATH
export PATH

注意.bashrc里面要加set。配置完成后,重新登录生效。


8,初始化数据库

mysql_install_db


9,启动mysqld

service mysqld start


10,进入mysql

# mysql -uroot -p

注意对mysql权限的操作,如操作mysql.user表,则需要执行以下语句来生效(或者重启)

mysql> flush privileges;











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值