sto*_*ain 12 mysql php ssh centos apache-2.2
我正在一台机器上重新安装操作系统,该机器将用于为我们的业务托管几个应用程序。应用程序将仅限本地;来自外部客户端的访问将仅通过 VPN 进行。
之前的设置为大多数管理员使用了托管控制面板 (Plesk),我正在考虑使用另一个类似的软件进行重新安装 - 但我想我最终应该了解它是如何工作的。我可以做软件能为我做的大部分事情,但我不清楚这一切的共生关系。如果可能的话,这一切都是为了进一步远离Configuration Programmer/Programmer 领域。
我无法在任何地方找到我正在寻找的完整演练,所以我想我会提出这个问题,如果人们可以帮助我,我将用答案编辑它,并记录我的进步/陷阱。希望有一天这会帮助某人下线。
将 IUS 存储库添加到我们的包管理器
cd /tmp
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/epel-release-1-1.ius.el5.noarch.rpm
rpm -Uvh epel-release-1-1.ius.el5.noarch.rpm
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1-4.ius.el5.noarch.rpm
rpm -Uvh ius-release-1-4.ius.el5.noarch.rpm
yum list | grep -w \.ius\. # list all the packages in the IUS repository; use this to find PHP/MySQL version and libraries you want to install
Run Code Online (Sandbox Code Playgroud)
删除旧版本的 PHP 并从 IUS 安装新版本
rpm -qa | grep php # to list all of the installed php packages we want to remove
yum shell # open an interactive yum shell
remove php-common php-mysql php-cli #remove installed PHP components
install php53 php53-mysql php53-cli php53-common #add packages you want
transaction solve #important!! checks for dependencies
transaction run #important!! does the actual installation of packages.
[control+d] #exit yum shell
php -v
PHP 5.3.2 (cli) (built: Apr 6 2010 18:13:45)
Run Code Online (Sandbox Code Playgroud)
从 IUS 存储库升级 MySQL
/etc/init.d/mysqld stop
rpm -qa | grep mysql # to see installed mysql packages
yum shell
remove mysql mysql-server #remove installed MySQL components
install mysql51 mysql51-server mysql51-devel
transaction solve #important!! checks for dependencies
transaction run #important!! does the actual installation of packages.
[control+d] #exit yum shell
service mysqld start
mysql -v
Server version: 5.1.42-ius Distributed by The IUS Community Project
Run Code Online (Sandbox Code Playgroud)
IUS wiki 提供的升级说明:http : //wiki.iuscommunity.org/Doc/ClientUsageGuide。
scp和sftp访问,不允许ssh登录cd /tmp
wget http://dag.wieers.com/rpm/packages/rssh/rssh-2.3.2-1.2.el5.rf.x86_64.rpm
rpm -ivh rssh-2.3.2-1.2.el5.rf.x86_64.rpm
useradd -m -d /home/dev -s /usr/bin/rssh dev
passwd dev
Run Code Online (Sandbox Code Playgroud)
编辑/etc/rssh.conf以向 rssh 用户授予对 SFTP 的访问权限。
vi /etc/rssh.conf
Run Code Online (Sandbox Code Playgroud)
取消注释或添加:
allowscp
allowsftp
Run Code Online (Sandbox Code Playgroud)
这允许我通过 Transmit 中的 SFTP 协议连接到机器(我选择的 FTP 程序;我确定它与其他 FTP 应用程序类似)。
来自http://www.cyberciti.biz/tips/linux-unix-restrict-shell-access-with-rssh.html 的rssh 说明(感谢!)。
ifconfig eth1:1 192.168.1.3 up #start up the virtual interface
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth1 ifcfg-eth1:1 #copy default script and match name to our virtual interface
vi ifcfg-eth1:1 #modify eth1:1 script
Run Code Online (Sandbox Code Playgroud)
#ifcfg-eth1:1 | 修改如下:
DEVICE=eth1:1
IPADDR=192.168.1.3
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
NAME=eth1:1
根据需要重复添加更多虚拟接口。因为ONBOOT=yesifcfg-eth1:1文件中有一行,所以在系统启动,或者网络启动/重启的时候会出现这个界面。
service network restart
Run Code Online (Sandbox Code Playgroud)
关闭接口 eth0:[ OK ]
关闭接口 eth1: [ OK ]
关闭环回接口: [ OK ]
拉起环回接口: [ OK ]
拉起接口 eth0 : [ OK ]
拉起接口 eth1 : [ OK ]
ping 192.168.1.3
Run Code Online (Sandbox Code Playgroud)
来自 192.168.1.3 的 64 个字节:icmp_seq=1 ttl=64 time=0.105 ms
在上面的 rssh 部分中,我添加了一个用于 SFTP 的用户。在这个用户的主目录中,我创建了一个名为“https”的文件夹。这是该站点的文档所在的位置,因此我需要添加一个指向它的虚拟主机。我将在这个站点上使用上面的虚拟接口(这里称为 dev.site.local)。
vi /etc/http/conf/httpd.conf
Run Code Online (Sandbox Code Playgroud)
将以下内容添加到 httpd.conf 的末尾:
<VirtualHost 192.168.1.3:80>
ServerAdmin dev@site.local
DocumentRoot /home/dev/https
ServerName dev.site.local
ErrorLog /home/dev/logs/error_log
TransferLog /home/dev/logs/access_log
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
我在 https 目录中放置了一个虚拟的 index.html 文件只是为了检查所有内容。我尝试浏览它,但遇到了权限被拒绝的错误。日志只对正在发生的事情给出了一个模糊的参考:
[Mon May 17 14:57:11 2010] [error] [client 192.168.1.100] (13)权限被拒绝:访问 /index.html 被拒绝
我试过 chmod 777 等。al.,但无济于事。原来,我需要 chmod+x https 目录及其父目录。
chmod +x /home
chmod +x /home/dev
chmod +x /home/dev/https
Run Code Online (Sandbox Code Playgroud)
这解决了这个问题。
我正在通过我们本地的 Windows Server 2003 机器处理 DNS。然而,BIND 的 CentOS 文档可以在这里找到:http : //www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-bind.html
为了让 SSL 工作,我在 httpd.conf 中更改了以下内容:
NameVirtualHost 192.168.1.3:443 #make sure this line is in httpd.conf
<VirtualHost 192.168.1.3:443> #change port to 443
ServerAdmin dev@site.local
DocumentRoot /home/dev/https
ServerName dev.site.local
ErrorLog /home/dev/logs/error_log
TransferLog /home/dev/logs/access_log
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
不幸的是,在尝试使用 SSL 访问页面时,我不断收到(错误代码:ssl_error_rx_record_too_long)错误。正如 JamesHannah在下面优雅地指出的那样,我没有在 httpd.conf 中设置证书的位置,因此将页面抛出到浏览器作为证书使浏览器犹豫不决。
所以首先,我需要设置一个CA并制作证书文件。我在这里找到了一个很棒的(如果旧的)演练:http : //www.debian-administration.org/articles/284。
以下是我从那篇文章中采取的相关步骤:
mkdir /home/CA
cd /home/CA/
mkdir newcerts private
echo '01' > serial
touch index.txt #this and the above command are for the database that will keep track of certs
Run Code Online (Sandbox Code Playgroud)
openssl.cnf在/home/CA/目录中创建一个文件并按照上面链接的演练对其进行编辑。(作为参考,我完成的 openssl.cnf 文件如下所示:http ://pastebin.com/raw.php?i=hnZDij4T )
openssl req -new -x509 -extensions v3_ca -keyout private/cakey.pem -out cacert.pem -days 3650 -config ./openssl.cnf #this creates the cacert.pem which gets distributed and imported to the browser(s)
Run Code Online (Sandbox Code Playgroud)
openssl.cnf根据演练说明再次修改。
#generates certificate request, and key.pem which I renamed dev.key.pem.
openssl req -sha1 -new -nodes -out dev.req.pem -config ./openssl.cnf
Run Code Online (Sandbox Code Playgroud)
openssl.cnf根据演练说明再次修改。
#create and sign certificate.
openssl ca -out dev.cert.pem -md sha1 -config ./openssl.cnf -infiles dev.req.pem
Run Code Online (Sandbox Code Playgroud)
cp dev.cert.pem /home/dev/certs/cert.pem
cp dev.key.pem /home/certs/key.pem
Run Code Online (Sandbox Code Playgroud)
我更新了 httpd.conf 以反映证书并打开 SSLEngine:
NameVirtualHost 192.168.1.3:443
<VirtualHost 192.168.1.3:443>
ServerAdmin dev@site.local
DocumentRoot /home/dev/https
SSLEngine on
SSLCertificateFile /home/dev/certs/cert.pem
SSLCertificateKeyFile /home/dev/certs/key.pem
ServerName dev.site.local
ErrorLog /home/dev/logs/error_log
TransferLog /home/dev/logs/access_log
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
将 CA cert.pem 放在可通过网络访问的位置,并将其下载/导入到我的浏览器中。现在我可以访问https://dev.site.local而没有错误或警告。
这就是我所在的位置。随着我的进步,我会继续编辑这个。任何有关如何配置 SSL 电子邮件和/或配置到另一个将成为 MySQL 服务器的 Box 的安全连接的提示都将不胜感激。
本指南有很多关于在 Apache 中使用 SSL 的答案,告诉您如何创建自签名证书、如何从公认的证书颁发机构 (CA) 获取正确的证书以及如何创建您自己的、不受信任的 CA 以创建自签名证书完整的证书。http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html
对于虚拟主机和SSL,每个主机都需要自己的IP地址,或者更脏的解决方案是将它们托管在不同的端口上,:443由于SSL证书的性质,基于名称的虚拟主机与SSL不兼容;这就是为什么你需要另一种方法来区分;不同的端口/IP。
设置 SSH 非常简单,它应该已经在您的服务器上运行了。您将需要做很多事情来锁定它。
PermitRootLogin no
AllowGroups admins
PubkeyAuthentication yes
PermitEmptyPasswords no
PasswordAuthentication no
Run Code Online (Sandbox Code Playgroud)
它可以添加到您/etc/ssh/sshd_config的限制远程 root 访问,并删除密码身份验证,而不是使用公钥/私钥对登录。
要创建您的 SSH 密钥对,您可以puttygen在 Windows 中使用;http://putty.very.rulez.org/download.html也可以创建在Linux环境中,像这样的密钥对:ssh-keygen -b 2048 -t RSA -f my_keypair。这将创建一个my_keypair文件和一个my_keypair.pub文件(仅为本示例命名,我可能建议为您的用户名命名或保留-f,并让它生成~/.ssh/id_rsa)。
安全传输my_keypair到您的工作站,以供将来 SSH 访问,这是私钥,您不应与任何人共享。然后,在服务器上,创建$HOME/.ssh如果它不存在,mkdir ~/.ssh,然后复制公钥(my_keypair.pub)来~/.ssh/,如果你已经拥有authorized_keys的~/.ssh,因为你这样做的其他事情,你可以做cat my_keypair.pub >> authorized_keys附加你的公钥,或者cp my_keypair.pub authorized_keys如果它不存在。
现在运行chmod 700 ~/.ssh并chmod 644 ~/.ssh/my_keypair.pub ~/.ssh/authorized_keys设置权限。您可以保留一份my_keypairin~/.ssh/以在连接到其他主机时使用,但您应该这样做chmod 600 ~/.ssh/my_keypair以确保没有其他人可以访问它。
您需要为自己添加一个普通用户帐户,并将自己添加到 以外的组中users,就像admins在我的示例中一样。
您可能还想添加您的用户或组/etc/sudoers以启用sudo使用(如果您还没有)。这是通过命令完成的,visudo这是编辑此文件的唯一方法。visudo在写出之前对您的配置运行错误和语法检查,以防止sudo使用损失。
username ALL=(ALL) ALL
Run Code Online (Sandbox Code Playgroud)
添加到/etc/sudoers将允许username运行sudo yum install blah并提示您输入自己的密码。如果您有其他管理员或临时管理员,这很方便,您不需要共享 root 密码。
| 归档时间: |
|
| 查看次数: |
1587 次 |
| 最近记录: |