Hướng dẫn build LAMP Server: Setup CentOS 5.4

Date: 17 Tháng 5 2010 Comments:0

Quy trình cài đặt CentOS khá đơn giản, tôi không đi sâu vấn đề này, chỉ cần các bạn chú ý là: khi cài chúng ta sẽ chọn cài theo kiểu customize và không chọn bất kỳ nhóm nào ngoại trừ 2 nhóm gói là BaseEditor. Trong quá trình cài tôi sẽ chọn IP cho server là 192.168.1.253, hostname sẽ là server.hanhtv.local. Sau khi cài xong tại màn hình đầu tiên, tại màn hình cài đặt cho Firewall configuration, chúng ta sẽ chọn Disable cho Security Level và SELinux. Tiếp theo là Update cho hệ điều hành bằng lênh:

yum update

Sau đó reboot lại và chúng ta cài thêm các gói: C/C++ và thư viện OpenSSL bằng lệnh:

yum install gcc-c++ openssl openssl-devel

Sau khi kết thúc quá trình trên, hệ điều hành của chúng ta đã sẵn sàng cho việc cài đặt và Build các gói trong bộ LAMP của chúng ta.

Tags: ,

Hướng dẫn tự build một LAMP server một cách “mỳ ăn liền”.

Date: 17 Tháng 5 2010 Comments:0

LAMP – Linux, Apache, MySQL và PHP là một máy chủ cung cấp tài nguyên mà hầu hết ai làm trong lĩnh vực thiết kế website đều biết. Từ trước đến nay để có thể thể cài đặt thành công máy chủ này sẽ tốn rất nhiều công sức và thời gian, đặc biệt nếu các gói được build từ source code thì không phải ai cũng có thể làm được.

Dừng lại một chút, thông thường các bản phân phối Linux luôn được đóng gói theo rất nhiều phần mềm, chúng ta chỉ cần sử dụng một số câu lệnh là có thể cài đầy đủ các gói cần thiết như trên, nhưng tại sao chúng ta lại chọn theo cách build từ source code các gói trên. Lý do là, các phần mềm được đóng gói theo hệ điều hành thường có phiên bản thấp hơn so với các phiên bản đang có tại các trang chủ của các phần mềm này. Mà thông thường phiên bản càng thấp thì càng hỗ trợ kém và đặc biệt là chưa nhiều lỗ hổng, rất dễ bị lợi dụng và tấn công, hơn nữa cài từ source code tuy có tốn thời gian và công sức nhưng lại cho chúng ta quyền chủ động trong việc lựa chọn các module cài theo hệ thống.

Trong bải viết này tôi sẽ hướng dẫn cách build một LAMP server từ các thành phần sau:

  • Hệ điều hành: CentOS 5.4
  • Web server : Apache 2.2.15
  • PHP Engine: 5.2.13
  • Database server: MySQL 5.1.46

Ngoài ra còn rất nhiều các thư viện khác như libjpeg hay libpng, mhash…. sẽ được tự động cài trong quá trình build hệ thống. Sau khi cài xong chúng ta sẽ có một hệ thống mà có thể chạy được gần như tất cả các bộ code PHP hiện tại. Và đặc biệt công cụ để giúp chúng ta đơn giản hóa trong vấn đề build chính là bộ script buil server của Directadmin, đây là một bộ script khá hoàn chỉnh giúp chúng ta có thể build một server từ source code mà không cần biết quy trình build như thế nào, có thể nói là mỳ ăn liền.

Bài này khá dài nên tôi sẽ ngắt ra làm nhiều bài nhỏ cho tiện, mỗi bài là một chủ điểm cài khác nhau. Các thứ tự cài đặt sẽ là:

  • Cài đặt CentOS và chú ý khi cài và sau khi cài
  • Cài đặt và config cơ bản cho MySQL
  • Download và setup Directadmin và Update Script
  • Cài đặt các thành phần liên quan.
  • Cấu hình sau cài đặt và thử nghiệm demo.

Nào chúng ta cùng bắt đầu.

Các lệnh cơ bản của MySQL P4

Date: 3 Tháng 3 2010 Comments:0

Load a CSV file into a table.

mysql> LOAD DATA INFILE ‘/tmp/filename.csv’ replace INTO TABLE [table name] FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\n’ (field1,field2,field3);

Dump all databases for backup. Backup file is sql commands to recreate all db’s.

# [mysql dir]/bin/mysqldump -u root -ppassword –opt >/tmp/alldatabases.sql

Dump one database for backup.

# [mysql dir]/bin/mysqldump -u username -ppassword –databases databasename >/tmp/databasename.sql

Dump a table from a database.

# [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql

Restore database (or database table) from backup.

# [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql

Create Table Example 1.

mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));

Create Table Example 2.

mysql> create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default ‘bato’);

Tags: ,

Các lệnh cơ bản của MySQL P3

Date: 3 Tháng 3 2010 Comments:0

Join tables on common columns.

mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;

Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,User,Password) VALUES(‘%’,'username’,PASSWORD(‘password’));
mysql> flush privileges;

Change a users password from unix shell.

# [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password ‘new-password’

Change a users password from MySQL prompt. Login as root. Set the password. Update privs.

# mysql -u root -p
mysql> SET PASSWORD FOR ‘user’@'hostname’ = PASSWORD(‘passwordhere’);
mysql> flush privileges;

Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.

# /etc/init.d/mysql stop
# mysqld_safe –skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD(“newrootpassword”) where User=’root’;
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start

Set a root password if there is on root password.

# mysqladmin -u root password newpassword

Update a root password.

# mysqladmin -u root -p oldpassword newpassword

Allow the user “bob” to connect to the server from localhost using the password “passwd”. Login as root. Switch to the MySQL db. Give privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> grant usage on *.* to bob@localhost identified by ‘passwd’;
mysql> flush privileges;

Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES (‘%’,'databasename’,'username’,'Y’,'Y’,'Y’,'Y’,'Y’,'N’);
mysql> flush privileges;

or

mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;

To update info already in a table.

mysql> UPDATE [table name] SET Select_priv = ‘Y’,Insert_priv = ‘Y’,Update_priv = ‘Y’ where [field name] = ‘user’;

Delete a row(s) from a table.

mysql> DELETE from [table name] where [field name] = ‘whatever’;

Update database permissions/privilages.

mysql> flush privileges;

Delete a column.

mysql> alter table [table name] drop column [column name];

Add a new column to db.

mysql> alter table [table name] add column [new column name] varchar (20);

Change column name.

mysql> alter table [table name] change [old column name] [new column name] varchar (50);

Make a unique column so you get no dupes.

mysql> alter table [table name] add unique ([column name]);

Make a column bigger.

mysql> alter table [table name] modify [column name] VARCHAR(3);

Delete unique from table.

mysql> alter table [table name] drop index [colmn name];

Tags: ,
  • Search for:
  • Phản hồi gần đây

  • Tags Cloud