VPS维护
首先确认网关配置是否有错,检查/etc/resolv.conf
:
nameserver 127.0.0.1
nameserver 8.8.8.8
如果是类似字样说明配置正确,如果还是一样的错误
执行一下sudo ifconfig
如果发现只显示了lo,那么检查网卡配置文件/etc/sysconfig/network-scripts/ifcfg-ethx
是否出错
由于VPS配置了双网卡,网卡分别命名为eth0:0和eth0:1,所以要小心,基本的配置如下:
DEVICE=eth0:0
BOOTPROTO=static
ONBOOT=yes
IPADDR=VPS的IP
NETMASK=255.255.255.0
GATEWAY=VPS的网关
另外检查/etc/sysconfig/network
:
NETWORKING=yes
HOSTNAME=主机名
GATEWAY=VPS网关
然后ifup
相应网卡,再重启一下网络
参考:https://superuser.com/questions/901672/centos-7-ping-8-8-8-8-connect-network-is-unreachable
这是远程登录Linux的安全提示,打开这个文件可以查看登录日志,如果嫌烦,可以清空或删除。
执行echo "unset MAILCHECK">> /etc/profile
,再执行source /etc/profile
chmod 0 /usr/sbin/sendmailmv /usr/sbin/sendmail /usr/sbin/sendmail.bakln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
上面的方法是关闭sendmail服务,当然用户也可以自定义将邮件转发到自己的邮箱:
编辑/etc/log.d/logwatch.conf
:
添加MailTo = root,xxx@xxx.com
或者
编辑/etc/aliases
添加root: xxx@xxx.com
参考:解决Centos关闭You have new mail in /var/spool/mail/root提示
修改/etc/vim/vimrc.tiny
文件,将set compatible
设置成set nocompatible
. 这是因为有时候系统会默认vim兼容vi,所以使用vi的命令
某些VPS会自动杀掉部分进程,所以用这个脚本可以后台自动检测并自动重启进程
ssr(){
# 自行把 /home/shadowsocksr/run 修改成你自己的路径
cd /home/shadowsocksr/run && python server.py -d restart
}
while true
do
[[ -z `ps aux | grep -v grep | grep "python server.py -d start"` ]] && ssr
# 定时 5 分钟一检查
sleep 300
done
可以通过ps aux
查看相关后台内容
修改权限:
cd /etc/ssh
sudo chmod 644 ./*
sudo chmod 600 ssh_host_dsa_key
sudo chmod 600 ssh_host_rsa_key
sudo chmod 755 .
/etc/init.d/ssh restart
编辑ssh配置文件:
sudo vim /etc/ssh/sshd_config
补充上:
ClientAliveInterval 60
ClientAliveCountMax 3
然后重启,注意,使用sudo service ssh restart
而不要使用sudo /etc/init.d/ssh restart
(具体原因不明,有一次是用service命令才重启成功)
一次使用python,发现了一堆报错,检查后发现原来是python版本问题。
python --version
这里以2.7.3为例
wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar -xjvf Python-2.7.3.tar.bz2
./configure
make all
sudo make install && make clean && make distclean
sudo mv /usr/bin/python /usr/bin/python2.6.6
sudo ln -s /usr/local/bin/python2.7 /usr/bin/python
sudo vi /usr/bin/yum
将文件头部的
#!/usr/bin/python
改成
#!/usr/bin/python2.6
高版本的centos不会有这样问题,另外还要注意有些软件也可能会出现yum这样的情况
执行sudo pip install -r xxx.txt
的时候会报错,然后pip --version
查看一下pip版本也是报错:
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 356, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2476, in load_entry_point
return ep.load()
......
sudo apt-get remove python-pip
sudo easy_install pip
完成
参考自:https://askubuntu.com/questions/764222/nginx-installation-error-in-ubuntu-16-04
报错信息:
Errors were encountered while processing: nginx-full nginx
sudo cat /var/log/nginx/error.log|less
有可能是apache2的影响:
sudo service apache2 stop
#禁止apach2开机自启
sudo systemctl disable apache2.service
然后再安装
如果还是报错,尝试:
sudo apt-get remove nginx* --purge #
sudo apt-get install nginx-common
sudo apt-get install nginx
debian-minimal 的vps登录或者下载完一些软件之后报下列错误:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_MESSAGES = "zh_CN.UTF-8",
LANG = "zh_CN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
这是语言设置问题,不会影响正常使用,但是影响观感
sudo apt-get install localepurge
安装完成会弹出很多语言选项和说明,选择我们想要的语言,例如 en_US.UTF-8 和 zh_CN.UTF-8
如果想修改之前的设置:
sudo dpkg-reconfigure localepurge
生成自己想要的语言
sudo locale-gen zh_CN.UTF-8 en_US.UTF-8
打印当前配置信息
locale
或者也可以自己export
信息
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
指定ssh服务器语言
LC_ALL=en_US.UTF-8 ssh <host>
参考:
ubuntu 解决语言设置错误的问题
How to fix a locale setting warning from Perl?
出错信息如下:
dpkg: warning: 'ldconfig' not found in PATH or not executable
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
dpkg: error: 2 expected programs not found in PATH or not executable
Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin
E: Sub-process /usr/bin/dpkg returned an error code (2)
sudo apt-cache search ldconfig
得到:libc-bin - GNU C Library: Binaries
sudo apt-get install libc-bin
但是结果还是上面的问题,无法安装
输入:
export PATH=/usr/loca/sbin:/usr/sbin:/sbin:$PATH
或
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
解决
参考:
http://www.zhimengzhe.com/linux/329904.html
https://askubuntu.com/questions/399438/how-to-solve-dpkg-error-1-expected-program-not-found-in-path-or-not-executabl
申请了一个国外的webdav网盘,准备挂载到自己的VPS上
ls -l /dev/sd*
有些VPS上并没有sd*的设备,也就是要用户自己创建
fdisk /dev/sdc
输入n
,新建磁盘,连续多次回车,然后输入w
,将配置写入分区表
这里如果输入fdisk
后不能识别命令,按照下面操作:
# 查看环境变量
root@simonc:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 软连接
root@simonc:~# ln -s /sbin/fdisk /usr/bin/
如果新建磁盘出现下面:
root@simonc:~# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
fdisk: cannot open /dev/sdc: No such file or directory
mkfs -t ext4 /dev/sdc1
比如新建一个名叫/data
的挂载目录
mkdir -p /data
mount /dev/sdc1 /data
blkid
echo -ne "\nUUID=$(UUID)\t/data\text4\tdefaults\t1\t0\n" >> /etc/fstab