新装Linux服务器操作指南

  • 发布时间:2015-05-06 21:02:10
  • 阅读次数:164

CentOS 6.5 64位服务器 - 虚拟主机配置

一、初始设置

1、删除不必要的软件组 yum groupremove,只保留E-mail server,Security Tools这两个

2、修改时区和时间

rm -f /etc/localtime

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

date -s "14:00:00"

hwclock -w

3、禁用防火墙

vi /etc/sysconfig/selinux

修改:SELINUX=disabled

service iptables stop && chkconfig iptables off

service ip6tables stop && chkconfig ip6tables off

4、安装增强版yum库

yum install epel-release -y

5、网络设置

vi /etc/sysconfig/network-scripts/ifcfg-eth0

<pre class="brush:bash;toolbar:false">DEVICE=eth0
Type=Ethernet
ONBOOT=yes
BOOTPROTO=none(这里原来是dhcp)
IPADDR=**.**.**.**(这行需要添加的,就是分配的IP地址)
NETMASK=255.255.255.0
GATEWAY=**.**.**.**
DNS1=114.114.114.114
DNS2=8.8.8.8
IPV6INIT=no
IPV6_AUTOCONF=no

6、服务器更新并重启

yum update -y

reboot

二、安装软件

1、Apache + VSFTP

yum install httpd -y

yum install mod_bw -y

yum install httpd-itk -y

yum install vsftpd -y

2、PHP + MySQL

yum install php -y

yum install php-bcmath php-gd php-mcrypt php-mbstring php-mysql -y

yum install mysql-server -y

service mysqld start && chkconfig mysqld on

mysql_secure_installation

3、Zend Guard (64 bit for PHP 5.3)

下载并解压:http://www.zend.com/en/products/guard/downloads

tar -xzvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz

cp ZendGuardLoader.so /usr/lib64/php/modules/ (PHP模块地址)

vi /etc/php.d/zendguard.ini

<pre class="brush:bash;toolbar:false">添加内容:
zend_extension=/usr/lib64/php/modules/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=0

service httpd graceful

php -m 验证是否加载成功

三、配置软件

vi /etc/sysconfig/httpd

改成HTTPD=/usr/sbin/httpd.itk,并删除注释

vi /etc/httpd/conf/httpd.conf

禁用代理模块,注释掉LoadModule proxy_这几行。
ServerName localhost.localdomain
<Directory "/">  AllowOverride 从None改成All
<Directory "/var/www/html"> Options -Indexes(加上减号)
修改默认首页,DirectoryIndex index.php index.html index.htm default.html default.htm<br></br>

rm -f /var/www/html/*.*

cd /etc/httpd/conf.d

rm -f mod_bw.conf welcome.conf README

vi 0host.conf (用0开头的意义是让该文件在其他虚拟主机conf文件之前加载)

添加内容:
LoadModule bw_module modules/mod_bw.so

NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot /var/www/html
</VirtualHost>

vi php.conf

添加内容:
<IfModule itk.c>
  LoadModule php5_module modules/libphp5.so
</IfModule>
注释掉#DirectoryIndex index.php这行

service httpd start && chkconfig httpd on 重启Apache检查是否有报错

vi /etc/vsftpd/vsftpd.conf

<pre class="brush:bash;toolbar:false">anonymous_enable改成NO
删除注释:chroot_local_user=YES

service vsftpd start && chkconfig vsftpd on

vi /etc/php.ini

<pre class="brush:bash;toolbar:false">short_open_tag = 改成On<p>date.timezone = 去掉注释,改成"US/Pacific"</p><p>session.save_path = "/tmp"</p><p>disable_functions = mail(禁用mail函数)</p>

四、启用磁盘配额(一般是/home分区)

vi /etc/fstab

在要修改的分区defaults后面加上,usrquota

mount -o remount /home

yum install quota -y

quotacheck -vum /home

quotaon -av

查看某用户的磁盘配额:quota -u username

五、设置API网站

cd /home

mkdir -p zhaomuapi/{wwwroot,logfiles}

vi /etc/httpd/conf.d/0host.conf

添加内容:
Listen 8188
<VirtualHost *:8188>
   DocumentRoot /home/zhaomuapi/wwwroot
   ErrorLog /home/zhaomuapi/logfiles/error_log
   CustomLog /home/zhaomuapi/logfiles/access_log common
   <Directory />
      Order deny,allow
      Deny from all
      Allow from 58.215.65.49
   </Directory>
</VirtualHost>

chmod +w /etc/sudoers

vi /etc/sudoers

<pre class="brush:bash;toolbar:false">按2次PgDn键,注释掉#Defaults    requiretty这行
再按3次PgDn键,在root All这行下添加
apache  ALL=(ALL)       NOPASSWD:/home/zhaomuapi/wwwroot/*.sh

chmod -w /etc/sudoers

最后复制API程序到/home/zhaomuapi/wwwroot中,并测试是否可以开通空间,注意其中的.sh文件要给x执行权限。

六、启用备份

yum remove postfix

yum install crontabs

crontab -e

30 2 * * 2 /home/zhaomuapi/wwwroot/backup.sh

七、其他设置

vi /root/.bashrc

加上这行:alias ls='ls -la' (默认显示隐藏文件)

更改远程端口为8322:http://www.zhaomu.com/help/detail-487.html

添加一块硬盘作为备份:http://www.sudu.cn/service/detail.php?id=11831

安装RAR和ZIP,以支持文件压缩解压

yum install zip unzip -y

cd /root

wget http://www.rarlab.com/rar/rarlinux-x64-5.4.0.tar.gz

tar -zxvf rarlinux-x64-5.4.0.tar.gz

cd rar

cp rar unrar /bin

=============================

Extend a LVM volume in a Hyper-V Linux VM

Creating the LVM partition

All of the commands need to be done with root or a user with sudo rights as root.

First we need to create the LVM partition in fdisk

linuxapptest # fdisk /dev/hda

Type p to print current partition configuration

Command (m for help): p

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          31      248976   83  Linux
/dev/hda2              32        3263    25961040   8e  Linux LVM

Type n for a new partition

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)

Type p for primary

Partition number (1-4): 3

Type 3 since it is next partition number available

Just enter at the next two prompts to use the full amount of storage we added to the hard drive. Your cylinder numbers will probably be different then my example.

First cylinder (1-10443, default 7000):

Last cylinder or +size or +sizeM or +sizeK (1-10443, default 10443):

Now we need to change the new partition’s system id/type to LVM

Command (m for help): t
Partition number (1-4):

Type partition 3

Hex code (type L to list codes): 8e

Type 8e to change the partition type to LVM

Changed system type of partition 1 to 8e (Linux LVM)

We aren’t finished yet. Be sure to type w so the changes will be committed to the disk.

Command (m for help): w
The partition table has been altered!

Adding the additional storage

Create a Physical volume from the new partition

linuxapptest # pvcreate /dev/hda3

Display the LVM information so we grow the correct Volume Group

linuxapptest # lvdisplay
  --- Logical volume ---
  LV Name                /dev/linuxapptest/root
  VG Name                linuxapptest
  LV UUID                jvOih8-hex2-s2Ec-avuL-wtG2-M1KI-JVY6PG
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                23.69 GB
  Current LE             6064
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0

  --- Logical volume ---
  LV Name                /dev/linuxapptest/swap_1
  VG Name                linuxapptest
  LV UUID                qOASw0-GmoL-dipj-ORrP-qRxv-yOdE-g9i7dE
  LV Write Access        read/write
  LV Status              available
  # open                 2
  LV Size                1.07 GB
  Current LE             274
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:1

We now add the new partition to the Volume Group. You see that our Volume Group name (VG Name) is linuxapptest.

 linuxapptest # vgextend linuxapptest /dev/hda3

Next we add the new storage to the logical volume. We want to expand the “root” logical volume. The command will add all of the free storage to logical volume.

linuxapptest # lvresize -l +100%FREE /dev/linuxapptest/root

Online expansion of the filesystem

linuxapptest # resize2fs /dev/linuxapptest/root

At this point your Linux VM has the additional storage to use. I also like to reboot the server at this point to make sure everything works after a clean boot.

【全文完】

< 上一篇:VPS云主机在线监控和流量统计功能正式上线 下一篇:每日网站推广工作表 >