取经路上 2019-06-26
现在才发现理清一件事的原委是多么快乐的一件事,我们共同勉励。
懒得扯淡,直接正题
关于注册 linode 账户和如何选择 vps,相关教程已经有很多了,在下讲解一下如何搭建 LAMP 和 node 的 web server。
注意,本文针对centos 7进行讲解参考 官网 Get Start
# 连接服务器 $ ssh [email protected] # 输入密码 # Install Software Updates $ yum update # Setting the Hostname $ hostnamectl set-hostname example_hostname # 查看刚才设置的 hostname $ hostname # Set the TimezonePermalink $ timedatectl set-timezone 'Asia/Hong_Kong' # 查看当前系统时间 $ date
# 添加用户 $ useradd example_user && passwd example_user # 设置权限:增加新用户到 wheel 用户组,以获得执行 sudo 的权限 $ usermod -aG wheel example_user # 使用 SSH 密钥认证 # 本地生成ssh 密钥 # server 创建目录 $ mkdir .ssh $ 客户端公钥拷贝到server $ scp ~/.ssh/id_rsa.pub [email protected]:.ssh/authorized_keys # 修改 .ssh 的所有者(注意:所有者不要是 root 帐号)和执行权限(仅所有者可读写) $ chown -R example_user:example_user .ssh $ chmod 700 .ssh $ chmod 600 .ssh/authorized_keys # 现在试一下无密码ssh吧
按照官网搭建一直有坑,没有解决,本文参考Shadowsocks Server搭建。
sudo yum install m2crypto python-setuptools -y sudo easy_install pip sudo pip install shadowsocks
{
"server":"your_server_ip",
"server_port":8388,
"local_port":1080,
"password":"your_passwd",
"timeout":600,
"method":"aes-256-cfb"
}# 开启 sudo ssserver -c /etc/shadowsocks.json -d start # 停止 sudo ssserver -d stop # 重启 sudo ssserver -c /etc/shadowsocks.json -d restart
# vi /etc/rc.local # 以下为添加内容 /usr/bin/ssserver -c /etc/shadowsocks.json -d start # vi /usr/lib/systemd/system/rc-local.service # 以下为添加内容 [Install] WantedBy=multi-user.target # 启动并查看rc.local服务运行状态 $ systemctl start rc-local $ systemctl status rc-local #设置开机自启动 $ systemctl enable rc-local
参考官网shadowsocks搭建,此处提醒一下shadowsocksX添加服务器的主机名不能是ip。
# 1. apache
$ sudo yum install httpd
# Edit httpd.conf
$ 备份/etc/httpd/conf/httpd.conf
# vi /etc/httpd/conf/httpd.conf
# 追加内容如下
KeepAlive Off
<IfModule prefork.c>
    StartServers        4
    MinSpareServers     20
    MaxSpareServers     40
    MaxClients          200
    MaxRequestsPerChild 4500
</IfModule>
# Configure Name-based Virtual HostsPermalink
# vi /etc/httpd/conf.d/vhost.conf
# 文件内容如下
NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/html/example.com/public_html/
    ErrorLog /var/www/html/example.com/logs/error.log
    CustomLog /var/www/html/example.com/logs/access.log combined
</VirtualHost>
# 创建web目录
$ sudo mkdir -p /var/www/html/example.com/{public_html,logs}
# Enable Apache to start at boot, and restart the service for the above changes to take place
$ sudo systemctl enable httpd.service
$ sudo systemctl restart httpd.service
2. mysql
$ sudo yum install mariadb-server
$ sudo systemctl enable mariadb.service
$ sudo systemctl start mariadb.service
$ mysql_secure_installation
# 连接数据库
$ mysql -u root -p
3. php
$ sudo yum install php php-pear
$ sudo yum install php-mysql
# vi /etc/php.ini
# 文件内容
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
error_log = /var/log/php/error.log
max_input_time = 30
$ sudo mkdir /var/log/php
$ sudo chown apache /var/log/php
$ sudo systemctl reload httpd在/var/www/html/example.com/public_html 下面新建一个index.html,通过域名和ip就可以访问了
在线在阿里万网上买的域名,直接添加一个A记录解析到我们的linode vps的ip上就好了
本文https使用let's encrtypt
# Installing dependent modules $ sudo yum install epel-release mod_ssl # Downloading the Let’s Encrypt client $ sudo yum install python-certbot-apache # Setting up the SSL certificate $ certbot --apache -d example.com -d www.example.com # Setting up auto renewal of the certificate $ sudo certbot renew # 定时任务更新 $ crontab -e # 脚本内容 0 0 * * 1 /usr/bin/certbot renew >> /var/log/sslrenew.log
$ yum install samba samba-client samba-common -y # NMB对客户端提供NetBIOS服务 $ systemctl start smb nmb $ systemctl enable smb nmb $ systemctl status smb nmb
$ sudo yum install lrzsz
LAMP on CentOS 7
Get Start
官网shadowsocks搭建
let's encrypt
[]()
Q: ssh 登陆服务器后,警告如下:
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
A: vi /etc/environment
LANG=en_US.utf-8 LC_ALL=en_US.utf-8
CentOS 7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下
# 安装 $ yum install firewalld firewall-config # 查看防火墙状态 $ systemctl status firewalld # 启动 $ systemctl start firewalld # 停止 $ systemctl stop firewalld # 开机禁用 $ systemctl disable firewalld # 更新防火墙规则 $ firewall-cmd --reload # 查看版本 $ firewall-cmd --version # 查看帮助 $ firewall-cmd --help # 设置 iptables service yum -y install iptables-services # 如果要修改防火墙配置,如增加防火墙端口3306 # vi /etc/sysconfig/iptables 增加规则 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT # 重启防火墙使配置生效 $ systemctl restart iptables # 设置防火墙开机启动 $ systemctl enable iptables
Redhat使用了SELinux来增强安全,关闭的办法为: 1. 永久有效 修改 /etc/selinux/config 文件中的 SELINUX="" 为 disabled ,然后重启。 2. 即时生效 $ setenforce 0 selinux状态可以通过以下命令查看: $ sestatus