为什么80%的码农都做不了架构师?>>>
新买的云服务器,默认用户只有root,为了防止误操作,还是添加一个管理员为妙。
[root@localhost ~]# useradd maohao
添加管理员权限
[root@localhost home]# vi /etc/sudoers
## Allow root to run any commands anywhere
root ALL=(ALL) ALL#添加
maohao ALL=(ALL) ALL
设置密码
[root@localhost home]# passwd maohao
Changing password for user maohao.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
编辑防火墙
[maohao@localhost ~]$ sudo cat /etc/sysconfig/iptables
[sudo] password for maohao:
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
# -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
# -A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
重启防火墙
[maohao@localhost ~]$ sudo /etc/init.d/iptables restart
精简开机启动项
#设置格式
[maohao@localhost ~]$ LANG=en
#查看
[maohao@localhost ~]$ chkconfig --list|grep 3:on
#设置
[maohao@localhost ~]$ chkconfig --list|grep 3:on|grep -vE "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig " $1 " off"}'|bash
切换用户
[root@localhost home]# su mahao
开始干活了……
3
2
1
begin!
一、更新源
[maohao@localhost ~]$ sudo yum update -y
二、进行nginx源的安装
[maohao@localhost ~]$ sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
确认是否成功,查看信息
[mahao@localhost ~]$ yum info nginx
nginx version: nginx/1.12.2
版本太低,卸载
[maohao@localhost ~]$ sudo yum remove nginx
#查看
[maohao@localhost ~]$ which nginx
/usr/bin/which: no nginx in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/mahao/bi
准备安装环境
[maohao@localhost ~]$ sudo yum -y install gcc gcc-c++ autoconf automake make
[maohao@localhost ~]$ sudo yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
[maohao@localhost ~]$ sudo mkdir tools
[maohao@localhost ~]$ cd tools
[maohao@localhost tools]$ sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
[maohao@localhost tools]$ sudo tar -zxvf pcre-8.41.tar.gz
[maohao@localhost tools]$ cd pcre-8.41
[maohao@localhost pcre-8.41]$ sudo ./configure
[maohao@localhost pcre-8.41]$ sudo make
[maohao@localhost pcre-8.41]$ sudo make install
[maohao@localhost pcre-8.41]$ cd ../
[maohao@localhost tools]$ sudo wget http://zlib.net/zlib-1.2.11.tar.gz
[maohao@localhost tools]$ sudo tar -zxvf zlib-1.2.11.tar.gz
[maohao@localhost tools]$ cd zlib-1.2.11
[maohao@localhost zlib-1.2.11]$ sudo ./configure
[maohao@localhost zlib-1.2.11]$ sudo make
[maohao@localhost zlib-1.2.11]$ sudo make install
[maohao@localhost zlib-1.2.11]$ cd ../
[maohao@localhost tools]$ sudo wget http://www.openssl.org/source/openssl-fips-2.0.16.tar.gz
[maohao@localhost tools]$ sudo tar -zxvf openssl-fips-2.0.16.tar.gz
[maohao@localhost tools]$ cd openssl-fips-2.0.16
[maohao@localhost openssl-fips-2.0.16]$ sudo yum -y install openssl openssl-devel# 简单粗暴一点的方法
[maohao@localhost ~]$ sudo yum install gcc-c++
[maohao@localhost ~]$ sudo yum -y install pcre*
[maohao@localhost ~]$ sudo yum -y install openssl*
三、安装Nginx并设置开机启动
[maohao@localhost ~]$ sudo useradd nginx -s /sbin/nologin
[maohao@localhost ~]$ cd tools
[maohao@localhost tools]$ sudo wget http://nginx.org/download/nginx-1.9.9.tar.gz
[maohao@localhost tools]$ sudo tar -zxvf nginx-1.9.9.tar.gz
[maohao@localhost tools]$ cd nginx-1.9.9
[maohao@localhost tools]$ sudo ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[maohao@localhost tools]$ sudo make &&make install
修改配置文件
[maohao@localhost sbin]$ sudo vi /usr/local/nginx/conf/nginx.conf
找到这些 把标红的#全去掉,橘黄色的部分替换成暗红色部分
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#}
保存退出
重启
[mahao@localhost ~]$ sudo /usr/local/nginx/sbin/nginx -s reload
四、安装php
[maohao@localhost ~]$ sudo yum install php -y
[maohao@localhost ~]$ sudo yum install php-fpm -y
执行php -v查看版本
[maohao@localhost ~]$ php -v
PHP 5.3.3 (cli) (built: Mar 22 2017 12:27:09)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
5.3的版本很不爽
#检查当前安装的PHP包
[maohao@localhost ~]$ sudo yum list installed | grep php
#删除
[maohao@localhost ~]$ sudo yum remove php.x86_64 php-cli.x86_64 php-common.x86_64
php5.6安装
[maohao@localhost ~]$ sudo rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
[maohao@localhost ~]$ sudo yum -y --enablerepo=webtatic install php56w-devel
[maohao@localhost ~]$ sudo yum -y install php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64
这才看着舒服一点嘛
[maohao@localhost ~]$ php -v
PHP 5.6.32 (cli) (built: Oct 29 2017 19:00:01)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
下载安装PHP FPM设置启动
[mahao@localhost ~]$ sudo yum -y install php56w-fpm
#设置php-fpm开机启动
[mahao@localhost ~]$ sudo chkconfig php-fpm on
#启动php-fpm
[mahao@localhost ~]$ sudo /etc/init.d/php-fpm start
安装5.6的DOM扩展
[maohao@localhost ~]$ sudo yum install php56w-xml
五、安装mysql
[maohao@localhost ~]$ sudo yum install -y mysql mysql-server
[maohao@localhost ~]$ mysql -V
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
纳尼?5.1 卧槽,神马情况?卸载重装吧
[maohao@localhost ~]$ sudo rpm -qa | grep -i mysql
php56w-mysql-5.6.32-1.w6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64
查看mysql
[maohao@localhost ~]$ sudo rpm -qa | grep -i mysql
php56w-mysql-5.6.32-1.w6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64
终止mysql
[maohao@localhost init.d]$ sudo service mysqld stop
Stopping mysqld: [ OK ]
删除包
[maohao@localhost init.d]$ sudo rpm -ev mysql-server-5.1.73-8.el6_8.x86_64
[maohao@localhost init.d]$ sudo rpm -ev mysql-libs-5.1.73-8.el6_8.x86_64 --nodeps
[maohao@localhost init.d]$ sudo rpm -ev mysql-5.1.73-8.el6_8.x86_64
[maohao@localhost init.d]$ sudo find / -name mysql
/usr/share/mysql
/usr/lib64/mysql
/usr/lib64/perl5/auto/DBD/mysql
/usr/lib64/perl5/DBD/mysql
[maohao@localhost init.d]$ sudo rm -rf /usr/share/mysql
[maohao@localhost init.d]$ sudo rm -rf /usr/lib64/mysql/
[maohao@localhost init.d]$ sudo rm -rf /etc/my.cnf
#检查
[maohao@localhost init.d]$ sudo rpm -qa|grep -i mysql
php56w-mysql-5.6.32-1.w6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
安装5.5源
[maohao@localhost]$ sudo rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm
[maohao@localhost]$ sudo rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm
#查看
[maohao@localhost]$ yum --enablerepo=remi,remi-test list mysql mysql-server
#最后两行是这样就是成功了
mysql.x86_64 5.5.58-1.el6.remi remi
mysql-server.x86_64 5.5.58-1.el6.remi remi
安装mysql5.5
[maohao@localhost]$ sudo yum --enablerepo=remi,remi-test install mysql mysql-server
启动
[maohao@localhost ]$ sudo /etc/init.d/mysqld start
Initializing MySQL database: Installing MySQL system tables...
171201 11:25:06 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
171201 11:25:06 [Note] /usr/libexec/mysqld (mysqld 5.5.58) starting as process 2270 ...
OK
Filling help tables...
171201 11:25:08 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
171201 11:25:08 [Note] /usr/libexec/mysqld (mysqld 5.5.58) starting as process 2277 ...
OKTo start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'Alternatively you can run:
/usr/bin/mysql_secure_installationwhich will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.plPlease report any problems at http://bugs.mysql.com/
[ OK ]
Starting mysqld: [ OK ]
设置root密码
[maohao@localhost]$ sudo /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQLSERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
#这里的旧密码默认的是空,直接回车
Enter current password for root (enter for none):
OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..... Success!By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.Remove anonymous users? [Y/n] y... Success!Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y... Success!By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.Remove test database and access to it? [Y/n] y- Dropping test database...... Success!- Removing privileges on test database...... Success!Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.Reload privilege tables now? [Y/n] y... Success!Cleaning up...All done! If you've completed all of the above steps, your MySQL
installation should now be secure.Thanks for using MySQL!
设置开机启动,重启
[maohao@localhost ~]$ sudo chkconfig mysqld on
[maohao@localhost ~]$ sudo /etc/init.d/mysqld restart