VPS는 자신만이 사용하는 서버로 간주할 수 있습니다(실제로는 가상 머신입니다). 여기에는 모든 소프트웨어를 설치할 수 있으며 최대 권한이 있습니다. 속담처럼 권한이 크면 책임도 커집니다. 웹 서버, 데이터베이스, PHP 및 기타 유지 관리 작업을 직접 설치해야 합니다.
현재 대부분의 VPS에서 제공하는 운영체제는 Linux이며, 그래픽 인터페이스가 없으며 SSH 명령줄 인터페이스만 제공하므로 몇 가지 간단한 Linux 명령줄을 알아야 합니다. Linux에는 다양한 배포판이 있습니다. 가장 좋은 배포판은 Redhat일 수 있지만 상용 소프트웨어이므로 무료로 사용할 수 없습니다. 다행히 Redhat의 소스 코드를 완전히 사용하고 Redhat 로고를 제거하는 커뮤니티 버전 CentOS도 있습니다. 그리고 일부 비공개 소스 소프트웨어를 제거하면 시스템 기능, 성능, 안정성이 Redhat과 거의 동일하므로 선택했습니다.
리눅스 설치
Linux 설치의 경우 Ubuntu, Debian, Fedora 등 익숙한 배포판을 선택하면 됩니다. 서비스 제공업체에서는 기본적으로 최소 설치 모드로 설치해 주므로 제가 선택한 버전은 CentOS 6.3입니다. VPS 메모리 계정이 작을수록 32비트 버전이 설치됩니다.
설치 후 루트 사용자로 로그인하여 시스템이 필요한 일부 업데이트를 수행하도록 허용합니다. Linux와 Mac 모두 터미널이 함께 제공됩니다. Windows의 경우 SSH 연결에는 PuTTY를 사용하는 것이 좋습니다.
#以 root 用户登陆服务器 ssh root@198.xxx.xxx.xxx ... #系统更新 yum update ...
아파치 설치
Apache는 Linux 플랫폼의 오래된 무료 오픈소스 웹 서버로, 전 세계 웹사이트의 절반 이상이 Apache에서 운영되고 있다고 합니다. Apache를 설치하려면 명령줄에 다음 명령을 입력하세요.
yum install httpd
기본적으로 설치되는 Apache 버전은 최신 버전이 아닐 수 있지만, 실제로는 이번 Linux 버전에서 테스트한 가장 안정적인 버전입니다. 최신 버전을 설치해야 하는 경우 Apache 공식 웹사이트에서 최신 버전을 다운로드해야 합니다. .
설치 후 다음 명령을 실행하여 Apache 서비스를 시작합니다.
service httpd start
기본 웹페이지 저장 디렉터리는 /var/www/html/이며, 브라우저에서 http://198.xxx.xxx.xxx로 접속하면 아파치의 테스트 페이지가 나타난다는 의미입니다. 이(가) 성공적으로 설치되었습니다.
MySQL 설치
MySQL은 원래 스웨덴 회사인 MySQL AB에서 개발했으며 나중에 Sun에서 인수한 매우 인기 있는 데이터베이스 소프트웨어입니다. MySQL을 설치하는 명령은 다음과 같습니다.
yum install mysql-server
service mysqld start
/usr/bin/mysql_secure_installation
그러면 Y 또는 N을 선택하라는 보안 옵션이 표시됩니다. 예를 들어 익명 로그인 제거 여부, 루트 사용자의 원격 로그인 방지 여부, y를 선택하면 루트는 localhost를 통해서만 로그인할 수 있는지, 테스트 데이터베이스 제거 여부, 권한 테이블 즉시 새로 고침 여부 등이 있습니다. 일반적인 상황은 다음과 같습니다.
[root@CentOS6 ~]# /usr/bin/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): 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] y New password: Re-enter new password: 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] y ... 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] y ... 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] y - 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] y ... 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!
PHP 설치
PHP는 널리 사용되는 오픈 소스 동적 스크립팅 언어입니다. PHP를 설치하고 MySQL과 함께 작동하게 하려면 다음 명령을 실행해야 합니다.
yum install php php-mysql
#切换到 Apache 默认网页目录 cd /var/www/html #创建一个 php 脚本文件 touch phpinfo.php #向文件写入一小段 php 脚本,测试用 echo '<?php phpinfo(); ?>' > phpinfo.php <p># 因为刚刚安装了 PHP,所以别忘了重启一下 Apache,否则 PHP 不能正常工作<br />service httpd restart</p>
http://198.xxx.xxx.xxx/phpinfo.php를 방문하여 PHP가 제대로 작동하는지 확인하세요.
페이지에 서버 관련 환경 정보가 정상적으로 표시된다면 LAMP 환경이 정상적으로 작동하고 있다는 의미입니다.
vsftpd 설치
yum install vsftpd
#编辑 vsftpd 配置文件 vi /etc/vsftpd/vsftpd.conf ... #不允许匿名登陆 anonymous_enable=NO #本地账户可以登陆 local_enable=YES #可以写入 write_enable=YES #所有用户只能访问其 home 目录 chroot_local_user=YES ... #重启 vsftpd 以上设置才能生效 service vsftpd restart
vsftpd에 로그인하려면 일반적으로 Linux 사용자 영역을 사용하여 로그인하지만 루트 사용자는 로그인이 허용되지 않으므로 새로운 Linux 사용자를 생성해야 합니다.
#添加用户 lichao adduser lichao #为 lichao 设置密码 passwd lichao #如果出于安全考虑,这个用户你只想它能登陆 vsftpd, #而不能以 ssh 方式登陆服务器,可以禁止其 ssh 登陆 usermod -s /sbin/nologin lichao
부팅 시 시작되도록 Apache, MySQL 및 vsftpd 서비스 설정
chkconfig httpd on chkconfig mysqld on chkconfig vsftpd on
이 시점에서 기본적으로 완전한 동적 웹 서버, 데이터베이스 서버, FTP 서버가 설치됩니다.