[关闭]
@1405010304geshuaishuai 2016-09-14T03:01:03.000000Z 字数 8677 阅读 453

Mission 1 Installing & Configuring Servers on Linux

Server Linux


1. Server Softwares We have to install

  • SSH Server
  • FTP Server
  • Web Server
  • E-mail Server

2. Requirements

2-1 SSH Server

  • Install software such as openssh or something like that and test.

2-2 FTP Server

  • Install open-source or free FTP Server
  • Create Admin, Ordinary user account and allocate different authorization

2-3 Web Server

  • Insatll open-source or free Web Server
  • Design a personal homepage

2-4 E-mail Server

  • Install open-source or free E-mail Server
  • Create and manage user's E-mail

3. Map out a plan

  • For SSH Server: My Linux OS has been already installed with SSH Server before I use it so I'll skip this step.
  • For FTP Server: I'll install vsftpd on my Linux
  • For Web Server: Installing Apache2, Mysql server and PHP on Linux(LAMP)
  • For Email Server: To setup mail server in CentOS 6 (postfix-dovecot)

4. Experimental Contents

4-1 FTP Server-Installing and configuring vsftpd

Step 1 >> Isuue the below command to install vsftpd

  1. # yum -y install vsftpd

Vsftpd package installation is completed.

Step 2 >> After installation, now open /etc/vsftpd/vsftpd.conf which is the config file for vsftpd(FTP server).
Replace YES to NO in the below line.

  1. anonymous_enable=NO

Find and uncomment the below lines

  1. local_enable=YES
  1. write_enable=YES

and uncomment this line to limit the users to their home directories.

  1. chroot_local_user=YES

Step 3 >> Create a folder where you want to store FTP data. In my case I'm going to create in /(root folder) like below.

  1. # mkdir /pub

Step 4 >> Now start creating users for accessing ftp server.

  1. # useradd -d /pub test
  2. # passwd test

You just created username test with home directory /pub.

Step 5 >> Start vsftpd service by issuing the below command.

  1. # service vsftpd start

and type this below command to start service automatically while booting.

  1. # chkconfig --levels 235 vsftpd on

Step 6 >> That's it, now we can check the FTP access. Create some files in /pub folder.
You can use winscp tool to upload/download files from FTP server.

winscp

also,you can use browser to download files from FTP server.

page-file

Troubleshooting:

If you not able to connect ftp server, Disable the firewall(iptables) and selinux service on your ftp server.

Disable firewall(iptables)>>

  1. # service iptables stop
  1. # chkconfig iptables off

Disable Selinux >> open the file /etc/selinux/config and find the line

  1. SELINUX=enforcing

and replace with

  1. SELINUX=disabled

now reboot the server and try again.


4-2 Installing Apache2, Mysql server and PHP on Centos 6(LAMP)

In this tutorial we can see the step by step installation of Apache webserver along with mysql and php enabled.

Update yum repositories and packages by typing the below command

  1. # yum update

After updating repositories, we can start installing packages one by one.

  1. Apache2 installation and configuration
  2. Mysql installation
  3. PHP installation
  4. Testing all together

4-2-1 Apache2 installation

Apache2 package installation and configuration is very simple.

Step 1 >> just type the command

  1. # yum install httpd

This command will install httpd package along with dependencies

After installing the package.

Step 2 >> Open the file /etc/httpd/conf/httpd.conf.
Find "#ServerName www.example.com:80"(line no:276).

  1. #
  2. #ServerName www.example.com:80

and add this line below. "ServerName youripaddress:80"

  1. #
  2. #ServerName www.example.com:80
  3. ServerName 192.168.1.102:80

Step 3 >> Now start apache service

  1. # service httpd start

and type this below command to start apache service automatically while booting.

  1. # chkconfig --levels 235 httpd on

Step 4 >> Now you have successfully configured apache web server. Open your browser and type the ip address in the address bar and hit enter. You can see the test page of your web server.

Testing your page:

Goto the default apache root path /var/www/html. Create a new file index.html and paste the below code and save it.

  1. Welcome to my webserver

Again open the webserver ip address in the browser. You can see the index page created by you.

Welcome

4-2-2 Mysql installation

Step 1 >> just type the command to install mysql server and client packages along with dependencies.

  1. # yum install mysql-server

After installation packages and dependencies.

Step 2 >> Start mysql service

  1. # service mysqld start

and type this below command to start mysql server automatically while booting.

  1. # chkconfig --levels 235 mysqld on

Step 3 >> Create a new root password for mysqlserver

  1. # mysqladmin -u root password '********'

Step 4 >> Test your mysql server by login as root

  1. # mysql - u root -p(press enter)
  2. Enter password:(Type your mysql root password and press enter)

Now you can see the mysql prompt.

sql-test

4-2-3 PHP installation

Step 1 >> Install php package along with php-mysql.

  1. # yum install php php-mysql

After installing php, create a php info file to test your php configuration.

Step 2 >> Goto the default apache root path /var/www/html. Create a new file phpinfo.php and paste the below code and save it.

  1. <?php
  2. phpinfo();
  3. ?>

Step3 >> Restart apache service

  1. # service httpd restart

Step 4 >> open the filepath in the browser(http://192.168.1.102/phpinfo.php).
you can see the php information page as below.

php-test

Finally apache2, php and mysql has been configured perfectly. Few more steps need to be performed to check the database connectivity.

Testing All together:

We need to test mysql database connectivity in php.

Step 1 >> Create a new file dbtest.php in the apache root path(/var/www/html) and paste the below code. Replace "password" with your mysql root password.

  1. <?php
  2. $con = mysql_connect("localhost","root","password");
  3. if(!$con)
  4. {
  5. die('Could not connect: '.mysql_error());
  6. }
  7. else
  8. {
  9. echo "Congrats! connection established successfully";
  10. }
  11. mysql_close($con)
  12. ?>

Step 2 >> open the filepath in the browser(http://192.168.1.102/dbtest.php). You can see the page as below.

dbtest


4-3 Setup mail server in centos6 (postfix-dovecot)

>>Postfix(for sending)
>>Dovecot(for receving)

4-3-1 Installing and configuring postfix

Step 1 >> Before installation assign a static ip and add a host entry for your domain to that ip in /etc/hosts file like below.

  1. 192.168.0.15 geshuai.com

Step 2 >> Issue the below command to install postfix

  1. # yum -y install postfix

Step 3 >> Now issue the below command to install SMTP AUTH packages.

  1. # yum -y install cyrus-sasl cyrus-sasl-devel cyrus-sasl-gasspi cyrus-sasl-md5 cyrus-sasl-plain

Postfix package installation is completed.

Step 4 >> Issue the below commands one by one for creating SSL Cert.

  1. # mkdir /etc/postfix/ssl
  2. # cd /etc/postfix/ssl/
  3. # openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
  4. # chmod 600 smtpd.key
  5. # openssl req -new -key smtpd.key -out smtpd.csr
  6. # openssl x509 -req -days 365 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
  7. # openssl rsa -in smtpd.key -out smtpd.key.unencrypted
  8. # mv -f smtpd.key.unencrypted smtpd.key
  9. # openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 365

Step 5 >> Now open /etc/postfix/main.cf file.
Find and comment the below lines.

  1. #inet_interfaces = localhost #---> line no 116
  2. #mydestination = $myhostname, localhost.$mydomain, localhost #--> line no 164

and add these lines at the bottom of the line.

  1. myhostname = mail.geshuai.com
  2. mydomain = geshuai.com
  3. myorigin = $mydomain
  4. home_mailbox = mail/
  5. mynetworks = 127.0.0.0/8
  6. inet_interfaces = all
  7. mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
  8. smtpd_sasl_auth_enable = yes
  9. smtpd_sasl_type = cyrus
  10. smtpd_sasl_security_options = noanonymous
  11. broken_sasl_auth_clients = yes
  12. smtpd_sasl_authenticated_header = yes
  13. smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
  14. smtpd_tls_auth_only = no
  15. smtp_use_tls = yes
  16. smtpd_use_tls = yes
  17. smtp_tls_note_starttls_offer = yes
  18. smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
  19. smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
  20. smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
  21. smtpd_tls_received_header = yes
  22. smtpd_tls_session_cache_timeout = 3600s
  23. tls_random_source = dev:/dev/urandom

Step 6 >> Now open /etc/postfix/master.cf file and add the below line after smtp

  1. smtps inet n - n - - smtpd
  2. -o smtpd_sasl_auth_enable=yes
  3. -o smtpd_reject_unlisted_sender=yes
  4. -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  5. -o broken_sasl_auth_clients=yes

Step 7 >> Now start postfix and saslauthd service

  1. # service postfix start
  1. # service saslauthd start

>>Issue the below commands to start the postfix and saslauthd at startup

  1. # chkconfig --level 235 postfix on
  1. # chkconfig --level 235 saslauthd on

Step 8 >> Now check your smtp connectivity. Just telnet localhost on port 25 and type this command ehlo localhost

check-smtp

If you get this output.. Great .. everything is fine till now.

4-3-2 Installing and configuring dovecot

Step 9 >> Issue this command to install dovecot

  1. # yum -y install dovecot

Step 10 >> After installation open /etc/dovecot/dovecot.conf file and add the below line at the end of the file. Please make sure mail_location and home_mailbox in postfix configuration are using the same name.

  1. protocols = imap pop3
  2. mail_location = maildir:˜/mail
  3. pop_uidl_format=%08Xu%08Xv

Step 11 >> Now start dovecot service

  1. # service dovecot start

>>Issue the below command to start the devecot at startup

  1. # chkconfig --level 235 dovecot on

Step 12 >> Now test your pop3 connectivity.

pop3-test

Yes.. your server is ready to receive mails.

Step 13 >> Now create users to test your configuration.

  1. # useradd -m bobby -s /sbin/nologin
  1. # useradd -m leela -s /sbin/nologin

and create passwords for users created

  1. # passwd bobby
  1. # passwd leela

Step 14 >> Test your configuration in thunderbird. Refer the below image for configuration details

thunderbird

Step 15 >> Now you can send and receive mails using the server.

Your mail server is ready ...

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注