Quản Trị Mạng - Trong bài viết dưới đây, chúng tôi sẽ hướng dẫn các bạn cách cài đặt Nginx - thường gọi là engine x, đây là 1 hệ thống server HTTP mã nguồn mở, hoàn toàn miễn phí, hiệu suất hoạt động cao, độ ổn định cao, tổ hợp chức năng đa dạng, dễ dàng cấu hình, thiết lập và sử dụng ít tài nguyên hệ thống. Cụ thể, chúng ta sẽ cùng nhau tiến hành cài đặt Nginx trên server CentOS 6.0 với PHP5 hỗ trợ qua PHP – FPM và MySQL.
Trong bài thử nghiệm này, chúng ta sẽ dùng hostname server1.example.com với địa chỉ IP 192.168.0.100, tùy từng hệ thống khác nhau các bạn hãy thay đổi thông số kỹ thuật sao cho phù hợp. Bên cạnh đó, php-fpm không có sẵn trên repository chính thức của CentOS, nhưng lại có trên Remi RPM với cơ chế phụ thuộc vào EPEL repository, chúng ta có thể kích hoạt cả 2 repository như sau:
rpm --import https://fedoraproject.org/static/0608B895.txt
rpm -ivh http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum install yum-priorities
Sau đó, chỉnh sửa /etc/yum.repos.d/epel.repo...
vi /etc/yum.repos.d/epel.repo
Và thêm dòng priority=10 vào phần [epel]:
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
priority=10
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[…]
Làm tương tự như vậy với phần [remi] trong /etc/yum.repos.d/remi.repo, và thay đổi enabled thành 1:
vi /etc/yum.repos.d/remi.repo
[remi]
name=Les RPM de remi pour Enterprise Linux $releasever - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror
enabled=1
priority=10
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
failovermethod=priority
[remi-test]
name=Les RPM de remi en test pour Enterprise Linux $releasever - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/test/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/test/mirror
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Cài đặt MySQL 5:
Để tiến hành, chúng ta bắt đầu với câu lệnh:
yum install mysql mysql-server
Sau đó, tạo đường dẫn khởi động dành cho MySQL (và MySQL sẽ tự khởi động mỗi khi hệ thống hoạt động), đồng thời kích hoạt MySQL server:
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start
Kiểm tra hệ thống mạng đã ở trạng thái kích hoạt hay chưa, sử dụng lệnh:
netstat -tap | grep mysql
Và hệ thống của bạn sẽ hiển thị kết quả tương tự như dưới đây:
[root@server1 ~]# netstat -tap | grep mysql
tcp 0 0 *:mysql *:* LISTEN 2302/mysqld
[root@server1 ~]#
Nếu không, hãy chỉnh sửa file /etc/my.cnf và thêm chú thích tai phần skip-networking:
vi /etc/my.cnf
[...]
#skip-networking
[...]
Sau đó khởi động lại MySQL server:
/etc/init.d/mysqld restart
Chạy lệnh:
mysql_secure_installation
để khởi tạo mật khẩu cho tài khoản root (nếu không thì bất ai cũng có thể truy cập và sử dụng cơ sở dữ liệu MySQL):
[root@server1 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you 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): <-- nhấn ENTER
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <-- nhấn ENTER
New password: <-- mật khẩu tài khoản root
Re-enter new password: <-- mật khẩu tài khoản root
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] <-- nhấn ENTER
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <-- nhấn ENTER
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] <-- nhấn ENTER
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <-- nhấn ENTER
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@server1 ~]#