Linux:在CentOS/RHEL/Scientific Linux 6下安装 LAMP
July 10, 2015
LAMP 是服务器系统中开源软件的一个完美组合。它是 Linux 、Apache HTTP 服务器、MySQL 数据库、PHP(或者 Perl、Python)的第一个字母的缩写代码。对于很多系统管理员来说安装 LAMP 除了是必备的技能外,都已经具有驾轻就熟的操作他们的能力了。不过新手们通常希望有没完没了的这方面的教程来告诉自己怎么做,下面我就和大家说说我的方法步骤。
LAMP 是服务器系统中开源软件的一个完美组合。它是 Linux 、Apache HTTP 服务器、MySQL 数据库、PHP(或者 Perl、Python)的第一个字母的缩写代码。对于很多系统管理员来说安装 LAMP 除了是必备的技能外,都已经具有驾轻就熟的操作他们的能力了。不过新手们通常希望有没完没了的这方面的教程来告诉自己怎么做,下面我就和大家说说我的方法步骤。
现在,很多时候我们需要用 MariaDB 来代替 MySQL 了。在这里我会告诉大家 MariaDB 的安装过程。
我的测试主机名为:server.linux.cn,测试 IP 地址为:192.168.1.200/24
安装 ApacheApache 是一个开源的跨平台的 Web 服务器。它提供了一个全方位的 Web 服务器功能,包括CGI,SSL 和virtual domains (虚拟域)。安装命令非常简单,只需要打开一个终端,在终端中输入如下命令:
[root@server ~]# yum install httpd -y
安装完毕后,需要设置让 Apache 服务启动,并且在每次服务器重启的时候都自动启动,输入如下命令来完成:
[root@server ~]# /etc/init.d/httpd start[root@server ~]# chkconfig httpd on
如果您想通过您的防火墙活路由器来远程连接,那么需要允许 Apache 服务接管服务器的 80 端口:
[root@server ~]# vi /etc/sysconfig/iptables[…]-A INPUT -p udp -m state –state NEW –dport 80 -j ACCEPT-A INPUT -p tcp -m state –state NEW –dport 80 -j ACCEPT[…]
重新启动 iptables :
[root@server ~]# /etc/init.d/iptables restart
打开您的浏览器访问 http://localhost/ 或者 http://server-ip-address/ 测试 Apache 安装是否成功。
安装 MariaDB
MariaDB 是一个替换 MySQL 的产品。功能强大而可靠。安装前,如果您的服务器中安装有 MySQL ,那么您需要删除它。删除命令:
[root@server ~]# yum remove mysql* mysql-server mysql-devel mysql-libs
为了让 MariaDB 同时兼容 MySQL,我们需要安装 REMI 库来解决兼容性和安装 MariaDB 时软件包依赖性问题。安装命令:
[root@server ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
安装兼容 mysql55 包命令:
[root@server ~]# yum –enablerepo=remi-test –disablerepo=remi install compat-mysql55
为 MariaDB 创建一个 repository 文件,并在其中输入如下代码:
32 位系统:
[root@server ~]# vi /etc/yum.repos.d/mariadb.repo# MariaDB 5.5 CentOS repository list – created 2013-06-06 07:42 UTC# http://mariadb.org/mariadb/repositories/[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/5.5/centos6-x86gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1
64 位系统:
[root@server ~]# vi /etc/yum.repos.d/mariadb.repo# MariaDB 5.5 CentOS repository list – created 2013-06-06 07:53 UTC# http://mariadb.org/mariadb/repositories/[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/5.5/centos6-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1
保存并退出该文件,并运行 yum update 命令:
[root@server ~]# yum update
现在开始安装 MariaDB :
[root@server ~]# yum install MariaDB-devel MariaDB-client MariaDB-server -y
安装完毕后,启动 MariaDB 服务,并让它在每次重启服务器后自动启动。
[root@server ~]# /etc/init.d/mysql startStarting MySQL… SUCCESS![root@server ~]# chkconfig mysql on
为 MySQL 的 root 设置密码,默认情况下,MySWL root 密码是空的。为了防止未经授权的用户访问 MySQL 我们需要设置 root 用户密码:
[root@server ~]# /usr/bin/mysql_secure_installation/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not foundNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we’ll need the currentpassword for the root user. If you’ve just installed MariaDB, andyou haven’t set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none): OK, successfully used password, moving on…Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.You already have a root password set, so you can safely answer ‘n’.Change the root password? [Y/n] yNew password: Re-enter new password: Password updated successfully!Reloading privilege tables.. … Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] … Success!Normally, root should only be allowed to connect from ‘localhost’. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] … Success!By default, MariaDB comes with a database named ‘test’ that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] – Dropping test database…ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist … Failed! Not critical, keep moving… – Removing privileges on test database… … Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] … Success!Cleaning up…All done! If you’ve completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!
0 Comments