原因:前两天服务器的硬盘出故障,报错:scsi 0:0:2:0: rejecting I/O to dead device,报这个错误的时候重启过一次,撑了一个月时间,现在直接导致整个文件系统崩溃。很明显是硬盘出问题了(一直在线用了4年多,而且I/O操作也非常频繁),原来有3块sas硬盘,其中两块500G的作了Raid1,另一块1T是备份并作了LVM,现在很难确定是哪一块有问题,估计寿命也都差不多了,打算直接都换掉算了。
准备:现在备了一块256G固态硬盘用于装centos和一块1T的sas硬盘用作存储数据,并让机房帮忙安装了最小版的centos7,内核: 3.10.0-229.el7.x86_64。
一、网络设置及服务
原来的网络有两块网卡,一个接外网,一个接内网,直接执行ifconfig竟然提示无此命令,原来centos7最小版默认就不用这个了,可以用ip addr 和 ip link代替。而且ifcfg的名字也改为emN这种形式了,直接编辑/etc/sysconfig/network-scripts/ifcfg-em2配置内网ip,配好后执行service network restart,然后ping一下看能否连通其它内网机器。
可以在/lib/systemd/system/目录下创建一些扩展名为.service的服务配置文件,如:nginx.service.
二、安全设置
- 删除不用的用户:adm、lp、sync、shutdown、halt、ftp
- 更改sshd登录端口:
Port 12345#AddressFamily any#ListenAddress 0.0.0.0#ListenAddress ::# The default requires explicit activation of protocol 1Protocol 2
然后重启服务(注意: 在重启前请先保证防火墙已经放开了新的端口12345,具体参考下面的防火墙设置)
systemctl restart sshd.service
安装selinux管理命令:
semanage port -a -t ssh_port_t -p tcp 12345
查看端口列表
semanage port -l | grep ssh
-
防火墙:默认的已经由iptables转为了firewalld了(),如果用firewall参考,如果想继续用iptables可以参考
-
更多安全措施可参考:
三、磁盘设置
- 利用LVM增加硬盘及扩容,参考:http://www.centoscn.com/CentOS/config/2015/0315/4891.html;另外,也可以借助系统存储管理器管理LVM卷,参考:http://os.51cto.com/art/201409/450584.htm。
四、支撑环境
- 安装rabbitmq,参考:, 但在使用过程中发现没办法直接通过yum install erlang安装erlang,所以还得通过源码装。如果configure时指定了prefix,安装后还得在/etc/profile export指定path。在安装rabbitmq时提示
rabbitmq /bin/sh: zip: command not found
表示少了zip
yum install zip unzip
cd rabbitmq-server-3.5.3makemake install TARGET_DIR=/usr/local/rabbitmq SBIN_DIR=/usr/local/rabbitmq/sbin MAN_DIR=/usr/local/rabbitmq/man
后台启动
./rabbitmq-server -detached
rabbitmq安装后默认端口为5672,而且不需要特定的配置,如果想指定一些特殊配置,可以参考:
-
安装cmake:
wget http://www.cmake.org/files/v3.3/cmake-3.3.0-rc3.tar.gztar zxf cmake-3.3.0-rc3.tar.gzcd cmake-3.3.0-rc3./configuremakemake install
-
安装mysql
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27.tar.gztar zxf mysql-5.6.27.tar.gzgroupadd mysqluseradd -g mysql mysql -s /bin/falsemkdir -p /data/mysqlchown -R mysql:mysql /data/mysqlmkdir -p /usr/local/mysqlcd mysql-5.6.27cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etcmakemake installcd /usr/local/mysqlcp ./support-files/my-huge.cnf /etc/my.cnfvi /etc/my.cnfdatadir = /data/mysql #添加MySQL数据库路径./scripts/mysql_install_db --user=mysqlcp ./support-files/mysql.server /etc/rc.d/init.d/mysqld chmod 755 /etc/init.d/mysqld chkconfig mysqld onvi /etc/rc.d/init.d/mysqldbasedir = /usr/local/mysqldatadir = /data/mysqlservice mysqld startvi /etc/profileexport PATH=$PATH:/usr/local/mysql/binln -s /usr/local/mysql/lib /usr/lib/mysqlln -s /usr/local/mysql/include/mysql /usr/include/mysqlmysql_secure_installation
如果mysql命令行登录时提示:段错误(),则需要按下面步骤处理:
-
安装pcre
tar zxvf pcre-8.37.tar.gzcd pcre-8.37./configure --prefix=/usr/local/pcremakemake install
- 安装openssl
wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz
-
安装nginx
1. yum安装参考:2.yum -y install zlib-devel
-
源码安装:
wget http://nginx.org/download/nginx-1.9.5.tar.gztar zxf nginx-1.9.5.tar.gzgroupadd wwwuseradd -g www www -s /bin/falsecd nginx-1.9.5./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/root/tools/pcre-8.36makemake install
3.设置为服务
cat >> /usr/lib/systemd/system/nginx.service << NGINX_SERVICE> [Unit]> Description=The nginx HTTP and reverse proxy server> After=syslog.target network.target remote-fs.target nss-lookup.target> > [Service]> Type=forking> PIDFile=/run/nginx.pid> ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf> ExecReload=/bin/kill -s HUP $MAINPID> ExecStop=/bin/kill -s QUIT $MAINPID> PrivateTmp=true> > [Install]> WantedBy=multi-user.target> NGINX_SERVICEsystemctl enable nginxsystemctl start nginx.service
-
安装php
- 1.安装php相关支持库
-
yum -y install libxml2 libxml2-devel libcurl-devel freetype freetype-devel libjpeg* libpng libpng-devel gd openssl openssl-devel libmcrypt
- 2.安装php
-
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir makemake install
-
安装redis
wget http://download.redis.io/releases/redis-3.0.2.tar.gztar zxvf redis-3.0.2.tar.gzcd redis-3.0.2 mkdir /usr/local/redismake PREFIX=/usr/local/redis install
-
安装ttserver,同时装一下httpsqs
wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.48.tar.gztar zxf tokyocabinet-1.4.48.tar.gzcd tokyocabinet-1.4.48./configure --prefix=/usr/local/tokyocabinet-1.4.48/makemake installwget http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gztar zxf tokyotyrant-1.1.41.tar.gzcd tokyotyrant-1.1.41./configure --prefix=/usr/local/tokyotyrant-1.1.41 --with-tc=/usr/local/tokyocabinet-1.4.48/wget http://httpsqs.googlecode.com/files/httpsqs-1.7.tar.gztar xzf httpsqs-1.7.tar.gzcd httpsqs-1.7vi Makefile #将tokyocabinet由1.4.47改为1.4.48makemake install
ttserver的php扩展
wget http://pecl.php.net/get/tokyo_tyrant-0.7.0.tgztar zxvf tokyo_tyrant-0.7.0.tgzcd tokyo_tyrant-0.7.0/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-tokyo-tyrant=/usr/local/tokyotyrant-1.1.41 --with-tokyo-cabinet-dir=/usr/local/tokyocabinet-1.4.48make && make install
-
安装sphinx
wget http://www.sphinx-search.com/downloads/sphinx-for-chinese-2.2.1-dev-r4311.tar.gztar zxf sphinx-for-chinese-2.2.1-dev-r4311.tar.gzcd sphinx-for-chinese-2.2.1-dev-r4311./configure --prefix=/usr/local/sphinx --with-mysqlmakemake install
安装sphinx的php扩展
cd sphinx-for-chinese-2.2.1-dev-r4311/api/libsphinxclient./configure –prefix=/usr/local/sphinxclientmake && make installwget http://pecl.php.net/get/sphinx-1.3.0.tgztar zxf sphinx-1.3.0.tgzcd sphinx-1.3.0/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinxclient/make make install
五、应用环境;