如果你的服务器的总是报告内存不足,并且时常因为内存不足而引发服务被强制kill的话,在不增加物理内存的情况下,启用swap交换区作为虚拟内存是一个不错的选择。

虚拟内存一般设置为物理内存的2倍即可,多了也是浪费硬盘

运行:free -m,可查询物理内存大小和swap空间大小,swap空间通常应为物理内存两倍大。

增加swap空间步骤:

1、dd if=/dev/zero of=/home/swap bs=1024 count=5120000

这样就会创建/home/swap分区文件。文件的大小是512000个block,一般情况下1个block为1K,所以这里空间是5120M。

2、/sbin/mkswap /home/swap

把这个分区变成swap分区.

3、/sbin/swapon /home/swap

使其成为有效状态。

 

现在再用free -m命令查看一下内存和swap分区大小,就发现增加了5120M。

宝塔面板的访问一般是服务器ip:端口号这样访问,但是不排除你的IP被那啥了之后访问不了的情况。突然奇想,如果我们给宝塔面板设置一个域名,然后在把这个域名套入到cdn中,来实现域名访问。这样理论上来说只要cloudflare不挂,你的面板就可以一直访问到。而且,通过cdn访问也隐藏了服务器ip,原则上来说也是安全的。

一:

新建网站

在面板中新建一个网站,不需要任何php版本只需选择纯静态

二:

在宝塔面板绑定域名

三:

cloudflare端口
By default, Cloudflare proxies traffic destined for the HTTP/HTTPS ports listed below.
HTTP ports supported by Cloudflare:

HTTP ports supported by Cloudflare: 80;8080;8880;2052;2082;2086;2095
HTTPS ports supported by Cloudflare: 443;2053;2083;2087;2096

四:

修改端口

我们需要把端口改为8080,宝塔面板修改端口,就是在面板设置中,不会的看图。

 

 

 

 

五:域名接入CDN

上面的都做好之后,我们现在可以把域名接入cloudflare中了。如图:

先把加速关闭灰色哈

六:

这一步很重要,在刚刚的新建的网站里面设置一个反D。
目标URL:http://127.0.0.1:8080

然后去cloudflare那边开启服务即可

效果图

这个功能的话还是比较使用我的作用是可以隐藏原服务器的ip也可以实现利用cloudflare拯救你的ip

原文来自大鸟博客

 

wget 时提示 -bash:wget command not found,很明显没有安装wget软件包。简单来说就是系统太干净了

然后就是直接复制运行这个命令即可

yum -y install wget

 

使用命令行工具 nmcli 来设置

#显示当前网络连接

#nmcli connection show

NAME UUID                                 TYPE           DEVICE

eno1 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet en1

#修改当前网络连接对应的DNS服务器,这里的网络连接可以用名称或者UUID来标识

#nmcli con mod en1 ipv4.dns "114.114.114.114 8.8.8.8"

#将dns配置生效

#nmcli con up eno1

安装脚本:

以下安装教程带的为mysql官方5.6最新版同步更新。内存占用已经优化到70M左右。

yum -y install wget
echo "timeout=120" >> /etc/yum.conf
yum -y update
yum -y install epel-release
chkconfig nscd off;service nscd stop;yum -y install dnsmasq;sed -i 's/#listen-address.*/listen-address=127.0.0.1/g' /etc/dnsmasq.conf;echo -e 'nameserver 127.0.0.1\nnameserver 8.8.8.8\nnameserver 2001:4860:4860::8888\nnameserver 2606:4700:4700::1111\nnameserver 1.1.1.1\nnameserver 114.114.114.114\nnameserver 119.29.29.29\noptions timeout:1 attempts:1 rotate' > /etc/resolv.conf;chkconfig dnsmasq on;service dnsmasq start
rm -rf /etc/yum.repos.d/CentOS-Base.repo
wget http://github.itzmx.com/1265578519/mirrors/master/CentOS/CentOS6-Base-itzmx.repo -O /etc/yum.repos.d/CentOS6-Base-itzmx.repo
rm -rf /etc/yum.repos.d/*pel.repo /etc/yum.repos.d/epel-testing.repo
wget http://github.itzmx.com/1265578519/mirrors/master/EPEL/epel.repo -O /etc/yum.repos.d/epel.repo
rpm -ivh http://github.itzmx.com/1265578519/repo/master/CentOS/mysql-community-release-el6-5.noarch.rpm
rm -rf /etc/yum.repos.d/mysql-community.repo /etc/yum.repos.d/mysql-community-source.repo
wget http://github.itzmx.com/1265578519/repo/master/CentOS/mysql-community.repo -O /etc/yum.repos.d/mysql-community.repo
yum clean all;yum makecache
yum -y install which file wget make automake gcc gcc-c++ pcre-devel zlib-devel openssl-devel sqlite-devel quota unzip bzip2 libaio-devel
ulimit -n 1048576
echo "* soft nofile 1048576" >> /etc/security/limits.conf
echo "* hard nofile 1048576" >> /etc/security/limits.conf
wget http://github.itzmx.com/1265578519/kangle/master/ent/e.sh -O e.sh;sh e.sh /vhs/kangle
wget http://github.itzmx.com/1265578519/kangle/master/kangle/easypanel/ep.sh -O ep.sh;sh ep.sh
yum -y install memcached php-pecl-memcache
yum -y install php-pecl-apc
rm -rf /etc/sysconfig/memcached
wget http://github.itzmx.com/1265578519/kangle/master/memcached/memcached -O /etc/sysconfig/memcached
service memcached start
chkconfig --level 2345 memcached on
echo "127.0.0.1 download.safedog.cn" >> /etc/hosts
setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
wget http://github.itzmx.com/1265578519/safedog/master/2.4/safedog_linux64.tar.gz
tar xzf safedog_linux64.tar.gz
cd safedog_linux64
chmod -R 777 install.py
./install.py
sdcmd webflag 0
sdcmd twreuse 1
sdcmd sshddenyflag 1
cd ..
yum -y install mysql mysql-server
rm -rf /etc/my.cnf
wget http://github.itzmx.com/1265578519/kangle/master/mysql/5.6/my.cnf -O /etc/my.cnf
service mysqld restart

如果你完全不需要数据库运行,比如说单独跑CDN反向代理,怕mysql占内存可以卸载:

yum -y remove mysql mysql*
rm -rf /var/lib/mysql/*
yum -y install mysql-libs

安装后通过访问进入后台设置,默认用户名admin,密码kangle,mysql数据库用户名root,密码空,初始化后点击左边的mysql管理进行修改root密码,修改后记得去服务器设置填写新密码

http://ip:3312/admin

建议使用的系统计划任务
执行进入计划任务编辑
crontab -e
添加条目,打开系统定期自动更新

45 * * * * /usr/bin/yum -y update

增加mysql守护进程,解决数据库进程闪退,内存不足自动退出

* * * * * /etc/init.d/mysqld start
原文链接