Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置
CentOS 5.9下编译安装LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12)
RedHat 5.4下Web服务器架构之源码构建LAMP环境及应用PHPWind
LAMP源码环境搭建WEB服务器Linux+Apache+MySQL+PHP
本次环境;都是在一台主机上实现,系统为Centos6.5_64位
一、先安装httpd-2.4.9;
编译安装apr
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
编译安装apr-util
# tar xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make instal
编译安装httpd-2.4.9
# tar xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enables-modules=most --enable-mpms-shared=most --with-mpm=event
# make && make install
--------------------------------------------------------------------------------
二、编译安装mysql;
mysql应该把它的数据放在一个特殊的目录中,而且应该是个称独立的设备,因此需要创建一个新的分区来存放数据,做成LVM卷,挂载到一个空的目录中,并且要实现开机自动挂载
1、创建一个大小为10G的分区修改分区ID为8e(lvm);
把新建分区做成逻辑卷并格式化挂载至相应目录中;如下
[root@linux ~]# vgcreate /dev/sda3
Please enter a physical volume path
Run `vgcreate --help' for more information.
[root@linux ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@linux ~]# vgcreate myvg /dev/sda3
Volume group "myvg" successfully created
[root@linux ~]# lvcreate -L 10G -n mydata myvg
Logical volume "mydata" created
格式化
[root@linux ~]# mke2fs -t ext4 /dev/myvg/mydata
创建挂载目录
[root@linux ~]# mkdir /data
写进配置文件里实现开机自动挂载
[root@linux ~]# vim /etc/fstab
/dev/myvg/mydata /data ext4 default 0 0
查看挂载目录;
[root@linux ~]# ls /data
lost+found mydata
2、新建用户以安全的方式运行mysql;
[root@linux data]# groupadd -r mysql
[root@linux data]# useradd -g mysql -l -s /sbin/nologin -M -d /mydata/data mysql
[root@linux data]# chown -R mysql:mysql mydata
3、现在可以正式安装mysql数据了;
将mysql解压至/usr/src目录中
[root@linux xf]# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/src
[root@linux xf]# cd /usr/src/
[root@linux src]# ls
debug kernels mysql-5.5.33-linux2.6-x86_64
4、创建mysql创建一个链接文件,而且链接文件最好不要改名;
[root@linux src]# mv /usr/src/mysql-5.5.33-linux2.6-x86_64 /usr/local
[root@linux src]# cd /usr/local/
[root@linux local]# ln -sv mysql-5.5.33-linux2.6-x86_64 mysql
`mysql' -> `mysql-5.5.33-linux2.6-x86_64'
5、修改mysql的宿主宿组,并对数据库存初始化;
[root@linux mysql]# chown -R mysql:mysql . 修改当前当录及子目录的宿主宿组
[root@linux mysql]# scripts/mysql_install_db --datadir=/data/mydata/ --user=mysql 初始化数据库
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:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h linux.yang.com password 'new-password'
Alternatively you can run:
./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 . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
6、为mysql提供主配置文件,拷贝到/etc/目录中,事先/etc/目录下会有一个相同名的数据文件,覆盖即可,而后编辑/etc/my,conf这个文件,添加存放数据的存放目录
[root@linux mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@linux mysql]# ls /etc/my.cnf
/etc/my.cnf
[root@linux mysql]# vim /etc/my.cnf
thread_concurrency = 4 表示值为当前主机CPU的个数乘以2
datadir = /date/mydata 数据库的存放位置
7、为mysql提供sysv脚本,还好mysql自身提供有脚本,只需将其复制下来,存放至/init.d/目录中;
[root@linux mysql]# cd /usr/local/mysql
[root@linux mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@linux mysql]# chmod +x /etc/rc.d/init.d/mysqld
添加至服务列表
[root@linux mysql]# chkconfig --add mysqld
[root@linux mysql]#
[root@linux mysql]# chkconfig mysqld on
8、现在可以启动mysqlb
[root@linux mysql]# service mysqld start
Starting MySQL...... [ OK ]
[root@linux mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> \q
Bye
启动mysql后会在/data/mydata/目录下生成数据库文件,并且会在/tmp/目录下,有一个特殊文件,套接字文件,是用于如果客户端在本机,服务端也在本机时用到的一种特别高效的通信方式;
9、 输入mysql的头文件至系统头文件路径
#ln -sv /usr/local/mysql/include /usr/include/mysql
10、输入mysql的库文件给系统库查找路径;
#echo "/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig 让系统重读库文件
[root@linux mysql]# ldconfig -p | grep mysql
libtcmalloc_minimal.so.0 (libc6,x86-64) => /usr/local/mysql/lib/libtcmalloc_minimal.so.0
libmysqlclient_r.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient_r.so.16
libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.18
libmysqlclient.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.16
libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so
11、修改PATH环境变量,让系统可以直接使用mysql的相关命令;
vim /etc/profile.d/mysql.sh 后面这个mysql.sh是自定义的,但一定得是.sh结尾
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile.d/mysql.sh 重读文件即可生效
12、安装完成mysql需要删除mysql的匿名用户,给管理员加密码;
直接执行mysql命令即可进入mysql;
mysql> use mysql; 设置默认表
Database changed
mysql> select user,host,password from user; 查看
+------+----------------+----------+
| user | host | password |
+------+----------------+----------+
| root | localhost | |
| root | linux.yang.com | |
| root | 127.0.0.1 | |
| root | ::1 | |
+------+----------------+----------+
4 rows in set (0.00 sec)
mysql> UPDATE user SET password=PASSWORD('redhat') WHERE user='root'; 更改所有用户的密码为redhat
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> select user,host,password from user;
+------+----------------+-------------------------------------------+
| user | host | password |
+------+----------------+-------------------------------------------+
| root | localhost | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| root | linux.yang.com | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| root | 127.0.0.1 | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| root | ::1 | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
+------+----------------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
至此安装mysql数据库完成